Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
alimy committed Mar 21, 2022
1 parent e5970c6 commit 2f76f94
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 136 deletions.
4 changes: 3 additions & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
9 changes: 5 additions & 4 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
22 changes: 15 additions & 7 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand Down
10 changes: 3 additions & 7 deletions examples/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
// Copyright 2019 Michael Li <alimy@gility.net>. 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
Expand Down
10 changes: 7 additions & 3 deletions examples/mirc/auto/api/site.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions examples/mirc/auto/api/v1/site.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions examples/mirc/auto/api/v2/site.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions examples/mirc/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 Michael Li <alimy@gility.net>. 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 (
Expand All @@ -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"),
}
Expand Down
6 changes: 1 addition & 5 deletions examples/mirc/routes/site.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 Michael Li <alimy@gility.net>. 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 (
Expand All @@ -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/"`
Expand Down
6 changes: 1 addition & 5 deletions examples/mirc/routes/v1/site.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 Michael Li <alimy@gility.net>. 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 (
Expand All @@ -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"`
Expand Down
6 changes: 1 addition & 5 deletions examples/mirc/routes/v2/site.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 Michael Li <alimy@gility.net>. 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 (
Expand All @@ -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/"`
Expand Down
10 changes: 3 additions & 7 deletions examples/servants/servants.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// Copyright 2021 Michael Li <alimy@gility.net>. 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
Expand Down
27 changes: 3 additions & 24 deletions examples/servants/site.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
// Copyright 2019 Michael Li <alimy@gility.net>. 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{}
}
26 changes: 5 additions & 21 deletions examples/servants/site_v1.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
// Copyright 2019 Michael Li <alimy@gility.net>. 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{}
}
Loading

0 comments on commit 2f76f94

Please sign in to comment.