https://play.golang.com/p/BPWVd0WAfqR
package main import ( "encoding/json" "fmt" ) var bodyA = []byte(`{ "type": "A", "data": { "name": "Johnny" } }`) var bodyB = []byte(`{ "type": "B", "data": { "nickname": "J." } }`) type TypeA struct { Name string `json:"name"` } type TypeB struct { Nickname string `json:"nickname"` } func main() { req := struct { Type string `json:"type"` Data any `json:"data"` }{} err := json.Unmarshal(bodyA, &req) // bodyB if err !
https://notes.shichao.io/gopl/ch9/
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.
https://books.halfrost.com/leetcode/
https://ithelp.ithome.com.tw/articles/10225188
在Windows上編譯
To MacOs
SET CGO_ENABLED=0 SET GOOS=darwin SET GOARCH=amd64 go build main.go To Linux
SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 go build main.go To Windows ???
go build main.go 在Linux上編譯
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
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