update doc (#90)

* rebase upstream

* rebase

* trim no need line

* trim no need line

* trim no need line

* update doc

* remove update

* remove no need

* remove no need

* update jwt doc

* update jwt doc

* update jwt doc

* update jwt doc

Co-authored-by: kingxt <dream4kingxt@163.com>
master
kingxt 4 years ago committed by GitHub
parent 878fd14739
commit b6b8941a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,7 +9,7 @@
### 1. 客户端获取JWT Token
我们定义一个协议供客户端调用获取JWT token我们找一个目录执行goctl api new jwt将生成的jwt.api改成如下
我们定义一个协议供客户端调用获取JWT token我们新建一个目录jwt然后在目录中执行 `goctl api -o jwt.api`将生成的jwt.api改成如下
````go
type JwtTokenRequest struct {
@ -25,18 +25,18 @@ service jwt-api {
@server(
handler: JwtHandler
)
post /user/token(JwtTokenRequest) returns (JwtTokenResponse);
post /user/token(JwtTokenRequest) returns (JwtTokenResponse)
}
````
再次在生产服务目录中执行api go -api jwt.api -dir .
再次在生成服务目录中执行:`goctl api go -api jwt.api -dir .`
打开jwtlogic.go文件修改 `func (l *JwtLogic) Jwt(req types.Request) (*types.Response, error) {` 方法如下:
打开jwtlogic.go文件修改 `func (l *JwtLogic) Jwt(req types.JwtTokenRequest) (*types.JwtTokenResponse, error) {` 方法如下:
```go
const AccessSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
func (l *JwtLogic) Jwt(req types.Request) (*types.Response, error) {
func (l *JwtLogic) Jwt(req types.JwtTokenRequest) (*types.JwtTokenResponse, error) {
var accessExpire int64 = 60 * 60 * 24 * 7
now := time.Now().Unix()
@ -45,7 +45,7 @@ func (l *JwtLogic) Jwt(req types.Request) (*types.Response, error) {
return nil, err
}
return &types.Response{AccessToken: accessToken, AccessExpire: now + accessExpire, RefreshAfter: now + accessExpire/2}, nil
return &types.JwtTokenResponse{AccessToken: accessToken, AccessExpire: now + accessExpire, RefreshAfter: now + accessExpire/2}, nil
}
func (l *JwtLogic) GenToken(iat int64, secretKey string, payloads map[string]interface{}, seconds int64) (string, error) {

Loading…
Cancel
Save