https://github.com/uber-go/zap
https://marcoma.xyz/2019/03/17/gin-tutorial-7/
https://github.com/natefinch/lumberjack
https://juejin.im/post/5d3932bde51d454f73356e2d
http://www.jfh.com/jfperiodical/article/1949?
https://play.golang.org/p/i90_qsN2Sz-
package main import ( "fmt" "encoding/hex" ) func main() { id := "0x1dd84569ad60faa1b6838526ba7156388cf7c8d376ed0ccda9bce0419c2c3519" fmt.Printf("Ori ID: %v \n\n", id) fmt.Printf("Ori ID[2:]: %v \n\n", id[2:]) byteid := []byte(id) fmt.Printf("===== Byte id ===== Decimal \n") fmt.Printf("Byte ID: %v \n", byteid) fmt.Printf("Byte ID 0x%x \n\n", byteid) fmt.Printf("===== Decode(Byte id[2:]) ===== Decimal HEX \n") byteid = []byte(id[2:]) fmt.Printf("Byte ID: %v \n", byteid) fmt.Printf("Byte ID 0x%x \n\n", byteid) n, _ := hex.Decode(byteid, byteid) fmt.Printf("Byte ID[2:]: %v \n", byteid) fmt.
https://segmentfault.com/a/1190000020329813
1.什么是JWT
JWT(JSON Web Token)是一个非常轻巧的规范,这个规范允许我们使用JWT在用户和服务器之间传递安全可靠的信息,
一个JWT由三部分组成,Header头部、Claims载荷、Signature签名,
JWT原理类似我们加盖公章或手写签名的的过程,合同上写了很多条款,不是随便一张纸随便写啥都可以的,必须要一些证明,比如签名,比如盖章,JWT就是通过附加签名,保证传输过来的信息是真的,而不是伪造的,
它将用户信息加密到token里,服务器不保存任何用户信息,服务器通过使用保存的密钥验证token的正确性,只要正确即通过验证,
2.JWT构成
一个JWT由三部分组成,Header头部、Claims载荷、Signature签名,
Header头部:头部,表明类型和加密算法
Claims载荷:声明,即载荷(承载的内容)
Signature签名:签名,这一部分是将header和claims进行base64转码后,并用header中声明的加密算法加盐(secret)后构成,即:
let tmpstr = base64(header)+base64(claims)
let signature = encrypt(tmpstr,secret)
//最后三者用".“连接,即:
let token = base64(header)+”."+base64(claims)+"."+signature
https://github.com/terraform-providers/terraform-provider-github/blob/master/github/config.go
ctx := context.Background() insecureClient := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, }, } ctx = context.WithValue(ctx, oauth2.HTTPClient, insecureClient) client := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{ AccessToken: c.Param("accesstoken"), TokenType: "Bearer", })) resp, err := client.Get("https://ory-hydra-login-consent:9020/openid/userinfo") if err != nil { return newHTTPError(400, "InvalidToken", err.Error()) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return newHTTPError(400, "InvalidToken", err.Error()) } c.Logger().Debugf("resp: %s", body) var t map[string]interface{} err = json.Unmarshal(body, &t) if err !
func covertStringByte32(t string) [32]byte { var b32 [32]byte copy(b32[:], []byte(t)) return b32 } func covertStringByte64(t string) [64]byte { var b64 [64]byte copy(b64[:], []byte(t)) return b64 }
httpexpect star 1159
https://github.com/gavv/httpexpect
https://github.com/gavv/httpexpect/blob/master/_examples/echo_test.go
goconvey
https://segmentfault.com/a/1190000014924022
https://github.com/smartystreets/goconvey/
baloo star 652
https://github.com/h2non/baloo
frisby star 249
https://github.com/verdverm/frisby
apitest star 121
https://github.com/steinfletcher/apitest