go17/vblog/README.md
2024-12-01 17:17:51 +08:00

82 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Web全栈开发(Vblog)
## 软件设计
### 需求
管理markdown个文字的一个网站作者后台发布文章访客前台浏览查看文章
### 流程
![](./docs/flow.drawio)
### 产品原型
https://gitee.com/infraboard/go-course/blob/master/new.md#%E6%9E%B6%E6%9E%84%E8%AE%BE%E8%AE%A1
![](./docs/page.png)
### 架构(BS)和概要设计
![](./docs/arch.png)
### 业务的详细设计
直接使用Go的接口 来定义业务
```go
// 业务域
type Service interface {
UserService
InnterService
}
// 1. 外部
type UserService interface {
// 颁发令牌 登录
IssueToken(context.Context, *IssueTokenRequest) (*Token, error)
// 撤销令牌 退出
RevolkToken(context.Context, *RevolkTokenRequest) (*Token, error)
}
type RevolkTokenRequest struct {
// 访问令牌
AccessToken string `json:"access_token"`
// 刷新令牌, 构成一对避免AccessToken 泄露,用户可以直接 revolk
RefreshToken string `json:"refresh_token"`
}
type IssueTokenRequest struct {
Username string `json:"username"`
Password string `json:"password"`
// 记住我, Token可能1天过期, 过去时间调整为7天
RememberMe bool `json:"remember_me"`
}
// 内部
type InnterService interface {
// 令牌校验
ValidateToken(context.Context, *ValidateTokenRequest) (*Token, error)
}
type ValidateTokenRequest struct {
// 访问令牌
AccessToken string `json:"access_token"`
}
```
数据库的设计伴随接口设计已经完成
1. 如何基于Vscode 构造单元测试的配置
```json
{
"go.testEnvFile": "${workspaceFolder}/etc/test.env",
}
```
添加工作目录环境变量
```
WORKSPACE_DIR="/Users/xxxx/Projects/go-course/go17/vblog"
```