1、Authenticator old:Authenticator: func(userId string, password string, c *gin.Context) New: ============================ `` type login struct { Username string `form:"username" json:"username" binding:"required"` Password string `form:"password" json:"password" binding:"required"` } Authenticator: func(c *gin.Context) (interface{}, error) { var loginVals login if err := c.ShouldBind(&loginVals); err != nil { return "", jwt.ErrMissingLoginValues } userID := loginVals.Username password := loginVals.Password `` 2、authMiddleware old: authMiddleware := jwt.GinJWTMiddleware{ New: authMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{

繼續閱讀

Struct to Map by Tag

telegram Gopher 台灣 @winampmaker https://play.golang.org/p/RObzlfjZSRi ` func struct2Map(model interface{}, tagName string) map[string]interface{} { m := make(map[string]interface{}) r := reflect.ValueOf(model) total := r.NumField() for i := 0; i < total; i++ { m[r.Type().Field(i).Tag.Get(tagName)] = r.Field(i).Interface() } return m } ` ============================ ` "github.com/fatih/structs" func StructtoMapbyTag(tr interface{}, tag string) map[string]interface{} { t := make(map[string]interface{}) //儲存處理過的m s := structs.New(tr) m := s.Map() //先轉成map[string]interface{} for key, value := range m { t[s.Field(key).Tag(tag)] = value.(string) } return t } `

繼續閱讀

Usually how to tech is ` req, err := http.NewRequest("GET", "http://example.com", nil) req.Header.Add("Authorize", "dswxswsxw") resp, err := client.Do(req) ` BUT Have problem inside. So…. use this ` headers := http.Header{ "Accept-Encoding": []string{"gzip, deflate"}, } req, err := http.NewRequest("GET", url, nil) req.Header = headers client := &http.Client{} resp, err = client.Do(req) ` More Safe.

繼續閱讀

GraphQL golang

GraphQL https://www.thepolyglotdeveloper.com/2018/05/getting-started-graphql-golang/ https://www.thepolyglotdeveloper.com/2018/05/maintain-data-relationships-resolvers-graphql-golang-application/ https://www.thepolyglotdeveloper.com/2018/07/jwt-authorization-graphql-api-using-golang/

繼續閱讀

作者的圖片

Sue boy

Sueboy Can support You

CIO

Taiwan