Skip to content

Commit

Permalink
a new style generator for gin
Browse files Browse the repository at this point in the history
  • Loading branch information
alimy committed Jun 27, 2023
1 parent 36cae11 commit 5eaa44d
Show file tree
Hide file tree
Showing 148 changed files with 981 additions and 869 deletions.
14 changes: 7 additions & 7 deletions README-en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Mir
[![Go](https://github.com/alimy/mir/actions/workflows/go.yml/badge.svg)](https://github.com/alimy/mir/actions/workflows/go.yml)
[![GoDoc](https://godoc.org/github.com/alimy/mir?status.svg)](https://pkg.go.dev/github.com/alimy/mir/v3)
[![GoDoc](https://godoc.org/github.com/alimy/mir?status.svg)](https://pkg.go.dev/github.com/alimy/mir/v4)
[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?logo=sourcegraph)](https://sourcegraph.com/github.com/alimy/mir)

Mir is a toolkit to develop RESTful API backend service like develop service of gRPC. It adapt some HTTP framework sush as [Gin](https://github.com/gin-gonic/gin), [Chi](https://github.com/go-chi/chi), [Hertz](https://github.com/cloudwego/hertz), [Echo](https://github.com/labstack/echo), [Iris](https://github.com/kataras/iris), [Fiber](https://github.com/gofiber/fiber), [Macaron](https://github.com/go-macaron/macaron), [Mux](https://github.com/gorilla/mux), [httprouter](https://github.com/julienschmidt/httprouter)
Expand Down Expand Up @@ -67,8 +67,8 @@ example
package routes
import (
. "github.com/alimy/mir/v3"
. "github.com/alimy/mir/v3/engine"
. "github.com/alimy/mir/v4"
. "github.com/alimy/mir/v4/engine"
)
func init() {
Expand Down Expand Up @@ -106,7 +106,7 @@ package routes
import (
"net/http"
"github.com/alimy/mir/v3"
"github.com/alimy/mir/v4"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -230,7 +230,7 @@ func (r *UnimplementedUserRender) mustEmbedUnimplementedUserRender() {}
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
)
type userSrv struct {
Expand Down Expand Up @@ -288,7 +288,7 @@ func renderAny(c *gin.Context, data any, err mir.Error) {
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
"github.com/gin-gonic/gin"
)
Expand All @@ -309,7 +309,7 @@ package main
import (
"log"
"github.com/alimy/mir-example/v3/servants"
"github.com/alimy/mir-example/v4/servants"
"github.com/gin-gonic/gin"
)
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Mir
[![Go](https://github.com/alimy/mir/actions/workflows/go.yml/badge.svg)](https://github.com/alimy/mir/actions/workflows/go.yml)
[![GoDoc](https://godoc.org/github.com/alimy/mir?status.svg)](https://pkg.go.dev/github.com/alimy/mir/v3)
[![GoDoc](https://godoc.org/github.com/alimy/mir?status.svg)](https://pkg.go.dev/github.com/alimy/mir/v4)
[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?logo=sourcegraph)](https://sourcegraph.com/github.com/alimy/mir)

Mir 是一套提供类似gRPC服务开发体验的快速开发RESTful API后端开发脚手架,适配多种HTTP框架,包括 [Gin](https://github.com/gin-gonic/gin), [Chi](https://github.com/go-chi/chi), [Hertz](https://github.com/cloudwego/hertz), [Echo](https://github.com/labstack/echo), [Iris](https://github.com/kataras/iris), [Fiber](https://github.com/gofiber/fiber), [Macaron](https://github.com/go-macaron/macaron), [Mux](https://github.com/gorilla/mux), [httprouter](https://github.com/julienschmidt/httprouter)
Expand Down Expand Up @@ -67,8 +67,8 @@ example
package routes
import (
. "github.com/alimy/mir/v3"
. "github.com/alimy/mir/v3/engine"
. "github.com/alimy/mir/v4"
. "github.com/alimy/mir/v4/engine"
)
func init() {
Expand Down Expand Up @@ -106,7 +106,7 @@ package routes
import (
"net/http"
"github.com/alimy/mir/v3"
"github.com/alimy/mir/v4"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -230,7 +230,7 @@ func (r *UnimplementedUserRender) mustEmbedUnimplementedUserRender() {}
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
)
type userSrv struct {
Expand Down Expand Up @@ -288,7 +288,7 @@ func renderAny(c *gin.Context, data any, err mir.Error) {
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
"github.com/gin-gonic/gin"
)
Expand All @@ -309,7 +309,7 @@ package main
import (
"log"
"github.com/alimy/mir-example/v3/servants"
"github.com/alimy/mir-example/v4/servants"
"github.com/gin-gonic/gin"
)
Expand Down
39 changes: 25 additions & 14 deletions core/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"reflect"
"strings"

"github.com/alimy/mir/v3/internal/utils"
"github.com/alimy/mir/v4/internal/utils"
)

var (
VerInfo = &VersionInfo{
MirVer: "v3.2.1",
MirVer: "v4.0.0",
}
)

Expand Down Expand Up @@ -49,18 +49,19 @@ type FieldDescriptor struct {

// IfaceDescriptor interface Descriptor info
type IfaceDescriptor struct {
Group string
Chain string
Imports map[string]string
PkgPath string
PkgName string
TypeName string
Comment string // not support now so always empty
InOuts []reflect.Type
Fields []*FieldDescriptor
EngineInfo *EngineInfo
VerInfo *VersionInfo
WatchCtxDone bool
Group string
Chain string
Imports map[string]string
PkgPath string
PkgName string
TypeName string
Comment string // not support now so always empty
InOuts []reflect.Type
Fields []*FieldDescriptor
EngineInfo *EngineInfo
VerInfo *VersionInfo
WatchCtxDone bool
DeclareCoreInterface bool // whether need to declare core interface, default is false
}

// IfaceDescriptors interface Descriptor map {TypeName:*IfaceDescriptor}
Expand Down Expand Up @@ -124,6 +125,11 @@ func (d *IfaceDescriptor) SetPkgName(name string) {
d.PkgName = name
}

// SetDeclareCoreInterface set declare core interface value
func (d *IfaceDescriptor) SetDeclareCoreInterface(isNeed bool) {
d.DeclareCoreInterface = isNeed
}

// SetInnerInOuts set inner InOuts for defined
func (d *IfaceDescriptor) SetInnerInOuts(inOuts []reflect.Type) {
var extSts []reflect.Type
Expand Down Expand Up @@ -252,6 +258,11 @@ func (f *FieldDescriptor) HttpMethodArgs() string {
return utils.QuoteJoin(f.HttpMethods, ",")
}

// OrInOut in or out
func (f *FieldDescriptor) OrInOut() bool {
return f.In != nil || f.Out != nil
}

// InName return In type name
func (f *FieldDescriptor) InName() string {
if f.In == nil {
Expand Down
2 changes: 1 addition & 1 deletion core/descriptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package core
import (
"testing"

"github.com/alimy/mir/v3"
"github.com/alimy/mir/v4"
)

func TestDescriptors(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ example
package routes
import (
. "github.com/alimy/mir/v3"
. "github.com/alimy/mir/v3/engine"
. "github.com/alimy/mir/v4"
. "github.com/alimy/mir/v4/engine"
)
func init() {
Expand Down Expand Up @@ -100,7 +100,7 @@ package routes
import (
"net/http"
"github.com/alimy/mir/v3"
"github.com/alimy/mir/v4"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -224,7 +224,7 @@ func (r UnimplementedUserRender) mustEmbedUnimplementedUserRender() {}
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
)
type userSrv struct {
Expand Down Expand Up @@ -282,7 +282,7 @@ func renderAny(c *gin.Context, data any, err mir.Error) {
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
"github.com/gin-gonic/gin"
)
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ example
package routes
import (
. "github.com/alimy/mir/v3"
. "github.com/alimy/mir/v3/engine"
. "github.com/alimy/mir/v4"
. "github.com/alimy/mir/v4/engine"
)
func init() {
Expand Down Expand Up @@ -197,7 +197,7 @@ package routes
import (
"net/http"
"github.com/alimy/mir/v3"
"github.com/alimy/mir/v4"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -321,7 +321,7 @@ func (r UnimplementedUserRender) mustEmbedUnimplementedUserRender() {}
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
)
type userSrv struct {
Expand Down Expand Up @@ -379,7 +379,7 @@ func renderAny(c *gin.Context, data any, err mir.Error) {
package servants
import (
"github.com/alimy/mir-example/v3/mirc/auto/api"
"github.com/alimy/mir-example/v4/mirc/auto/api"
"github.com/gin-gonic/gin"
)
Expand Down
4 changes: 2 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"runtime"
"sync"

"github.com/alimy/mir/v3/core"
"github.com/alimy/mir/v3/internal"
"github.com/alimy/mir/v4/core"
"github.com/alimy/mir/v4/internal"
)

var (
Expand Down
39 changes: 21 additions & 18 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
module github.com/alimy/mir-example/v3
module github.com/alimy/mir-example/v4

go 1.18

require (
github.com/alimy/mir/v3 v3.2.1
github.com/gin-gonic/gin v1.9.0
github.com/alimy/mir/v4 v4.0.0
github.com/gin-gonic/gin v1.9.1
)

replace github.com/alimy/mir/v4 => ../

require (
github.com/bytedance/sonic v1.8.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 5eaa44d

Please sign in to comment.