Golang Gin Api become Windows Service Use github.com/kardianos/service package main import ( "errors" "fmt" "io" "log" "net" "net/http" "os" "path/filepath" "strings" "time" "github.com/gin-gonic/gin" "github.com/joho/godotenv" "github.com/kardianos/service" ) // Process Windows Service // github.com/kardianos/service var logger service.Logger type program struct{} func (p *program) Start(s service.Service) error { // Start should not block. Do the actual work async. go p.run() return nil } func (p *program) Stop(s service.Service) error { // Stop should not block.

繼續閱讀

golang loggin gin

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

繼續閱讀

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{

繼續閱讀

gin-jwt

1. Authenticator 回傳的 data 2. data 會丟入到 PayloadFunc 3. PayloadFunc 整理資料寫入 MapClaims 4. Authorizator 再拿 MapClaims 資料出來判斷 新版和舊版有地方不同 type xxxxx struct{  aaaaaaa:string } 1、 Authenticator: func(userId string, password string, c *gin.Context) (interface{}, bool) { return xxxxx{aaaaaaa: ooooxxxx} or string 2、 PayloadFunc: func(data interface{}) jwt.MapClaims { if v, ok := data.(xxxxx); ok { id = data.(xxxxx).aaaaaaa } return jwt.MapClaims{“aaaaaaa”: ooooxxxx, “bbbbbbb”: ooooxxxx} 3、 Authorizator: func(data interface{}, c *gin.Context) bool {

繼續閱讀

作者的圖片

Sue boy

Sueboy Can support You

CIO

Taiwan