摘要: 还是三步骤创建EndPoint,创建Transport,调用请求 第一步创建transport package Services import ( "context" "encoding/json" "errors" "github.com/tidwall/gjson" "io/ioutil" "net/http" ) func Deco... 阅读全文
posted @ 2019-12-24 15:24 离地最远的星 阅读(910) 评论(1) 推荐(0) 编辑
摘要: token设置过期时间 package main import ( "fmt" "github.com/dgrijalva/jwt-go" "io/ioutil" "log" "time" ) type UserClaim struct { Uname string `json:"username"` jwt.... 阅读全文
posted @ 2019-12-24 13:36 离地最远的星 阅读(6460) 评论(0) 推荐(0) 编辑
摘要: 生成公钥和私钥代码 package utils import ( "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/pem" "fmt" "io/ioutil" ) func GenRSAPubAndPri(bits int,filepath string ) error { //... 阅读全文
posted @ 2019-12-24 12:09 离地最远的星 阅读(3872) 评论(0) 推荐(0) 编辑
摘要: 使用第三方库jwt-go进行加密和验证 package main import ( "fmt" "github.com/dgrijalva/jwt-go" ) type UserClaim struct { Uname string `json:"username"` jwt.StandardClaims //嵌套了... 阅读全文
posted @ 2019-12-24 11:28 离地最远的星 阅读(695) 评论(0) 推荐(0) 编辑
摘要: 使用中间件的方式包装日志输出 package Services import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "golang.org/x/time/rate" "gomicro/utils" "strconv" )... 阅读全文
posted @ 2019-12-24 00:51 离地最远的星 阅读(790) 评论(0) 推荐(0) 编辑