diff --git a/examples/.gitignore b/examples/.gitignore index b280a60..745dfc8 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -17,4 +17,6 @@ tmp.out # Output of the go coverage tool, specifically when used with LiteIDE *.out -/mir-examples +# GoLand project files +.idea/ +*.iml diff --git a/examples/Makefile b/examples/Makefile index 1218024..9616a42 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,14 +1,12 @@ GOFMT ?= gofmt -s -w GOFILES := $(shell find . -name "*.go" -type f) -TARGET := mir-examples - .PHONY: default default: run .PHONY: build build: fmt - go build -o ${TARGET} main.go + go build -o mir-examples main.go .PHONY: build run: fmt diff --git a/examples/README.md b/examples/README.md index 3fda288..5bf9de3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,6 +3,6 @@ just a simple mir's examples for explain how to use mir in your project. #### Usage ```bash -% make genereate #will generate code to mirc/gen directory +% make generate % make build ``` diff --git a/examples/go.mod b/examples/go.mod index 63463da..8fbb8fa 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -1,8 +1,9 @@ -module github.com/alimy/mir/v2/examples +module github.com/alimy/mir-example -go 1.12 +go 1.16 require ( - github.com/alimy/mir/v2 v2.7.0-alpha - github.com/gin-gonic/gin v1.6.3 + github.com/alimy/mir/v2 v2.7.2 + github.com/gin-gonic/gin v1.7.7 + golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect ) diff --git a/examples/go.sum b/examples/go.sum index 3cf79f1..1d1ff30 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1,20 +1,20 @@ -github.com/alimy/mir/v2 v2.7.0-alpha h1:PCuWtXA7d4sI0o212wjfibwnRKrDWOOOBeOWVGJICoo= -github.com/alimy/mir/v2 v2.7.0-alpha/go.mod h1:lsJwZ58471a9/pztfiBW6+rs3rRqry2yZfr3oFxHAJA= +github.com/alimy/mir/v2 v2.7.2 h1:fFD1DqAtSsaTrjMS19Z5QSYCuPvxIUc/Wct55rYaQ2w= +github.com/alimy/mir/v2 v2.7.2/go.mod h1:lsJwZ58471a9/pztfiBW6+rs3rRqry2yZfr3oFxHAJA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= -github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= +github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= -github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= +github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -38,8 +38,16 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/examples/main.go b/examples/main.go index 17eac00..04e354b 100644 --- a/examples/main.go +++ b/examples/main.go @@ -1,20 +1,16 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package main import ( "log" - "github.com/alimy/mir/v2/examples/servants" + "github.com/alimy/mir-example/servants" "github.com/gin-gonic/gin" ) func main() { - e := gin.New() + e := gin.Default() - // register servants to engine + // register servants to gin servants.RegisterServants(e) // start servant service diff --git a/examples/mirc/auto/api/site.go b/examples/mirc/auto/api/site.go index d67608d..7fc708e 100644 --- a/examples/mirc/auto/api/site.go +++ b/examples/mirc/auto/api/site.go @@ -14,6 +14,8 @@ type Site interface { Index(*gin.Context) Articles(*gin.Context) + + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to gin @@ -32,14 +34,16 @@ func RegisterSiteServant(e *gin.Engine, s Site) { type UnimplementedSiteServant struct { } -func (*UnimplementedSiteServant) Chain() gin.HandlersChain { +func (UnimplementedSiteServant) Chain() gin.HandlersChain { return nil } -func (*UnimplementedSiteServant) Index(c *gin.Context) { +func (UnimplementedSiteServant) Index(c *gin.Context) { c.String(http.StatusNotImplemented, "method Index not implemented") } -func (*UnimplementedSiteServant) Articles(c *gin.Context) { +func (UnimplementedSiteServant) Articles(c *gin.Context) { c.String(http.StatusNotImplemented, "method Articles not implemented") } + +func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/examples/mirc/auto/api/v1/site.go b/examples/mirc/auto/api/v1/site.go index cee876c..d7f76bc 100644 --- a/examples/mirc/auto/api/v1/site.go +++ b/examples/mirc/auto/api/v1/site.go @@ -14,6 +14,8 @@ type Site interface { Index(*gin.Context) Articles(*gin.Context) + + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to gin @@ -32,14 +34,16 @@ func RegisterSiteServant(e *gin.Engine, s Site) { type UnimplementedSiteServant struct { } -func (*UnimplementedSiteServant) Chain() gin.HandlersChain { +func (UnimplementedSiteServant) Chain() gin.HandlersChain { return nil } -func (*UnimplementedSiteServant) Index(c *gin.Context) { +func (UnimplementedSiteServant) Index(c *gin.Context) { c.String(http.StatusNotImplemented, "method Index not implemented") } -func (*UnimplementedSiteServant) Articles(c *gin.Context) { +func (UnimplementedSiteServant) Articles(c *gin.Context) { c.String(http.StatusNotImplemented, "method Articles not implemented") } + +func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/examples/mirc/auto/api/v2/site.go b/examples/mirc/auto/api/v2/site.go index 4fcffbb..13bdc12 100644 --- a/examples/mirc/auto/api/v2/site.go +++ b/examples/mirc/auto/api/v2/site.go @@ -12,6 +12,8 @@ type Site interface { Index(*gin.Context) Articles(*gin.Context) Category(*gin.Context) + + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to gin @@ -28,14 +30,16 @@ func RegisterSiteServant(e *gin.Engine, s Site) { type UnimplementedSiteServant struct { } -func (*UnimplementedSiteServant) Index(c *gin.Context) { +func (UnimplementedSiteServant) Index(c *gin.Context) { c.String(http.StatusNotImplemented, "method Index not implemented") } -func (*UnimplementedSiteServant) Articles(c *gin.Context) { +func (UnimplementedSiteServant) Articles(c *gin.Context) { c.String(http.StatusNotImplemented, "method Articles not implemented") } -func (*UnimplementedSiteServant) Category(c *gin.Context) { +func (UnimplementedSiteServant) Category(c *gin.Context) { c.String(http.StatusNotImplemented, "method Category not implemented") } + +func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/examples/mirc/main.go b/examples/mirc/main.go index b282693..1a4452d 100644 --- a/examples/mirc/main.go +++ b/examples/mirc/main.go @@ -1,7 +1,3 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package main import ( @@ -10,16 +6,16 @@ import ( . "github.com/alimy/mir/v2/core" . "github.com/alimy/mir/v2/engine" - _ "github.com/alimy/mir/v2/examples/mirc/routes" - _ "github.com/alimy/mir/v2/examples/mirc/routes/v1" - _ "github.com/alimy/mir/v2/examples/mirc/routes/v2" + _ "github.com/alimy/mir-example/mirc/routes" + _ "github.com/alimy/mir-example/mirc/routes/v1" + _ "github.com/alimy/mir-example/mirc/routes/v2" ) //go:generate go run main.go func main() { log.Println("generate code start") opts := Options{ - RunMode(InSerialDebugMode), + RunMode(InSerialMode), GeneratorName(GeneratorGin), SinkPath("auto"), } diff --git a/examples/mirc/routes/site.go b/examples/mirc/routes/site.go index a54977f..bc53b37 100644 --- a/examples/mirc/routes/site.go +++ b/examples/mirc/routes/site.go @@ -1,7 +1,3 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package routes import ( @@ -13,7 +9,7 @@ func init() { AddEntry(new(Site)) } -// Site mir's struct tag define +// Site site interface info type Site struct { Chain Chain `mir:"-"` Index Get `mir:"/index/"` diff --git a/examples/mirc/routes/v1/site.go b/examples/mirc/routes/v1/site.go index f8a8ed6..559534b 100644 --- a/examples/mirc/routes/v1/site.go +++ b/examples/mirc/routes/v1/site.go @@ -1,7 +1,3 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package v1 import ( @@ -13,7 +9,7 @@ func init() { AddEntry(new(Site)) } -// Site mir's struct tag define +// Site site v1 interface info type Site struct { Chain Chain `mir:"-"` Group Group `mir:"v1"` diff --git a/examples/mirc/routes/v2/site.go b/examples/mirc/routes/v2/site.go index b6f5d4e..2e29da1 100644 --- a/examples/mirc/routes/v2/site.go +++ b/examples/mirc/routes/v2/site.go @@ -1,7 +1,3 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package v2 import ( @@ -13,7 +9,7 @@ func init() { AddEntry(new(Site)) } -// Site mir's struct tag define +// Site site v2 interface info type Site struct { Group Group `mir:"v2"` Index Get `mir:"/index/"` diff --git a/examples/servants/servants.go b/examples/servants/servants.go index f675917..47bd8a6 100644 --- a/examples/servants/servants.go +++ b/examples/servants/servants.go @@ -1,15 +1,11 @@ -// Copyright 2021 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package servants import ( - "github.com/alimy/mir/v2/examples/mirc/auto/api" + "github.com/alimy/mir-example/mirc/auto/api" "github.com/gin-gonic/gin" - v1 "github.com/alimy/mir/v2/examples/mirc/auto/api/v1" - v2 "github.com/alimy/mir/v2/examples/mirc/auto/api/v2" + v1 "github.com/alimy/mir-example/mirc/auto/api/v1" + v2 "github.com/alimy/mir-example/mirc/auto/api/v2" ) // RegisterServants register all the servants to gin.Engine diff --git a/examples/servants/site.go b/examples/servants/site.go index 91ae68a..4193e3a 100644 --- a/examples/servants/site.go +++ b/examples/servants/site.go @@ -1,32 +1,11 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package servants -import ( - "net/http" - - "github.com/alimy/mir/v2/examples/mirc/auto/api" - "github.com/gin-gonic/gin" -) +import "github.com/alimy/mir-example/mirc/auto/api" -type emptySiteWithNoGroup struct { +type siteSrv struct { api.UnimplementedSiteServant } -func (emptySiteWithNoGroup) Chain() gin.HandlersChain { - return gin.HandlersChain{gin.Logger()} -} - -func (emptySiteWithNoGroup) Index(c *gin.Context) { - c.String(http.StatusOK, "get index data") -} - -func (emptySiteWithNoGroup) Articles(c *gin.Context) { - c.String(http.StatusOK, "get articles data") -} - func newSiteSrv() api.Site { - return &emptySiteWithNoGroup{} + return &siteSrv{} } diff --git a/examples/servants/site_v1.go b/examples/servants/site_v1.go index 4ce0ee8..c689ae8 100644 --- a/examples/servants/site_v1.go +++ b/examples/servants/site_v1.go @@ -1,29 +1,13 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package servants import ( - "net/http" - - "github.com/gin-gonic/gin" - - api "github.com/alimy/mir/v2/examples/mirc/auto/api/v1" + v1 "github.com/alimy/mir-example/mirc/auto/api/v1" ) -type emptySiteV1 struct { - api.UnimplementedSiteServant -} - -func (*emptySiteV1) Index(c *gin.Context) { - c.String(http.StatusOK, "get index data (v1)") -} - -func (*emptySiteV1) Articles(c *gin.Context) { - c.String(http.StatusOK, "get articles data (v1)") +type siteV1Srv struct { + v1.UnimplementedSiteServant } -func newSiteV1Srv() api.Site { - return &emptySiteV1{} +func newSiteV1Srv() v1.Site { + return &siteV1Srv{} } diff --git a/examples/servants/site_v2.go b/examples/servants/site_v2.go index 7aa3e15..08781a6 100644 --- a/examples/servants/site_v2.go +++ b/examples/servants/site_v2.go @@ -1,37 +1,13 @@ -// Copyright 2019 Michael Li . All rights reserved. -// Use of this source code is governed by Apache License 2.0 that -// can be found in the LICENSE file. - package servants import ( - "net/http" - - "github.com/gin-gonic/gin" - - api "github.com/alimy/mir/v2/examples/mirc/auto/api/v2" + v2 "github.com/alimy/mir-example/mirc/auto/api/v2" ) -type emptySiteV2 struct { - api.UnimplementedSiteServant -} - -func (*emptySiteV2) Chain() gin.HandlersChain { - return gin.HandlersChain{gin.Logger()} -} - -func (*emptySiteV2) Index(c *gin.Context) { - c.String(http.StatusOK, "get index data (v2)") -} - -func (*emptySiteV2) Articles(c *gin.Context) { - c.String(http.StatusOK, "get articles data (v2)") -} - -func (*emptySiteV2) Category(c *gin.Context) { - c.String(http.StatusOK, "get Category data (v2)") +type siteV2Srv struct { + v2.UnimplementedSiteServant } -func newSiteV2Srv() api.Site { - return &emptySiteV2{} +func newSiteV2Srv() v2.Site { + return &siteV2Srv{} }