From 7a6d2b4723375fca8ace51b08c8bb1131a6815e6 Mon Sep 17 00:00:00 2001 From: alimy Date: Wed, 6 Apr 2022 16:28:56 +0800 Subject: [PATCH] support define option http method in tag string when field type is Any --- core/descriptor.go | 36 +++++++ core/descriptor_test.go | 8 +- internal/generator/templates.go | 20 ++-- internal/generator/templates/chi_iface.tmpl | 5 +- internal/generator/templates/echo_iface.tmpl | 3 +- internal/generator/templates/fiber_iface.tmpl | 3 +- .../generator/templates/fiber_iface_v2.tmpl | 3 +- internal/generator/templates/gin_iface.tmpl | 3 +- .../generator/templates/httprouter_iface.tmpl | 5 +- internal/generator/templates/iris_iface.tmpl | 3 +- .../generator/templates/macaron_iface.tmpl | 9 +- internal/generator/templates/mux_iface.tmpl | 9 +- internal/parser/fields.go | 56 ++++++++--- internal/utils/utils.go | 53 +++++++++++ internal/utils/utils_test.go | 40 ++++++++ mirc/cmd/templates/chi-v5/go.mod.tmpl | 2 +- .../chi-v5/mirc/auto/api/site.go.tmpl | 93 ++++++++++++++++++- .../chi-v5/mirc/auto/api/v1/site.go.tmpl | 91 ++++++++++++++++++ .../chi-v5/mirc/auto/api/v2/site.go.tmpl | 2 +- .../templates/chi-v5/mirc/routes/site.go.tmpl | 16 +++- .../chi-v5/mirc/routes/v1/site.go.tmpl | 18 +++- mirc/cmd/templates/chi/go.mod.tmpl | 2 +- .../templates/chi/mirc/auto/api/site.go.tmpl | 93 ++++++++++++++++++- .../chi/mirc/auto/api/v2/site.go.tmpl | 86 ++++++++++++++++- .../templates/chi/mirc/routes/site.go.tmpl | 16 +++- .../templates/chi/mirc/routes/v2/site.go.tmpl | 17 +++- mirc/cmd/templates/echo/go.mod.tmpl | 2 +- .../templates/echo/mirc/auto/api/site.go.tmpl | 86 ++++++++++++++++- .../echo/mirc/auto/api/v1/site.go.tmpl | 2 +- .../echo/mirc/auto/api/v2/site.go.tmpl | 70 +++++++++++++- .../templates/echo/mirc/routes/site.go.tmpl | 17 +++- .../echo/mirc/routes/v2/site.go.tmpl | 17 +++- mirc/cmd/templates/fiber-v2/go.mod.tmpl | 2 +- .../fiber-v2/mirc/auto/api/site.go.tmpl | 83 ++++++++++++++++- .../fiber-v2/mirc/auto/api/v1/site.go.tmpl | 6 +- .../fiber-v2/mirc/auto/api/v2/site.go.tmpl | 83 +++++++++++++++-- .../fiber-v2/mirc/routes/site.go.tmpl | 15 ++- .../fiber-v2/mirc/routes/v2/site.go.tmpl | 16 +++- mirc/cmd/templates/fiber/go.mod.tmpl | 3 +- .../fiber/mirc/auto/api/site.go.tmpl | 74 ++++++++++++++- .../fiber/mirc/auto/api/v1/site.go.tmpl | 6 +- .../fiber/mirc/auto/api/v2/site.go.tmpl | 75 +++++++++++++-- .../templates/fiber/mirc/routes/site.go.tmpl | 15 ++- .../fiber/mirc/routes/v2/site.go.tmpl | 16 +++- mirc/cmd/templates/gin/go.mod.tmpl | 3 +- .../templates/gin/mirc/auto/api/site.go.tmpl | 61 +++++++++++- .../gin/mirc/auto/api/v1/site.go.tmpl | 61 +++++++++++- .../gin/mirc/auto/api/v2/site.go.tmpl | 2 +- .../templates/gin/mirc/routes/site.go.tmpl | 15 ++- .../templates/gin/mirc/routes/v1/site.go.tmpl | 17 +++- mirc/cmd/templates/httprouter/go.mod.tmpl | 2 +- .../httprouter/mirc/auto/api/site.go.tmpl | 86 ++++++++++++++++- .../httprouter/mirc/auto/api/v1/site.go.tmpl | 2 +- .../httprouter/mirc/auto/api/v2/site.go.tmpl | 87 ++++++++++++++++- .../httprouter/mirc/routes/site.go.tmpl | 15 ++- .../httprouter/mirc/routes/v2/site.go.tmpl | 16 +++- mirc/cmd/templates/iris/go.mod.tmpl | 2 +- .../templates/iris/mirc/auto/api/site.go.tmpl | 70 +++++++++++++- .../iris/mirc/auto/api/v1/site.go.tmpl | 2 +- .../iris/mirc/auto/api/v2/site.go.tmpl | 71 +++++++++++++- .../templates/iris/mirc/routes/site.go.tmpl | 15 ++- .../iris/mirc/routes/v2/site.go.tmpl | 16 +++- mirc/cmd/templates/macaron/go.mod.tmpl | 2 +- .../macaron/mirc/auto/api/site.go.tmpl | 70 +++++++++++++- .../macaron/mirc/auto/api/v1/site.go.tmpl | 2 +- .../macaron/mirc/auto/api/v2/site.go.tmpl | 71 +++++++++++++- .../macaron/mirc/routes/site.go.tmpl | 15 ++- .../macaron/mirc/routes/v2/site.go.tmpl | 16 +++- mirc/cmd/templates/mux/go.mod.tmpl | 2 +- .../templates/mux/mirc/auto/api/site.go.tmpl | 81 ++++++++++++++-- .../mux/mirc/auto/api/v1/site.go.tmpl | 7 +- .../mux/mirc/auto/api/v2/site.go.tmpl | 79 ++++++++++++++-- .../templates/mux/mirc/routes/site.go.tmpl | 15 ++- .../templates/mux/mirc/routes/v2/site.go.tmpl | 16 +++- mirc/version/version.go | 2 +- 75 files changed, 1993 insertions(+), 208 deletions(-) create mode 100644 internal/utils/utils.go create mode 100644 internal/utils/utils_test.go diff --git a/core/descriptor.go b/core/descriptor.go index e6f6c19..d54df29 100644 --- a/core/descriptor.go +++ b/core/descriptor.go @@ -8,6 +8,9 @@ import ( "errors" "fmt" "strings" + + "github.com/alimy/mir/v2" + "github.com/alimy/mir/v2/internal/utils" ) // EngineInfo Engine information @@ -97,3 +100,36 @@ func (d Descriptors) keyFrom(s string) string { func (d *IfaceDescriptor) SetPkgName(name string) { d.PkgName = name } + +// NotHttpAny not just http any method +func (f *FieldDescriptor) NotHttpAny() bool { + return !strings.HasPrefix(f.HttpMethod, mir.MethodAny) +} + +// JustHttpAny not just http any method +func (f *FieldDescriptor) JustHttpAny() bool { + return f.HttpMethod == mir.MethodAny +} + +// AnyHttpMethods return methods in HttpMethods +// Note this is assumed HttpMethods like ANY:POST,GET,HEAD +func (f *FieldDescriptor) AnyHttpMethods() []string { + methods := strings.Split(f.HttpMethod, ":") + if len(methods) > 1 { + return strings.Split(methods[1], ",") + } + return nil +} + +// HttpMethodArgs return http method as argument like "POST","GET","HEAD" +// Note this is assumed HttpMethods like ANY:POST,GET,HEAD +func (f *FieldDescriptor) HttpMethodArgs() string { + httpMthods := mir.HttpMethods + if strings.HasPrefix(f.HttpMethod, mir.MethodAny) { + methods := strings.Split(f.HttpMethod, ":") + if len(methods) > 1 { + httpMthods = strings.Split(methods[1], ",") + } + } + return utils.QuoteJoin(httpMthods, ",") +} diff --git a/core/descriptor_test.go b/core/descriptor_test.go index 721d69e..1648188 100644 --- a/core/descriptor_test.go +++ b/core/descriptor_test.go @@ -4,7 +4,11 @@ package core -import "testing" +import ( + "testing" + + "github.com/alimy/mir/v2" +) func TestDescriptors(t *testing.T) { d := make(Descriptors) @@ -19,7 +23,7 @@ func TestDescriptors(t *testing.T) { Host: "", Path: "/", Queries: nil, - HttpMethod: "GET", + HttpMethod: mir.MethodGet, MethodName: "Index", Comment: "", }, diff --git a/internal/generator/templates.go b/internal/generator/templates.go index ef870b1..79aa0a6 100644 --- a/internal/generator/templates.go +++ b/internal/generator/templates.go @@ -10,8 +10,8 @@ import ( "strings" "text/template" - "github.com/alimy/mir/v2" "github.com/alimy/mir/v2/core" + "github.com/alimy/mir/v2/internal/utils" ) //go:embed templates @@ -40,11 +40,11 @@ func templateFrom(name string) (*template.Template, error) { return nil, err } t := template.New("mir").Funcs(template.FuncMap{ - "notEmptyStr": notEmptyStr, - "notHttpAny": notHttpAny, - "joinPath": joinPath, - "valideQuery": valideQuery, - "inflateQuery": inflateQuery, + "notEmptyStr": notEmptyStr, + "joinPath": joinPath, + "valideQuery": valideQuery, + "inflateQuery": inflateQuery, + "upperFirstName": upperFirstName, }) if tmpl, err := t.Parse(string(data)); err == nil { return tmpl, nil @@ -57,10 +57,6 @@ func notEmptyStr(s string) bool { return s != "" } -func notHttpAny(m string) bool { - return m != mir.MethodAny -} - func joinPath(group, subpath string) string { if group == "" { return subpath @@ -93,3 +89,7 @@ func inflateQuery(qs []string) string { } return strings.TrimRight(b.String(), ",") } + +func upperFirstName(name string) string { + return utils.UpperFirst(strings.ToLower(name)) +} diff --git a/internal/generator/templates/chi_iface.tmpl b/internal/generator/templates/chi_iface.tmpl index e43f4c3..20b73b3 100644 --- a/internal/generator/templates/chi_iface.tmpl +++ b/internal/generator/templates/chi_iface.tmpl @@ -30,7 +30,7 @@ func Register{{.TypeName}}Servant(r chi.Router, s {{.TypeName}}) { router.Use(middlewares...) {{end}} // register routes info to router -{{range .Fields}}{{if notHttpAny .HttpMethod }} router.MethodFunc("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else}} router.Head("{{.Path}}", s.{{.MethodName}}) +{{range .Fields}}{{if .NotHttpAny}} router.MethodFunc("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else if .JustHttpAny}} router.Head("{{.Path}}", s.{{.MethodName}}) router.Get("{{.Path}}", s.{{.MethodName}}) router.Post("{{.Path}}", s.{{.MethodName}}) router.Put("{{.Path}}", s.{{.MethodName}}) @@ -38,7 +38,8 @@ func Register{{.TypeName}}Servant(r chi.Router, s {{.TypeName}}) { router.Patch("{{.Path}}", s.{{.MethodName}}) router.Options("{{.Path}}", s.{{.MethodName}}) router.Connect("{{.Path}}", s.{{.MethodName}}) - router.Trace("{{.Path}}", s.{{.MethodName}}){{end}} + router.Trace("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} router.MethodFunc("{{.}}", "{{$field.Path}}", s.{{$field.MethodName}}) +{{end}}{{end}} {{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/echo_iface.tmpl b/internal/generator/templates/echo_iface.tmpl index 6c6b1bc..f7f1d04 100644 --- a/internal/generator/templates/echo_iface.tmpl +++ b/internal/generator/templates/echo_iface.tmpl @@ -28,7 +28,8 @@ func Register{{.TypeName}}Servant(e *echo.Echo, s {{.TypeName}}) { g.Use(middlewares...) {{end}} // register routes info to router -{{range .Fields}}{{if notHttpAny .HttpMethod }} g.Add("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else}} g.Any("{{.Path}}", s.{{.MethodName}}){{end}} +{{range .Fields}}{{if .NotHttpAny }} g.Add("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else if .JustHttpAny}} g.Any("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} g.Add("{{.}}", "{{$field.Path}}", s.{{$field.MethodName}}) +{{end}}{{end}} {{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/fiber_iface.tmpl b/internal/generator/templates/fiber_iface.tmpl index ab241e7..0ddf3fb 100644 --- a/internal/generator/templates/fiber_iface.tmpl +++ b/internal/generator/templates/fiber_iface.tmpl @@ -30,7 +30,8 @@ func Register{{.TypeName}}Servant(app *fiber.App, s {{.TypeName}}) { router.Use(middlewares...) {{end}} // register routes info to router -{{range .Fields}}{{if eq .HttpMethod "GET" }} router.Get("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "POST"}} router.Post("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "PUT"}} router.Put("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "DELETE"}} router.Delete("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "HEAD"}} router.Head("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "OPTIONS"}} router.Options("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "TRACE"}} router.Trace("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "PATCH"}} router.Patch("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "CONNECT"}} router.Connect("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "ANY" }} router.All("{{.Path}}", s.{{.MethodName}}){{end}} +{{range .Fields}}{{if .NotHttpAny }} router.Add("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else if .JustHttpAny}} router.All("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} router.Add("{{.}}", "{{$field.Path}}", s.{{$field.MethodName}}) +{{end}}{{end}} {{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/fiber_iface_v2.tmpl b/internal/generator/templates/fiber_iface_v2.tmpl index be7e645..c9a3026 100644 --- a/internal/generator/templates/fiber_iface_v2.tmpl +++ b/internal/generator/templates/fiber_iface_v2.tmpl @@ -30,7 +30,8 @@ func Register{{.TypeName}}Servant(app *fiber.App, s {{.TypeName}}) { router.Use(middlewares...) {{end}} // register routes info to router -{{range .Fields}}{{if eq .HttpMethod "GET" }} router.Get("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "POST"}} router.Post("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "PUT"}} router.Put("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "DELETE"}} router.Delete("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "HEAD"}} router.Head("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "OPTIONS"}} router.Options("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "TRACE"}} router.Trace("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "PATCH"}} router.Patch("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "CONNECT"}} router.Connect("{{.Path}}", s.{{.MethodName}}){{else if eq .HttpMethod "ANY" }} router.All("{{.Path}}", s.{{.MethodName}}){{end}} +{{range .Fields}}{{if .NotHttpAny }} router.Add("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else if .JustHttpAny}} router.All("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} router.Add("{{.}}", "{{$field.Path}}", s.{{$field.MethodName}}) +{{end}}{{end}} {{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/gin_iface.tmpl b/internal/generator/templates/gin_iface.tmpl index 0f69d08..c9444a8 100644 --- a/internal/generator/templates/gin_iface.tmpl +++ b/internal/generator/templates/gin_iface.tmpl @@ -28,7 +28,8 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}) { router.Use(middlewares...) {{end}} // register routes info to router -{{range .Fields}}{{if notHttpAny .HttpMethod }} router.Handle("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else}} router.Any("{{.Path}}", s.{{.MethodName}}){{end}} +{{range .Fields}}{{if .NotHttpAny }} router.Handle("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else if .JustHttpAny}} router.Any("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} router.Handle("{{.}}", "{{$field.Path}}", s.{{$field.MethodName}}) +{{end}}{{end}} {{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/httprouter_iface.tmpl b/internal/generator/templates/httprouter_iface.tmpl index 2a061fa..6638002 100644 --- a/internal/generator/templates/httprouter_iface.tmpl +++ b/internal/generator/templates/httprouter_iface.tmpl @@ -20,7 +20,7 @@ type {{.TypeName}} interface { // Register{{.TypeName}}Servant register {{.TypeName}} servant to httprouter func Register{{.TypeName}}Servant(r *httprouter.Router, s {{.TypeName}}) { -{{range .Fields}}{{if notHttpAny .HttpMethod }} r.Handle("{{.HttpMethod}}", "{{joinPath $.Group .Path}}", s.{{.MethodName}}){{else}} r.Handle(http.MethodGet, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) +{{range .Fields}}{{if .NotHttpAny }} r.Handle("{{.HttpMethod}}", "{{joinPath $.Group .Path}}", s.{{.MethodName}}){{else if .JustHttpAny}} r.Handle(http.MethodGet, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) r.Handle(http.MethodPut, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) r.Handle(http.MethodPost, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) r.Handle(http.MethodDelete, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) @@ -28,7 +28,8 @@ func Register{{.TypeName}}Servant(r *httprouter.Router, s {{.TypeName}}) { r.Handle(http.MethodPatch, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) r.Handle(http.MethodOptions, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) r.Handle(http.MethodConnect, "{{joinPath $.Group .Path}}", s.{{.MethodName}}) - r.Handle(http.MethodTrace, "{{joinPath $.Group .Path}}", s.{{.MethodName}}){{end}} + r.Handle(http.MethodTrace, "{{joinPath $.Group .Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} r.Handle("{{.}}", "{{joinPath $.Group $field.Path}}", s.{{$field.MethodName}}) +{{end}}{{end}} {{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/iris_iface.tmpl b/internal/generator/templates/iris_iface.tmpl index 5edda9c..f76d57f 100644 --- a/internal/generator/templates/iris_iface.tmpl +++ b/internal/generator/templates/iris_iface.tmpl @@ -30,7 +30,8 @@ func Register{{.TypeName}}Servant(app *iris.Application, s {{.TypeName}}) { p.Use(middlewares...) {{end}} // register routes info to party -{{range .Fields}}{{if notHttpAny .HttpMethod }} p.Handle("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else}} p.Any("{{.Path}}", s.{{.MethodName}}){{end}} +{{range .Fields}}{{if .NotHttpAny}} p.Handle("{{.HttpMethod}}", "{{.Path}}", s.{{.MethodName}}){{else if .JustHttpAny}} p.Any("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} p.Handle("{{.}}", "{{$field.Path}}", s.{{$field.MethodName}}) +{{end}}{{end}} {{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/macaron_iface.tmpl b/internal/generator/templates/macaron_iface.tmpl index 4915e64..45ebec9 100644 --- a/internal/generator/templates/macaron_iface.tmpl +++ b/internal/generator/templates/macaron_iface.tmpl @@ -25,15 +25,18 @@ func Register{{.TypeName}}Servant(m *macaron.Macaron, s {{.TypeName}}) { {{if notEmptyStr .Group }}{{if notEmptyStr .Chain }} // use chain for router middlewares := s.{{.Chain}}() m.Group("{{.Group}}", func() { -{{range .Fields}}{{if notHttpAny .HttpMethod }} m.Handle("{{.HttpMethod}}", "{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{else}} m.Any("{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{end}} +{{range .Fields}}{{if .NotHttpAny }} m.Handle("{{.HttpMethod}}", "{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{else if .JustHttpAny}} m.Any("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} m.Handle("{{.}}", "{{$field.Path}}", []macaron.Handler{s.{{$field.MethodName}}}) +{{end}}{{end}} {{end}}}, middlewares...){{else}} m.Group("{{.Group}}", func() { -{{range .Fields}}{{if notHttpAny .HttpMethod }} m.Handle("{{.HttpMethod}}", "{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{else}} m.Any("{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{end}} +{{range .Fields}}{{if .NotHttpAny }} m.Handle("{{.HttpMethod}}", "{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{else if .JustHttpAny}} m.Any("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} m.Handle("{{.}}", "{{$field.Path}}", []macaron.Handler{s.{{$field.MethodName}}}) +{{end}}{{end}} {{end}}}){{end}}{{else}}{{if notEmptyStr .Chain }} // use chain for router middlewares := s.{{.Chain}}() for _, middleware := range middlewares { m.Use(middleware) }{{end}} -{{range .Fields}}{{if notHttpAny .HttpMethod }} m.Handle("{{.HttpMethod}}", "{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{else}} m.Any("{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{end}} +{{range .Fields}}{{if .NotHttpAny }} m.Handle("{{.HttpMethod}}", "{{.Path}}", []macaron.Handler{s.{{.MethodName}}}){{else if .JustHttpAny}} m.Any("{{.Path}}", s.{{.MethodName}}){{else}}{{$field := .}}{{range .AnyHttpMethods}} m.Handle("{{.}}", "{{$field.Path}}", []macaron.Handler{s.{{$field.MethodName}}}) +{{end}}{{end}} {{end}}{{end}}} {{ $unimplementedServant := print "Unimplemented" .TypeName "Servant" }} diff --git a/internal/generator/templates/mux_iface.tmpl b/internal/generator/templates/mux_iface.tmpl index 61640f6..48141d4 100644 --- a/internal/generator/templates/mux_iface.tmpl +++ b/internal/generator/templates/mux_iface.tmpl @@ -5,14 +5,9 @@ package {{ .PkgName }} import ( "net/http" - "github.com/alimy/mir/v2" - mux "{{if notEmptyStr .EngineInfo.PkgName }}{{ .EngineInfo.PkgName }}{{else}}github.com/gorilla/mux{{end}}" ) -// just use for mir.Any method to register -var httpMethods = mir.HttpMethods - {{if notEmptyStr .Comment }}// {{.Comment}}{{end}} type {{.TypeName}} interface { {{if notEmptyStr .Chain }} // Chain provide middlewares for mux @@ -35,11 +30,11 @@ func Register{{.TypeName}}Servant(r *mux.Router, s {{.TypeName}}) { {{end}} // register routes info to router -{{range .Fields}}{{if notHttpAny .HttpMethod }} router.HandleFunc("{{.Path}}", s.{{.MethodName}}). +{{range .Fields}}{{if .NotHttpAny }} router.HandleFunc("{{.Path}}", s.{{.MethodName}}). Methods("{{.HttpMethod}}"){{if notEmptyStr .Host}}. Host("{{.Host}}"){{end}}{{if valideQuery .Queries}}. Queries({{inflateQuery .Queries}}){{end}}{{else}} router.HandleFunc("{{.Path}}", s.{{.MethodName}}). - Methods(httpMethods...){{if notEmptyStr .Host}}. + Methods({{.HttpMethodArgs}}){{if notEmptyStr .Host}}. Host("{{.Host}}"){{end}}{{if valideQuery .Queries}}. Queries({{inflateQuery .Queries}}){{end}}{{end}} {{end}}} diff --git a/internal/parser/fields.go b/internal/parser/fields.go index c322d96..c2c0766 100644 --- a/internal/parser/fields.go +++ b/internal/parser/fields.go @@ -5,12 +5,13 @@ package parser import ( + "errors" + "net/http" "reflect" "strings" - "unicode" - "unicode/utf8" "github.com/alimy/mir/v2" + "github.com/alimy/mir/v2/internal/utils" ) var ( @@ -23,7 +24,8 @@ var ( errMultChainInfo tagError = "multiple chain info in struct defined" // defaultTag indicate default mir's struct tag name - defaultTag = "mir" + defaultTag = "mir" + defautlMethodTag = "method" ) // tagError indicate error information @@ -36,7 +38,7 @@ func (e tagError) Error() string { // tagInfo indicate mir tag information in struct tag string type tagInfo struct { - Method string // Method indicate method information in struct tag string + Method string // Method indicate methods information in struct tag string Host string // Host indicate host information in struct tag string Path string // Path indicate path information in struct tag string Queries []string // Queries indicate path information in struct tag string @@ -95,7 +97,15 @@ func (r *reflex) tagInfoFrom(field reflect.StructField) (*tagInfo, error) { case "Connect": info.Method = mir.MethodConnect case "Any": - info.Method = "ANY" + if methodTag, exist := field.Tag.Lookup(defautlMethodTag); exist { + if methods, ok := r.anyMethodsFromTag(methodTag); ok { + info.Method = mir.MethodAny + ":" + strings.Join(methods, ",") + break + } + } + info.Method = mir.MethodAny + default: + return nil, errors.New("not supported filed type") } // host info @@ -156,22 +166,38 @@ func (r *reflex) tagInfoFrom(field reflect.StructField) (*tagInfo, error) { // check handler if not group field if info.handler == "" { - firstRune, size := utf8.DecodeRuneInString(field.Name) - upperFirst := unicode.ToUpper(firstRune) - - // encode upperFirst to []byte,use max byte for contain unicode - methoName := make([]byte, 4) - number := utf8.EncodeRune(methoName, upperFirst) - methoName = methoName[:number] - methoName = append(methoName, field.Name[size:]...) - // assign handler name - info.handler = string(methoName) + info.handler = utils.UpperFirst(field.Name) } return info, nil } +func (r *reflex) anyMethodsFromTag(value string) ([]string, bool) { + anyMethod := strings.TrimSpace(value) + methods := strings.Split(anyMethod, ",") + res := make([]string, 0, len(methods)) + for _, method := range methods { + method = strings.ToUpper(strings.TrimSpace(method)) + switch method { + case http.MethodGet, + http.MethodHead, + http.MethodPost, + http.MethodPut, + http.MethodPatch, + http.MethodDelete, + http.MethodConnect, + http.MethodOptions, + http.MethodTrace: + res = append(res, method) + } + } + if len(res) > 0 { + return res, true + } + return nil, false +} + func (r *reflex) inflateQuery(qs string) []string { items := strings.Split(qs, "&") res := make([]string, 0, len(items)*2) diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 0000000..a76722c --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,53 @@ +// Copyright 2022 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 utils + +import ( + "strings" + "unicode" + "unicode/utf8" +) + +// UpperFirst make first rune upper in s string +func UpperFirst(s string) string { + firstRune, size := utf8.DecodeRuneInString(s) + if unicode.IsUpper(firstRune) { + return s + } + // encode upperFirst to []byte,use max byte for contain unicode + res := make([]byte, len(s)) + upperRune := unicode.ToUpper(firstRune) + number := utf8.EncodeRune(res, upperRune) + res = res[:number] + res = append(res, s[size:]...) + return string(res) +} + +// QuoteJoin give a string slice return a quoted join string by sep +func QuoteJoin(elems []string, sep string) string { + switch len(elems) { + case 0: + return "" + case 1: + return elems[0] + } + n := len(sep) * (len(elems) - 1) + for i := 0; i < len(elems); i++ { + n += len(elems[i]) + 2 + } + + var b strings.Builder + b.Grow(n) + b.WriteByte('"') + b.WriteString(elems[0]) + b.WriteByte('"') + for _, s := range elems[1:] { + b.WriteString(sep) + b.WriteByte('"') + b.WriteString(s) + b.WriteByte('"') + } + return b.String() +} diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go new file mode 100644 index 0000000..06e2515 --- /dev/null +++ b/internal/utils/utils_test.go @@ -0,0 +1,40 @@ +// Copyright 2022 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 utils + +import "testing" + +func TestUpperFirst(t *testing.T) { + for input, expect := range map[string]string{ + "Options": "Options", + "get": "Get", + "post": "Post", + "head": "Head", + } { + if res := UpperFirst(input); res != expect { + t.Errorf("expect %s but got %s", expect, res) + } + } +} + +func TestQuoteJoin(t *testing.T) { + for _, data := range []struct { + input []string + expect string + }{ + { + input: []string{"GET", "POST", "HEAD"}, + expect: `"GET","POST","HEAD"`, + }, + { + input: []string{"Options", "Trace", "Post"}, + expect: `"Options","Trace","Post"`, + }, + } { + if res := QuoteJoin(data.input, ","); res != data.expect { + t.Errorf("expect (%s) but got (%s)", data.expect, res) + } + } +} diff --git a/mirc/cmd/templates/chi-v5/go.mod.tmpl b/mirc/cmd/templates/chi-v5/go.mod.tmpl index 4f05601..43404ae 100644 --- a/mirc/cmd/templates/chi-v5/go.mod.tmpl +++ b/mirc/cmd/templates/chi-v5/go.mod.tmpl @@ -3,7 +3,7 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/go-chi/chi/v5 {{ .VersionOfEngine "v5.0.7" }} ) {{if notEmptyStr .MirPkgName }} diff --git a/mirc/cmd/templates/chi-v5/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/chi-v5/mirc/auto/api/site.go.tmpl index b2a2598..e216501 100644 --- a/mirc/cmd/templates/chi-v5/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/chi-v5/mirc/auto/api/site.go.tmpl @@ -14,8 +14,18 @@ type Site interface { Index(http.ResponseWriter, *http.Request) Articles(http.ResponseWriter, *http.Request) + Category(http.ResponseWriter, *http.Request) + Login(http.ResponseWriter, *http.Request) + Logout(http.ResponseWriter, *http.Request) + Assets(http.ResponseWriter, *http.Request) + Others(http.ResponseWriter, *http.Request) + Logs(http.ResponseWriter, *http.Request) + Status(http.ResponseWriter, *http.Request) + Admin(http.ResponseWriter, *http.Request) + Dashboard(http.ResponseWriter, *http.Request) + HomePage(http.ResponseWriter, *http.Request) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to chi @@ -29,6 +39,37 @@ func RegisterSiteServant(r chi.Router, s Site) { // register routes info to router router.MethodFunc("GET", "/index/", s.Index) router.MethodFunc("GET", "/articles/{category}/{id:[0-9]+}", s.Articles) + router.MethodFunc("GET", "/category/", s.Category) + router.MethodFunc("POST", "/login", s.Login) + router.MethodFunc("POST", "/logout", s.Logout) + router.MethodFunc("HEAD", "/assets", s.Assets) + router.MethodFunc("GET", "/assets", s.Assets) + + router.Head("/others", s.Others) + router.Get("/others", s.Others) + router.Post("/others", s.Others) + router.Put("/others", s.Others) + router.Delete("/others", s.Others) + router.Patch("/others", s.Others) + router.Options("/others", s.Others) + router.Connect("/others", s.Others) + router.Trace("/others", s.Others) + router.Head("/logs", s.Logs) + router.Get("/logs", s.Logs) + router.Post("/logs", s.Logs) + router.Put("/logs", s.Logs) + router.Delete("/logs", s.Logs) + router.Patch("/logs", s.Logs) + router.Options("/logs", s.Logs) + router.Connect("/logs", s.Logs) + router.Trace("/logs", s.Logs) + router.MethodFunc("GET", "/Status", s.Status) + router.MethodFunc("POST", "/Status", s.Status) + router.MethodFunc("HEAD", "/Status", s.Status) + + router.MethodFunc("GET", "/admin", s.Admin) + router.MethodFunc("GET", "/dashboard", s.Dashboard) + router.MethodFunc("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -49,4 +90,54 @@ func (UnimplementedSiteServant) Articles(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Articles not implemented")) } +func (UnimplementedSiteServant) Category(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Category not implemented")) +} + +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/chi-v5/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/chi-v5/mirc/auto/api/v1/site.go.tmpl index b75ca83..832b621 100644 --- a/mirc/cmd/templates/chi-v5/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/chi-v5/mirc/auto/api/v1/site.go.tmpl @@ -14,6 +14,16 @@ type Site interface { Index(http.ResponseWriter, *http.Request) Articles(http.ResponseWriter, *http.Request) + Category(http.ResponseWriter, *http.Request) + Login(http.ResponseWriter, *http.Request) + Logout(http.ResponseWriter, *http.Request) + Assets(http.ResponseWriter, *http.Request) + Others(http.ResponseWriter, *http.Request) + Logs(http.ResponseWriter, *http.Request) + Status(http.ResponseWriter, *http.Request) + Admin(http.ResponseWriter, *http.Request) + Dashboard(http.ResponseWriter, *http.Request) + HomePage(http.ResponseWriter, *http.Request) mustEmbedUnimplementedSiteServant() } @@ -30,6 +40,37 @@ func RegisterSiteServant(r chi.Router, s Site) { // register routes info to router router.MethodFunc("GET", "/index/", s.Index) router.MethodFunc("GET", "/articles/{category}/{id:[0-9]+}", s.Articles) + router.MethodFunc("GET", "/category/", s.Category) + router.MethodFunc("POST", "/login", s.Login) + router.MethodFunc("POST", "/logout", s.Logout) + router.MethodFunc("HEAD", "/assets", s.Assets) + router.MethodFunc("GET", "/assets", s.Assets) + + router.Head("/others", s.Others) + router.Get("/others", s.Others) + router.Post("/others", s.Others) + router.Put("/others", s.Others) + router.Delete("/others", s.Others) + router.Patch("/others", s.Others) + router.Options("/others", s.Others) + router.Connect("/others", s.Others) + router.Trace("/others", s.Others) + router.Head("/logs", s.Logs) + router.Get("/logs", s.Logs) + router.Post("/logs", s.Logs) + router.Put("/logs", s.Logs) + router.Delete("/logs", s.Logs) + router.Patch("/logs", s.Logs) + router.Options("/logs", s.Logs) + router.Connect("/logs", s.Logs) + router.Trace("/logs", s.Logs) + router.MethodFunc("GET", "/Status", s.Status) + router.MethodFunc("POST", "/Status", s.Status) + router.MethodFunc("HEAD", "/Status", s.Status) + + router.MethodFunc("GET", "/admin", s.Admin) + router.MethodFunc("GET", "/dashboard", s.Dashboard) + router.MethodFunc("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -50,4 +91,54 @@ func (UnimplementedSiteServant) Articles(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Articles not implemented")) } +func (UnimplementedSiteServant) Category(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Category not implemented")) +} + +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/chi-v5/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/chi-v5/mirc/auto/api/v2/site.go.tmpl index 2506129..dc37dea 100644 --- a/mirc/cmd/templates/chi-v5/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/chi-v5/mirc/auto/api/v2/site.go.tmpl @@ -13,7 +13,7 @@ type Site interface { Articles(http.ResponseWriter, *http.Request) Category(http.ResponseWriter, *http.Request) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to chi diff --git a/mirc/cmd/templates/chi-v5/mirc/routes/site.go.tmpl b/mirc/cmd/templates/chi-v5/mirc/routes/site.go.tmpl index 18761cf..57fe8ba 100644 --- a/mirc/cmd/templates/chi-v5/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/chi-v5/mirc/routes/site.go.tmpl @@ -11,7 +11,17 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` + Category Get `mir:"/category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/chi-v5/mirc/routes/v1/site.go.tmpl b/mirc/cmd/templates/chi-v5/mirc/routes/v1/site.go.tmpl index 8227108..cf1f567 100644 --- a/mirc/cmd/templates/chi-v5/mirc/routes/v1/site.go.tmpl +++ b/mirc/cmd/templates/chi-v5/mirc/routes/v1/site.go.tmpl @@ -11,8 +11,18 @@ func init() { // Site site v1 interface info type Site struct { - Chain Chain `mir:"-"` - Group Group `mir:"/v1"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` + Chain Chain `mir:"-"` + Group Group `mir:"/v1"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` + Category Get `mir:"/category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/chi/go.mod.tmpl b/mirc/cmd/templates/chi/go.mod.tmpl index 2217c99..bb07956 100644 --- a/mirc/cmd/templates/chi/go.mod.tmpl +++ b/mirc/cmd/templates/chi/go.mod.tmpl @@ -3,7 +3,7 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/go-chi/chi {{ .VersionOfEngine "v4.1.2+incompatible" }} ) {{if notEmptyStr .MirPkgName }} diff --git a/mirc/cmd/templates/chi/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/chi/mirc/auto/api/site.go.tmpl index 7581925..6705b0e 100644 --- a/mirc/cmd/templates/chi/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/chi/mirc/auto/api/site.go.tmpl @@ -14,8 +14,18 @@ type Site interface { Index(http.ResponseWriter, *http.Request) Articles(http.ResponseWriter, *http.Request) + Category(http.ResponseWriter, *http.Request) + Login(http.ResponseWriter, *http.Request) + Logout(http.ResponseWriter, *http.Request) + Assets(http.ResponseWriter, *http.Request) + Others(http.ResponseWriter, *http.Request) + Logs(http.ResponseWriter, *http.Request) + Status(http.ResponseWriter, *http.Request) + Admin(http.ResponseWriter, *http.Request) + Dashboard(http.ResponseWriter, *http.Request) + HomePage(http.ResponseWriter, *http.Request) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to chi @@ -29,6 +39,37 @@ func RegisterSiteServant(r chi.Router, s Site) { // register routes info to router router.MethodFunc("GET", "/index/", s.Index) router.MethodFunc("GET", "/articles/{category}/{id:[0-9]+}", s.Articles) + router.MethodFunc("GET", "/category/", s.Category) + router.MethodFunc("POST", "/login", s.Login) + router.MethodFunc("POST", "/logout", s.Logout) + router.MethodFunc("HEAD", "/assets", s.Assets) + router.MethodFunc("GET", "/assets", s.Assets) + + router.Head("/others", s.Others) + router.Get("/others", s.Others) + router.Post("/others", s.Others) + router.Put("/others", s.Others) + router.Delete("/others", s.Others) + router.Patch("/others", s.Others) + router.Options("/others", s.Others) + router.Connect("/others", s.Others) + router.Trace("/others", s.Others) + router.Head("/logs", s.Logs) + router.Get("/logs", s.Logs) + router.Post("/logs", s.Logs) + router.Put("/logs", s.Logs) + router.Delete("/logs", s.Logs) + router.Patch("/logs", s.Logs) + router.Options("/logs", s.Logs) + router.Connect("/logs", s.Logs) + router.Trace("/logs", s.Logs) + router.MethodFunc("GET", "/Status", s.Status) + router.MethodFunc("POST", "/Status", s.Status) + router.MethodFunc("HEAD", "/Status", s.Status) + + router.MethodFunc("GET", "/admin", s.Admin) + router.MethodFunc("GET", "/dashboard", s.Dashboard) + router.MethodFunc("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -49,4 +90,54 @@ func (UnimplementedSiteServant) Articles(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Articles not implemented")) } +func (UnimplementedSiteServant) Category(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Category not implemented")) +} + +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/chi/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/chi/mirc/auto/api/v2/site.go.tmpl index fae22d4..b1af373 100644 --- a/mirc/cmd/templates/chi/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/chi/mirc/auto/api/v2/site.go.tmpl @@ -12,8 +12,17 @@ type Site interface { Index(http.ResponseWriter, *http.Request) Articles(http.ResponseWriter, *http.Request) Category(http.ResponseWriter, *http.Request) + Login(http.ResponseWriter, *http.Request) + Logout(http.ResponseWriter, *http.Request) + Assets(http.ResponseWriter, *http.Request) + Others(http.ResponseWriter, *http.Request) + Logs(http.ResponseWriter, *http.Request) + Status(http.ResponseWriter, *http.Request) + Admin(http.ResponseWriter, *http.Request) + Dashboard(http.ResponseWriter, *http.Request) + HomePage(http.ResponseWriter, *http.Request) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to chi @@ -25,6 +34,36 @@ func RegisterSiteServant(r chi.Router, s Site) { router.MethodFunc("GET", "/index/", s.Index) router.MethodFunc("GET", "/articles/{category}/{id:[0-9]+}", s.Articles) router.MethodFunc("GET", "/category/", s.Category) + router.MethodFunc("POST", "/login", s.Login) + router.MethodFunc("POST", "/logout", s.Logout) + router.MethodFunc("HEAD", "/assets", s.Assets) + router.MethodFunc("GET", "/assets", s.Assets) + + router.Head("/others", s.Others) + router.Get("/others", s.Others) + router.Post("/others", s.Others) + router.Put("/others", s.Others) + router.Delete("/others", s.Others) + router.Patch("/others", s.Others) + router.Options("/others", s.Others) + router.Connect("/others", s.Others) + router.Trace("/others", s.Others) + router.Head("/logs", s.Logs) + router.Get("/logs", s.Logs) + router.Post("/logs", s.Logs) + router.Put("/logs", s.Logs) + router.Delete("/logs", s.Logs) + router.Patch("/logs", s.Logs) + router.Options("/logs", s.Logs) + router.Connect("/logs", s.Logs) + router.Trace("/logs", s.Logs) + router.MethodFunc("GET", "/Status", s.Status) + router.MethodFunc("POST", "/Status", s.Status) + router.MethodFunc("HEAD", "/Status", s.Status) + + router.MethodFunc("GET", "/admin", s.Admin) + router.MethodFunc("GET", "/dashboard", s.Dashboard) + router.MethodFunc("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -46,4 +85,49 @@ func (UnimplementedSiteServant) Category(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Category not implemented")) } +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/chi/mirc/routes/site.go.tmpl b/mirc/cmd/templates/chi/mirc/routes/site.go.tmpl index 18761cf..57fe8ba 100644 --- a/mirc/cmd/templates/chi/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/chi/mirc/routes/site.go.tmpl @@ -11,7 +11,17 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` + Category Get `mir:"/category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/chi/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/chi/mirc/routes/v2/site.go.tmpl index a74351f..06e3212 100644 --- a/mirc/cmd/templates/chi/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/chi/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,17 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"/v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` - Category Get `mir:"/category/"` + Group Group `mir:"/v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/{category}/{id:[0-9]+}"` + Category Get `mir:"/category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/echo/go.mod.tmpl b/mirc/cmd/templates/echo/go.mod.tmpl index 378954f..edffe7c 100644 --- a/mirc/cmd/templates/echo/go.mod.tmpl +++ b/mirc/cmd/templates/echo/go.mod.tmpl @@ -3,7 +3,7 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/labstack/echo/v4 {{ .VersionOfEngine "v4.6.1" }} ) {{if notEmptyStr .MirPkgName }} diff --git a/mirc/cmd/templates/echo/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/echo/mirc/auto/api/site.go.tmpl index aff22ea..46815e5 100644 --- a/mirc/cmd/templates/echo/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/echo/mirc/auto/api/site.go.tmpl @@ -13,9 +13,20 @@ type Site interface { Chain() []echo.MiddlewareFunc Index(echo.Context) error + Titles(echo.Context) error Articles(echo.Context) error + Category(echo.Context) error + Login(echo.Context) error + Logout(echo.Context) error + Assets(echo.Context) error + Others(echo.Context) error + Logs(echo.Context) error + Status(echo.Context) error + Admin(echo.Context) error + Dashboard(echo.Context) error + HomePage(echo.Context) error - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to echo @@ -27,7 +38,23 @@ func RegisterSiteServant(e *echo.Echo, s Site) { // register routes info to router g.Add("GET", "/index/", s.Index) - g.Add("GET", "/articles/:category/", s.Articles) + g.Add("POST", "/titles", s.Titles) + g.Any("/articles/:category/", s.Articles) + g.Add("GET", "/category/", s.Category) + g.Add("POST", "/login", s.Login) + g.Add("POST", "/logout", s.Logout) + g.Add("HEAD", "/assets", s.Assets) + g.Add("GET", "/assets", s.Assets) + + g.Any("/others", s.Others) + g.Any("/logs", s.Logs) + g.Add("GET", "/Status", s.Status) + g.Add("POST", "/Status", s.Status) + g.Add("HEAD", "/Status", s.Status) + + g.Add("GET", "/admin", s.Admin) + g.Add("GET", "/dashboard", s.Dashboard) + g.Add("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -43,9 +70,64 @@ func (UnimplementedSiteServant) Index(c echo.Context) error { return nil } +func (UnimplementedSiteServant) Titles(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Titles not implemented") + return nil +} + func (UnimplementedSiteServant) Articles(c echo.Context) error { c.String(http.StatusNotImplemented, "method Articles not implemented") return nil } +func (UnimplementedSiteServant) Category(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Category not implemented") + return nil +} + +func (UnimplementedSiteServant) Login(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Login not implemented") + return nil +} + +func (UnimplementedSiteServant) Logout(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Logout not implemented") + return nil +} + +func (UnimplementedSiteServant) Assets(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Assets not implemented") + return nil +} + +func (UnimplementedSiteServant) Others(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Others not implemented") + return nil +} + +func (UnimplementedSiteServant) Logs(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Logs not implemented") + return nil +} + +func (UnimplementedSiteServant) Status(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Status not implemented") + return nil +} + +func (UnimplementedSiteServant) Admin(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Admin not implemented") + return nil +} + +func (UnimplementedSiteServant) Dashboard(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Dashboard not implemented") + return nil +} + +func (UnimplementedSiteServant) HomePage(c echo.Context) error { + c.String(http.StatusNotImplemented, "method HomePage not implemented") + return nil +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/echo/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/echo/mirc/auto/api/v1/site.go.tmpl index 894caef..450d600 100644 --- a/mirc/cmd/templates/echo/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/echo/mirc/auto/api/v1/site.go.tmpl @@ -15,7 +15,7 @@ type Site interface { Index(echo.Context) error Articles(echo.Context) error - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to echo diff --git a/mirc/cmd/templates/echo/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/echo/mirc/auto/api/v2/site.go.tmpl index 107120c..4fc906c 100644 --- a/mirc/cmd/templates/echo/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/echo/mirc/auto/api/v2/site.go.tmpl @@ -12,8 +12,17 @@ type Site interface { Index(echo.Context) error Articles(echo.Context) error Category(echo.Context) error + Login(echo.Context) error + Logout(echo.Context) error + Assets(echo.Context) error + Others(echo.Context) error + Logs(echo.Context) error + Status(echo.Context) error + Admin(echo.Context) error + Dashboard(echo.Context) error + HomePage(echo.Context) error - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to echo @@ -24,6 +33,20 @@ func RegisterSiteServant(e *echo.Echo, s Site) { g.Add("GET", "/index/", s.Index) g.Add("GET", "/articles/:category/", s.Articles) g.Add("GET", "/category/", s.Category) + g.Add("POST", "/login", s.Login) + g.Add("POST", "/logout", s.Logout) + g.Add("HEAD", "/assets", s.Assets) + g.Add("GET", "/assets", s.Assets) + + g.Any("/others", s.Others) + g.Any("/logs", s.Logs) + g.Add("GET", "/Status", s.Status) + g.Add("POST", "/Status", s.Status) + g.Add("HEAD", "/Status", s.Status) + + g.Add("GET", "/admin", s.Admin) + g.Add("GET", "/dashboard", s.Dashboard) + g.Add("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -45,4 +68,49 @@ func (UnimplementedSiteServant) Category(c echo.Context) error { return nil } +func (UnimplementedSiteServant) Login(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Login not implemented") + return nil +} + +func (UnimplementedSiteServant) Logout(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Logout not implemented") + return nil +} + +func (UnimplementedSiteServant) Assets(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Assets not implemented") + return nil +} + +func (UnimplementedSiteServant) Others(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Others not implemented") + return nil +} + +func (UnimplementedSiteServant) Logs(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Logs not implemented") + return nil +} + +func (UnimplementedSiteServant) Status(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Status not implemented") + return nil +} + +func (UnimplementedSiteServant) Admin(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Admin not implemented") + return nil +} + +func (UnimplementedSiteServant) Dashboard(c echo.Context) error { + c.String(http.StatusNotImplemented, "method Dashboard not implemented") + return nil +} + +func (UnimplementedSiteServant) HomePage(c echo.Context) error { + c.String(http.StatusNotImplemented, "method HomePage not implemented") + return nil +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/echo/mirc/routes/site.go.tmpl b/mirc/cmd/templates/echo/mirc/routes/site.go.tmpl index bc53b37..b754428 100644 --- a/mirc/cmd/templates/echo/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/echo/mirc/routes/site.go.tmpl @@ -11,7 +11,18 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Titles Post `mir:"/titles"` + Articles Any `mir:"/articles/:category/"` + Category Get `mir:"/category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/echo/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/echo/mirc/routes/v2/site.go.tmpl index 2e29da1..fe49b5d 100644 --- a/mirc/cmd/templates/echo/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/echo/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,17 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` - Category Get `mir:"/category/"` + Group Group `mir:"v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Category Get `mir:"/category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/fiber-v2/go.mod.tmpl b/mirc/cmd/templates/fiber-v2/go.mod.tmpl index 959d4bc..f5d1b23 100644 --- a/mirc/cmd/templates/fiber-v2/go.mod.tmpl +++ b/mirc/cmd/templates/fiber-v2/go.mod.tmpl @@ -3,7 +3,7 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/gofiber/fiber/v2 {{ .VersionOfEngine "v2.24.0" }} ) {{if notEmptyStr .MirPkgName }} diff --git a/mirc/cmd/templates/fiber-v2/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/fiber-v2/mirc/auto/api/site.go.tmpl index a06fa5a..8d5fbe8 100644 --- a/mirc/cmd/templates/fiber-v2/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/fiber-v2/mirc/auto/api/site.go.tmpl @@ -16,8 +16,17 @@ type Site interface { Index(c *fiber.Ctx) error Articles(c *fiber.Ctx) error + Login(c *fiber.Ctx) error + Logout(c *fiber.Ctx) error + Assets(c *fiber.Ctx) error + Others(c *fiber.Ctx) error + Logs(c *fiber.Ctx) error + Status(c *fiber.Ctx) error + Admin(c *fiber.Ctx) error + Dashboard(c *fiber.Ctx) error + HomePage(c *fiber.Ctx) error - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to fiber @@ -28,8 +37,22 @@ func RegisterSiteServant(app *fiber.App, s Site) { router.Use(middlewares...) // register routes info to router - router.Get("/index/", s.Index) - router.Get("/articles/:category/", s.Articles) + router.Add("GET", "/index/", s.Index) + router.Add("GET", "/articles/:category/", s.Articles) + router.Add("POST", "/login", s.Login) + router.Add("POST", "/logout", s.Logout) + router.Add("HEAD", "/assets", s.Assets) + router.Add("GET", "/assets", s.Assets) + + router.All("/others", s.Others) + router.All("/logs", s.Logs) + router.Add("GET", "/Status", s.Status) + router.Add("POST", "/Status", s.Status) + router.Add("HEAD", "/Status", s.Status) + + router.Add("GET", "/admin", s.Admin) + router.Add("GET", "/dashboard", s.Dashboard) + router.Add("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -52,4 +75,58 @@ func (UnimplementedSiteServant) Articles(c *fiber.Ctx) error { return nil } +func (UnimplementedSiteServant) Login(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Login not implemented")) + return nil +} + +func (UnimplementedSiteServant) Logout(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logout not implemented")) + return nil +} + +func (UnimplementedSiteServant) Assets(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Assets not implemented")) + return nil +} + +func (UnimplementedSiteServant) Others(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Others not implemented")) + return nil +} + +func (UnimplementedSiteServant) Logs(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logs not implemented")) + return nil +} + +func (UnimplementedSiteServant) Status(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Status not implemented")) + return nil +} + +func (UnimplementedSiteServant) Admin(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Admin not implemented")) + return nil +} + +func (UnimplementedSiteServant) Dashboard(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Dashboard not implemented")) + return nil +} + +func (UnimplementedSiteServant) HomePage(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method HomePage not implemented")) + return nil +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/fiber-v2/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/fiber-v2/mirc/auto/api/v1/site.go.tmpl index f198b50..25c283b 100644 --- a/mirc/cmd/templates/fiber-v2/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/fiber-v2/mirc/auto/api/v1/site.go.tmpl @@ -17,7 +17,7 @@ type Site interface { Index(c *fiber.Ctx) error Articles(c *fiber.Ctx) error - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to fiber @@ -28,8 +28,8 @@ func RegisterSiteServant(app *fiber.App, s Site) { router.Use(middlewares...) // register routes info to router - router.Get("/index/", s.Index) - router.Get("/articles/:category/", s.Articles) + router.Add("GET", "/index/", s.Index) + router.Add("GET", "/articles/:category/", s.Articles) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. diff --git a/mirc/cmd/templates/fiber-v2/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/fiber-v2/mirc/auto/api/v2/site.go.tmpl index 2decc95..4d0daa1 100644 --- a/mirc/cmd/templates/fiber-v2/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/fiber-v2/mirc/auto/api/v2/site.go.tmpl @@ -11,9 +11,17 @@ import ( type Site interface { Index(c *fiber.Ctx) error Articles(c *fiber.Ctx) error - Category(c *fiber.Ctx) error + Login(c *fiber.Ctx) error + Logout(c *fiber.Ctx) error + Assets(c *fiber.Ctx) error + Others(c *fiber.Ctx) error + Logs(c *fiber.Ctx) error + Status(c *fiber.Ctx) error + Admin(c *fiber.Ctx) error + Dashboard(c *fiber.Ctx) error + HomePage(c *fiber.Ctx) error - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to fiber @@ -21,9 +29,22 @@ func RegisterSiteServant(app *fiber.App, s Site) { router := app.Group("v2") // register routes info to router - router.Get("/index/", s.Index) - router.Get("/articles/:category?", s.Articles) - router.Get("/category/", s.Category) + router.Add("GET", "/index/", s.Index) + router.Add("GET", "/articles/:category/", s.Articles) + router.Add("POST", "/login", s.Login) + router.Add("POST", "/logout", s.Logout) + router.Add("HEAD", "/assets", s.Assets) + router.Add("GET", "/assets", s.Assets) + + router.All("/others", s.Others) + router.All("/logs", s.Logs) + router.Add("GET", "/Status", s.Status) + router.Add("POST", "/Status", s.Status) + router.Add("HEAD", "/Status", s.Status) + + router.Add("GET", "/admin", s.Admin) + router.Add("GET", "/dashboard", s.Dashboard) + router.Add("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -42,9 +63,57 @@ func (UnimplementedSiteServant) Articles(c *fiber.Ctx) error { return nil } -func (UnimplementedSiteServant) Category(c *fiber.Ctx) error { +func (UnimplementedSiteServant) Login(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Login not implemented")) + return nil +} + +func (UnimplementedSiteServant) Logout(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logout not implemented")) + return nil +} + +func (UnimplementedSiteServant) Assets(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Assets not implemented")) + return nil +} + +func (UnimplementedSiteServant) Others(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Others not implemented")) + return nil +} + +func (UnimplementedSiteServant) Logs(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logs not implemented")) + return nil +} + +func (UnimplementedSiteServant) Status(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Status not implemented")) + return nil +} + +func (UnimplementedSiteServant) Admin(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Admin not implemented")) + return nil +} + +func (UnimplementedSiteServant) Dashboard(c *fiber.Ctx) error { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Dashboard not implemented")) + return nil +} + +func (UnimplementedSiteServant) HomePage(c *fiber.Ctx) error { c.Status(http.StatusNotImplemented) - c.Write([]byte("method Category not implemented")) + c.Write([]byte("method HomePage not implemented")) return nil } diff --git a/mirc/cmd/templates/fiber-v2/mirc/routes/site.go.tmpl b/mirc/cmd/templates/fiber-v2/mirc/routes/site.go.tmpl index bc53b37..dae19ff 100644 --- a/mirc/cmd/templates/fiber-v2/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/fiber-v2/mirc/routes/site.go.tmpl @@ -11,7 +11,16 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/fiber-v2/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/fiber-v2/mirc/routes/v2/site.go.tmpl index 215ef28..02ba8f2 100644 --- a/mirc/cmd/templates/fiber-v2/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/fiber-v2/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,16 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category?"` - Category Get `mir:"/category/"` + Group Group `mir:"v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/fiber/go.mod.tmpl b/mirc/cmd/templates/fiber/go.mod.tmpl index 73aa833..6356d59 100644 --- a/mirc/cmd/templates/fiber/go.mod.tmpl +++ b/mirc/cmd/templates/fiber/go.mod.tmpl @@ -3,8 +3,9 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/gofiber/fiber {{ .VersionOfEngine "v1.14.6" }} + golang.org/x/sys v0.0.0-20220405210540-1e041c57c461 // indirect ) {{if notEmptyStr .MirPkgName }} replace ( diff --git a/mirc/cmd/templates/fiber/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/fiber/mirc/auto/api/site.go.tmpl index f0972a9..29ab8fd 100644 --- a/mirc/cmd/templates/fiber/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/fiber/mirc/auto/api/site.go.tmpl @@ -16,8 +16,17 @@ type Site interface { Index(c *fiber.Ctx) Articles(c *fiber.Ctx) + Login(c *fiber.Ctx) + Logout(c *fiber.Ctx) + Assets(c *fiber.Ctx) + Others(c *fiber.Ctx) + Logs(c *fiber.Ctx) + Status(c *fiber.Ctx) + Admin(c *fiber.Ctx) + Dashboard(c *fiber.Ctx) + HomePage(c *fiber.Ctx) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to fiber @@ -28,8 +37,22 @@ func RegisterSiteServant(app *fiber.App, s Site) { router.Use(middlewares...) // register routes info to router - router.Get("/index/", s.Index) - router.Get("/articles/:category/", s.Articles) + router.Add("GET", "/index/", s.Index) + router.Add("GET", "/articles/:category/", s.Articles) + router.Add("POST", "/login", s.Login) + router.Add("POST", "/logout", s.Logout) + router.Add("HEAD", "/assets", s.Assets) + router.Add("GET", "/assets", s.Assets) + + router.All("/others", s.Others) + router.All("/logs", s.Logs) + router.Add("GET", "/Status", s.Status) + router.Add("POST", "/Status", s.Status) + router.Add("HEAD", "/Status", s.Status) + + router.Add("GET", "/admin", s.Admin) + router.Add("GET", "/dashboard", s.Dashboard) + router.Add("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -50,4 +73,49 @@ func (UnimplementedSiteServant) Articles(c *fiber.Ctx) { c.Write([]byte("method Articles not implemented")) } +func (UnimplementedSiteServant) Login(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/fiber/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/fiber/mirc/auto/api/v1/site.go.tmpl index fb3222a..530ee04 100644 --- a/mirc/cmd/templates/fiber/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/fiber/mirc/auto/api/v1/site.go.tmpl @@ -17,7 +17,7 @@ type Site interface { Index(c *fiber.Ctx) Articles(c *fiber.Ctx) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to fiber @@ -28,8 +28,8 @@ func RegisterSiteServant(app *fiber.App, s Site) { router.Use(middlewares...) // register routes info to router - router.Get("/index/", s.Index) - router.Get("/articles/:category/", s.Articles) + router.Add("GET", "/index/", s.Index) + router.Add("GET", "/articles/:category/", s.Articles) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. diff --git a/mirc/cmd/templates/fiber/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/fiber/mirc/auto/api/v2/site.go.tmpl index 62a1da3..5142c44 100644 --- a/mirc/cmd/templates/fiber/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/fiber/mirc/auto/api/v2/site.go.tmpl @@ -11,9 +11,17 @@ import ( type Site interface { Index(c *fiber.Ctx) Articles(c *fiber.Ctx) - Category(c *fiber.Ctx) + Login(c *fiber.Ctx) + Logout(c *fiber.Ctx) + Assets(c *fiber.Ctx) + Others(c *fiber.Ctx) + Logs(c *fiber.Ctx) + Status(c *fiber.Ctx) + Admin(c *fiber.Ctx) + Dashboard(c *fiber.Ctx) + HomePage(c *fiber.Ctx) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to fiber @@ -21,9 +29,22 @@ func RegisterSiteServant(app *fiber.App, s Site) { router := app.Group("v2") // register routes info to router - router.Get("/index/", s.Index) - router.Get("/articles/:category?", s.Articles) - router.Get("/category/", s.Category) + router.Add("GET", "/index/", s.Index) + router.Add("GET", "/articles/:category/", s.Articles) + router.Add("POST", "/login", s.Login) + router.Add("POST", "/logout", s.Logout) + router.Add("HEAD", "/assets", s.Assets) + router.Add("GET", "/assets", s.Assets) + + router.All("/others", s.Others) + router.All("/logs", s.Logs) + router.Add("GET", "/Status", s.Status) + router.Add("POST", "/Status", s.Status) + router.Add("HEAD", "/Status", s.Status) + + router.Add("GET", "/admin", s.Admin) + router.Add("GET", "/dashboard", s.Dashboard) + router.Add("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -40,9 +61,49 @@ func (UnimplementedSiteServant) Articles(c *fiber.Ctx) { c.Write([]byte("method Articles not implemented")) } -func (UnimplementedSiteServant) Category(c *fiber.Ctx) { +func (UnimplementedSiteServant) Login(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(c *fiber.Ctx) { + c.Status(http.StatusNotImplemented) + c.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(c *fiber.Ctx) { c.Status(http.StatusNotImplemented) - c.Write([]byte("method Category not implemented")) + c.Write([]byte("method HomePage not implemented")) } func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/fiber/mirc/routes/site.go.tmpl b/mirc/cmd/templates/fiber/mirc/routes/site.go.tmpl index bc53b37..dae19ff 100644 --- a/mirc/cmd/templates/fiber/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/fiber/mirc/routes/site.go.tmpl @@ -11,7 +11,16 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/fiber/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/fiber/mirc/routes/v2/site.go.tmpl index 215ef28..02ba8f2 100644 --- a/mirc/cmd/templates/fiber/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/fiber/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,16 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category?"` - Category Get `mir:"/category/"` + Group Group `mir:"v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/gin/go.mod.tmpl b/mirc/cmd/templates/gin/go.mod.tmpl index 5a05da5..2b43719 100644 --- a/mirc/cmd/templates/gin/go.mod.tmpl +++ b/mirc/cmd/templates/gin/go.mod.tmpl @@ -3,8 +3,9 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/gin-gonic/gin {{ .VersionOfEngine "v1.7.7" }} + golang.org/x/sys v0.0.0-20220405210540-1e041c57c461 // indirect ) {{if notEmptyStr .MirPkgName }} replace ( diff --git a/mirc/cmd/templates/gin/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/gin/mirc/auto/api/site.go.tmpl index a0e0ab5..6928603 100644 --- a/mirc/cmd/templates/gin/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/gin/mirc/auto/api/site.go.tmpl @@ -14,8 +14,17 @@ type Site interface { Index(*gin.Context) Articles(*gin.Context) + Login(*gin.Context) + Logout(*gin.Context) + Assets(*gin.Context) + Others(*gin.Context) + Logs(*gin.Context) + Status(*gin.Context) + Admin(*gin.Context) + Dashboard(*gin.Context) + HomePage(*gin.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to gin @@ -28,6 +37,20 @@ func RegisterSiteServant(e *gin.Engine, s Site) { // register routes info to router router.Handle("GET", "/index/", s.Index) router.Handle("GET", "/articles/:category/", s.Articles) + router.Handle("POST", "/login", s.Login) + router.Handle("POST", "/logout", s.Logout) + router.Handle("HEAD", "/assets", s.Assets) + router.Handle("GET", "/assets", s.Assets) + + router.Any("/others", s.Others) + router.Any("/logs", s.Logs) + router.Handle("GET", "/Status", s.Status) + router.Handle("POST", "/Status", s.Status) + router.Handle("HEAD", "/Status", s.Status) + + router.Handle("GET", "/admin", s.Admin) + router.Handle("GET", "/dashboard", s.Dashboard) + router.Handle("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -46,4 +69,40 @@ func (UnimplementedSiteServant) Articles(c *gin.Context) { c.String(http.StatusNotImplemented, "method Articles not implemented") } +func (UnimplementedSiteServant) Login(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Login not implemented") +} + +func (UnimplementedSiteServant) Logout(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Logout not implemented") +} + +func (UnimplementedSiteServant) Assets(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Assets not implemented") +} + +func (UnimplementedSiteServant) Others(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Others not implemented") +} + +func (UnimplementedSiteServant) Logs(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Logs not implemented") +} + +func (UnimplementedSiteServant) Status(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Status not implemented") +} + +func (UnimplementedSiteServant) Admin(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Admin not implemented") +} + +func (UnimplementedSiteServant) Dashboard(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Dashboard not implemented") +} + +func (UnimplementedSiteServant) HomePage(c *gin.Context) { + c.String(http.StatusNotImplemented, "method HomePage not implemented") +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/gin/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/gin/mirc/auto/api/v1/site.go.tmpl index f864e55..2c026d7 100644 --- a/mirc/cmd/templates/gin/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/gin/mirc/auto/api/v1/site.go.tmpl @@ -14,8 +14,17 @@ type Site interface { Index(*gin.Context) Articles(*gin.Context) + Login(*gin.Context) + Logout(*gin.Context) + Assets(*gin.Context) + Others(*gin.Context) + Logs(*gin.Context) + Status(*gin.Context) + Admin(*gin.Context) + Dashboard(*gin.Context) + HomePage(*gin.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to gin @@ -28,6 +37,20 @@ func RegisterSiteServant(e *gin.Engine, s Site) { // register routes info to router router.Handle("GET", "/index/", s.Index) router.Handle("GET", "/articles/:category/", s.Articles) + router.Handle("POST", "/login", s.Login) + router.Handle("POST", "/logout", s.Logout) + router.Handle("HEAD", "/assets", s.Assets) + router.Handle("GET", "/assets", s.Assets) + + router.Any("/others", s.Others) + router.Any("/logs", s.Logs) + router.Handle("GET", "/Status", s.Status) + router.Handle("POST", "/Status", s.Status) + router.Handle("HEAD", "/Status", s.Status) + + router.Handle("GET", "/admin", s.Admin) + router.Handle("GET", "/dashboard", s.Dashboard) + router.Handle("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -46,4 +69,40 @@ func (UnimplementedSiteServant) Articles(c *gin.Context) { c.String(http.StatusNotImplemented, "method Articles not implemented") } +func (UnimplementedSiteServant) Login(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Login not implemented") +} + +func (UnimplementedSiteServant) Logout(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Logout not implemented") +} + +func (UnimplementedSiteServant) Assets(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Assets not implemented") +} + +func (UnimplementedSiteServant) Others(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Others not implemented") +} + +func (UnimplementedSiteServant) Logs(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Logs not implemented") +} + +func (UnimplementedSiteServant) Status(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Status not implemented") +} + +func (UnimplementedSiteServant) Admin(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Admin not implemented") +} + +func (UnimplementedSiteServant) Dashboard(c *gin.Context) { + c.String(http.StatusNotImplemented, "method Dashboard not implemented") +} + +func (UnimplementedSiteServant) HomePage(c *gin.Context) { + c.String(http.StatusNotImplemented, "method HomePage not implemented") +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/gin/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/gin/mirc/auto/api/v2/site.go.tmpl index 8ddab38..13bdc12 100644 --- a/mirc/cmd/templates/gin/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/gin/mirc/auto/api/v2/site.go.tmpl @@ -13,7 +13,7 @@ type Site interface { Articles(*gin.Context) Category(*gin.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to gin diff --git a/mirc/cmd/templates/gin/mirc/routes/site.go.tmpl b/mirc/cmd/templates/gin/mirc/routes/site.go.tmpl index bc53b37..dae19ff 100644 --- a/mirc/cmd/templates/gin/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/gin/mirc/routes/site.go.tmpl @@ -11,7 +11,16 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/gin/mirc/routes/v1/site.go.tmpl b/mirc/cmd/templates/gin/mirc/routes/v1/site.go.tmpl index 559534b..2a88b16 100644 --- a/mirc/cmd/templates/gin/mirc/routes/v1/site.go.tmpl +++ b/mirc/cmd/templates/gin/mirc/routes/v1/site.go.tmpl @@ -11,8 +11,17 @@ func init() { // Site site v1 interface info type Site struct { - Chain Chain `mir:"-"` - Group Group `mir:"v1"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` + Chain Chain `mir:"-"` + Group Group `mir:"v1"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/httprouter/go.mod.tmpl b/mirc/cmd/templates/httprouter/go.mod.tmpl index c216cb9..13ee971 100644 --- a/mirc/cmd/templates/httprouter/go.mod.tmpl +++ b/mirc/cmd/templates/httprouter/go.mod.tmpl @@ -3,7 +3,7 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/julienschmidt/httprouter {{ .VersionOfEngine "v1.3.0" }} ) {{if notEmptyStr .MirPkgName }} diff --git a/mirc/cmd/templates/httprouter/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/httprouter/mirc/auto/api/site.go.tmpl index c8e0e65..fffd5a5 100644 --- a/mirc/cmd/templates/httprouter/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/httprouter/mirc/auto/api/site.go.tmpl @@ -11,14 +11,53 @@ import ( type Site interface { Index(http.ResponseWriter, *http.Request, httprouter.Params) Articles(http.ResponseWriter, *http.Request, httprouter.Params) + Login(http.ResponseWriter, *http.Request, httprouter.Params) + Logout(http.ResponseWriter, *http.Request, httprouter.Params) + Assets(http.ResponseWriter, *http.Request, httprouter.Params) + Others(http.ResponseWriter, *http.Request, httprouter.Params) + Logs(http.ResponseWriter, *http.Request, httprouter.Params) + Status(http.ResponseWriter, *http.Request, httprouter.Params) + Admin(http.ResponseWriter, *http.Request, httprouter.Params) + Dashboard(http.ResponseWriter, *http.Request, httprouter.Params) + HomePage(http.ResponseWriter, *http.Request, httprouter.Params) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to httprouter func RegisterSiteServant(r *httprouter.Router, s Site) { r.Handle("GET", "/index/", s.Index) r.Handle("GET", "/articles/:category/", s.Articles) + r.Handle("POST", "/login", s.Login) + r.Handle("POST", "/logout", s.Logout) + r.Handle("HEAD", "/assets", s.Assets) + r.Handle("GET", "/assets", s.Assets) + + r.Handle(http.MethodGet, "/others", s.Others) + r.Handle(http.MethodPut, "/others", s.Others) + r.Handle(http.MethodPost, "/others", s.Others) + r.Handle(http.MethodDelete, "/others", s.Others) + r.Handle(http.MethodHead, "/others", s.Others) + r.Handle(http.MethodPatch, "/others", s.Others) + r.Handle(http.MethodOptions, "/others", s.Others) + r.Handle(http.MethodConnect, "/others", s.Others) + r.Handle(http.MethodTrace, "/others", s.Others) + r.Handle(http.MethodGet, "/logs", s.Logs) + r.Handle(http.MethodPut, "/logs", s.Logs) + r.Handle(http.MethodPost, "/logs", s.Logs) + r.Handle(http.MethodDelete, "/logs", s.Logs) + r.Handle(http.MethodHead, "/logs", s.Logs) + r.Handle(http.MethodPatch, "/logs", s.Logs) + r.Handle(http.MethodOptions, "/logs", s.Logs) + r.Handle(http.MethodConnect, "/logs", s.Logs) + r.Handle(http.MethodTrace, "/logs", s.Logs) + r.Handle("GET", "/Status", s.Status) + r.Handle("POST", "/Status", s.Status) + r.Handle("HEAD", "/Status", s.Status) + + r.Handle("GET", "/admin", s.Admin) + r.Handle("GET", "/dashboard", s.Dashboard) + r.Handle("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -35,4 +74,49 @@ func (UnimplementedSiteServant) Articles(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Articles not implemented")) } +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/httprouter/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/httprouter/mirc/auto/api/v1/site.go.tmpl index 2b9e022..318a94e 100644 --- a/mirc/cmd/templates/httprouter/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/httprouter/mirc/auto/api/v1/site.go.tmpl @@ -12,7 +12,7 @@ type Site interface { Index(http.ResponseWriter, *http.Request, httprouter.Params) Articles(http.ResponseWriter, *http.Request, httprouter.Params) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to httprouter diff --git a/mirc/cmd/templates/httprouter/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/httprouter/mirc/auto/api/v2/site.go.tmpl index 2ad2f81..15ff10e 100644 --- a/mirc/cmd/templates/httprouter/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/httprouter/mirc/auto/api/v2/site.go.tmpl @@ -11,16 +11,53 @@ import ( type Site interface { Index(http.ResponseWriter, *http.Request, httprouter.Params) Articles(http.ResponseWriter, *http.Request, httprouter.Params) - Category(http.ResponseWriter, *http.Request, httprouter.Params) + Login(http.ResponseWriter, *http.Request, httprouter.Params) + Logout(http.ResponseWriter, *http.Request, httprouter.Params) + Assets(http.ResponseWriter, *http.Request, httprouter.Params) + Others(http.ResponseWriter, *http.Request, httprouter.Params) + Logs(http.ResponseWriter, *http.Request, httprouter.Params) + Status(http.ResponseWriter, *http.Request, httprouter.Params) + Admin(http.ResponseWriter, *http.Request, httprouter.Params) + Dashboard(http.ResponseWriter, *http.Request, httprouter.Params) + HomePage(http.ResponseWriter, *http.Request, httprouter.Params) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to httprouter func RegisterSiteServant(r *httprouter.Router, s Site) { r.Handle("GET", "/v2/index/", s.Index) r.Handle("GET", "/v2/articles/:category/", s.Articles) - r.Handle("GET", "/v2/category/", s.Category) + r.Handle("POST", "/v2/login", s.Login) + r.Handle("POST", "/v2/logout", s.Logout) + r.Handle("HEAD", "/v2/assets", s.Assets) + r.Handle("GET", "/v2/assets", s.Assets) + + r.Handle(http.MethodGet, "/v2/others", s.Others) + r.Handle(http.MethodPut, "/v2/others", s.Others) + r.Handle(http.MethodPost, "/v2/others", s.Others) + r.Handle(http.MethodDelete, "/v2/others", s.Others) + r.Handle(http.MethodHead, "/v2/others", s.Others) + r.Handle(http.MethodPatch, "/v2/others", s.Others) + r.Handle(http.MethodOptions, "/v2/others", s.Others) + r.Handle(http.MethodConnect, "/v2/others", s.Others) + r.Handle(http.MethodTrace, "/v2/others", s.Others) + r.Handle(http.MethodGet, "/v2/logs", s.Logs) + r.Handle(http.MethodPut, "/v2/logs", s.Logs) + r.Handle(http.MethodPost, "/v2/logs", s.Logs) + r.Handle(http.MethodDelete, "/v2/logs", s.Logs) + r.Handle(http.MethodHead, "/v2/logs", s.Logs) + r.Handle(http.MethodPatch, "/v2/logs", s.Logs) + r.Handle(http.MethodOptions, "/v2/logs", s.Logs) + r.Handle(http.MethodConnect, "/v2/logs", s.Logs) + r.Handle(http.MethodTrace, "/v2/logs", s.Logs) + r.Handle("GET", "/v2/Status", s.Status) + r.Handle("POST", "/v2/Status", s.Status) + r.Handle("HEAD", "/v2/Status", s.Status) + + r.Handle("GET", "/v2/admin", s.Admin) + r.Handle("GET", "/v2/dashboard", s.Dashboard) + r.Handle("GET", "/v2/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -37,9 +74,49 @@ func (UnimplementedSiteServant) Articles(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Articles not implemented")) } -func (UnimplementedSiteServant) Category(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request, params httprouter.Params) { rw.WriteHeader(http.StatusNotImplemented) - rw.Write([]byte("method Category not implemented")) + rw.Write([]byte("method HomePage not implemented")) } func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/httprouter/mirc/routes/site.go.tmpl b/mirc/cmd/templates/httprouter/mirc/routes/site.go.tmpl index bc53b37..dae19ff 100644 --- a/mirc/cmd/templates/httprouter/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/httprouter/mirc/routes/site.go.tmpl @@ -11,7 +11,16 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/httprouter/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/httprouter/mirc/routes/v2/site.go.tmpl index 2e29da1..02ba8f2 100644 --- a/mirc/cmd/templates/httprouter/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/httprouter/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,16 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` - Category Get `mir:"/category/"` + Group Group `mir:"v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/iris/go.mod.tmpl b/mirc/cmd/templates/iris/go.mod.tmpl index af346ab..3ff765d 100644 --- a/mirc/cmd/templates/iris/go.mod.tmpl +++ b/mirc/cmd/templates/iris/go.mod.tmpl @@ -4,7 +4,7 @@ go 1.16 require ( github.com/ajg/form v1.5.1 // indirect - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect github.com/google/go-querystring v1.0.0 // indirect github.com/imkira/go-interpol v1.1.0 // indirect diff --git a/mirc/cmd/templates/iris/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/iris/mirc/auto/api/site.go.tmpl index f1c8260..d87d094 100644 --- a/mirc/cmd/templates/iris/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/iris/mirc/auto/api/site.go.tmpl @@ -16,8 +16,17 @@ type Site interface { Index(context.Context) Articles(context.Context) + Login(context.Context) + Logout(context.Context) + Assets(context.Context) + Others(context.Context) + Logs(context.Context) + Status(context.Context) + Admin(context.Context) + Dashboard(context.Context) + HomePage(context.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to iris @@ -30,6 +39,20 @@ func RegisterSiteServant(app *iris.Application, s Site) { // register routes info to party p.Handle("GET", "/index/", s.Index) p.Handle("GET", "/articles/{category:string}", s.Articles) + p.Handle("POST", "/login", s.Login) + p.Handle("POST", "/logout", s.Logout) + p.Handle("HEAD", "/assets", s.Assets) + p.Handle("GET", "/assets", s.Assets) + + p.Any("/others", s.Others) + p.Any("/logs", s.Logs) + p.Handle("GET", "/Status", s.Status) + p.Handle("POST", "/Status", s.Status) + p.Handle("HEAD", "/Status", s.Status) + + p.Handle("GET", "/admin", s.Admin) + p.Handle("GET", "/dashboard", s.Dashboard) + p.Handle("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -50,4 +73,49 @@ func (UnimplementedSiteServant) Articles(c context.Context) { c.WriteString("method Articles not implemented") } +func (UnimplementedSiteServant) Login(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Login not implemented") +} + +func (UnimplementedSiteServant) Logout(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Logout not implemented") +} + +func (UnimplementedSiteServant) Assets(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Assets not implemented") +} + +func (UnimplementedSiteServant) Others(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Others not implemented") +} + +func (UnimplementedSiteServant) Logs(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Logs not implemented") +} + +func (UnimplementedSiteServant) Status(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Status not implemented") +} + +func (UnimplementedSiteServant) Admin(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Admin not implemented") +} + +func (UnimplementedSiteServant) Dashboard(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Dashboard not implemented") +} + +func (UnimplementedSiteServant) HomePage(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method HomePage not implemented") +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/iris/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/iris/mirc/auto/api/v1/site.go.tmpl index eff2b5c..c310925 100644 --- a/mirc/cmd/templates/iris/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/iris/mirc/auto/api/v1/site.go.tmpl @@ -17,7 +17,7 @@ type Site interface { Index(context.Context) Articles(context.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to iris diff --git a/mirc/cmd/templates/iris/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/iris/mirc/auto/api/v2/site.go.tmpl index 5be9336..a36920c 100644 --- a/mirc/cmd/templates/iris/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/iris/mirc/auto/api/v2/site.go.tmpl @@ -13,9 +13,17 @@ import ( type Site interface { Index(context.Context) Articles(context.Context) - Category(context.Context) + Login(context.Context) + Logout(context.Context) + Assets(context.Context) + Others(context.Context) + Logs(context.Context) + Status(context.Context) + Admin(context.Context) + Dashboard(context.Context) + HomePage(context.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to iris @@ -25,7 +33,20 @@ func RegisterSiteServant(app *iris.Application, s Site) { // register routes info to party p.Handle("GET", "/index/", s.Index) p.Handle("GET", "/articles/{category:string}", s.Articles) - p.Handle("GET", "/category/", s.Category) + p.Handle("POST", "/login", s.Login) + p.Handle("POST", "/logout", s.Logout) + p.Handle("HEAD", "/assets", s.Assets) + p.Handle("GET", "/assets", s.Assets) + + p.Any("/others", s.Others) + p.Any("/logs", s.Logs) + p.Handle("GET", "/Status", s.Status) + p.Handle("POST", "/Status", s.Status) + p.Handle("HEAD", "/Status", s.Status) + + p.Handle("GET", "/admin", s.Admin) + p.Handle("GET", "/dashboard", s.Dashboard) + p.Handle("GET", "/home", s.HomePage) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -42,9 +63,49 @@ func (UnimplementedSiteServant) Articles(c context.Context) { c.WriteString("method Articles not implemented") } -func (UnimplementedSiteServant) Category(c context.Context) { +func (UnimplementedSiteServant) Login(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Login not implemented") +} + +func (UnimplementedSiteServant) Logout(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Logout not implemented") +} + +func (UnimplementedSiteServant) Assets(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Assets not implemented") +} + +func (UnimplementedSiteServant) Others(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Others not implemented") +} + +func (UnimplementedSiteServant) Logs(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Logs not implemented") +} + +func (UnimplementedSiteServant) Status(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Status not implemented") +} + +func (UnimplementedSiteServant) Admin(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Admin not implemented") +} + +func (UnimplementedSiteServant) Dashboard(c context.Context) { + c.StatusCode(http.StatusNotImplemented) + c.WriteString("method Dashboard not implemented") +} + +func (UnimplementedSiteServant) HomePage(c context.Context) { c.StatusCode(http.StatusNotImplemented) - c.WriteString("method Category not implemented") + c.WriteString("method HomePage not implemented") } func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/iris/mirc/routes/site.go.tmpl b/mirc/cmd/templates/iris/mirc/routes/site.go.tmpl index 385c456..5ba9c52 100644 --- a/mirc/cmd/templates/iris/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/iris/mirc/routes/site.go.tmpl @@ -11,7 +11,16 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/{category:string}"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/{category:string}"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/iris/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/iris/mirc/routes/v2/site.go.tmpl index 860461f..f5dfeff 100644 --- a/mirc/cmd/templates/iris/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/iris/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,16 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/{category:string}"` - Category Get `mir:"/category/"` + Group Group `mir:"v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/{category:string}"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/macaron/go.mod.tmpl b/mirc/cmd/templates/macaron/go.mod.tmpl index 101040a..2425d9e 100644 --- a/mirc/cmd/templates/macaron/go.mod.tmpl +++ b/mirc/cmd/templates/macaron/go.mod.tmpl @@ -3,7 +3,7 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} gopkg.in/macaron.v1 {{ .VersionOfEngine "v1.4.0" }} ) {{if notEmptyStr .MirPkgName }} diff --git a/mirc/cmd/templates/macaron/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/macaron/mirc/auto/api/site.go.tmpl index d1d14cb..c63249c 100644 --- a/mirc/cmd/templates/macaron/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/macaron/mirc/auto/api/site.go.tmpl @@ -14,8 +14,17 @@ type Site interface { Index(*macaron.Context) Articles(*macaron.Context) + Login(*macaron.Context) + Logout(*macaron.Context) + Assets(*macaron.Context) + Others(*macaron.Context) + Logs(*macaron.Context) + Status(*macaron.Context) + Admin(*macaron.Context) + Dashboard(*macaron.Context) + HomePage(*macaron.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to macaron @@ -27,6 +36,20 @@ func RegisterSiteServant(m *macaron.Macaron, s Site) { } m.Handle("GET", "/index/", []macaron.Handler{s.Index}) m.Handle("GET", "/articles/:category/", []macaron.Handler{s.Articles}) + m.Handle("POST", "/login", []macaron.Handler{s.Login}) + m.Handle("POST", "/logout", []macaron.Handler{s.Logout}) + m.Handle("HEAD", "/assets", []macaron.Handler{s.Assets}) + m.Handle("GET", "/assets", []macaron.Handler{s.Assets}) + + m.Any("/others", s.Others) + m.Any("/logs", s.Logs) + m.Handle("GET", "/Status", []macaron.Handler{s.Status}) + m.Handle("POST", "/Status", []macaron.Handler{s.Status}) + m.Handle("HEAD", "/Status", []macaron.Handler{s.Status}) + + m.Handle("GET", "/admin", []macaron.Handler{s.Admin}) + m.Handle("GET", "/dashboard", []macaron.Handler{s.Dashboard}) + m.Handle("GET", "/home", []macaron.Handler{s.HomePage}) } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -47,4 +70,49 @@ func (UnimplementedSiteServant) Articles(c *macaron.Context) { c.Resp.Write([]byte("method Articles not implemented")) } +func (UnimplementedSiteServant) Login(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/macaron/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/macaron/mirc/auto/api/v1/site.go.tmpl index 8c55e19..480b8dc 100644 --- a/mirc/cmd/templates/macaron/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/macaron/mirc/auto/api/v1/site.go.tmpl @@ -15,7 +15,7 @@ type Site interface { Index(*macaron.Context) Articles(*macaron.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to macaron diff --git a/mirc/cmd/templates/macaron/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/macaron/mirc/auto/api/v2/site.go.tmpl index e59f962..8dc45d2 100644 --- a/mirc/cmd/templates/macaron/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/macaron/mirc/auto/api/v2/site.go.tmpl @@ -11,9 +11,17 @@ import ( type Site interface { Index(*macaron.Context) Articles(*macaron.Context) - Category(*macaron.Context) + Login(*macaron.Context) + Logout(*macaron.Context) + Assets(*macaron.Context) + Others(*macaron.Context) + Logs(*macaron.Context) + Status(*macaron.Context) + Admin(*macaron.Context) + Dashboard(*macaron.Context) + HomePage(*macaron.Context) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to macaron @@ -21,7 +29,20 @@ func RegisterSiteServant(m *macaron.Macaron, s Site) { m.Group("v2", func() { m.Handle("GET", "/index/", []macaron.Handler{s.Index}) m.Handle("GET", "/articles/:category/", []macaron.Handler{s.Articles}) - m.Handle("GET", "/category/", []macaron.Handler{s.Category}) + m.Handle("POST", "/login", []macaron.Handler{s.Login}) + m.Handle("POST", "/logout", []macaron.Handler{s.Logout}) + m.Handle("HEAD", "/assets", []macaron.Handler{s.Assets}) + m.Handle("GET", "/assets", []macaron.Handler{s.Assets}) + + m.Any("/others", s.Others) + m.Any("/logs", s.Logs) + m.Handle("GET", "/Status", []macaron.Handler{s.Status}) + m.Handle("POST", "/Status", []macaron.Handler{s.Status}) + m.Handle("HEAD", "/Status", []macaron.Handler{s.Status}) + + m.Handle("GET", "/admin", []macaron.Handler{s.Admin}) + m.Handle("GET", "/dashboard", []macaron.Handler{s.Dashboard}) + m.Handle("GET", "/home", []macaron.Handler{s.HomePage}) }) } @@ -39,9 +60,49 @@ func (UnimplementedSiteServant) Articles(c *macaron.Context) { c.Resp.Write([]byte("method Articles not implemented")) } -func (UnimplementedSiteServant) Category(c *macaron.Context) { +func (UnimplementedSiteServant) Login(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(c *macaron.Context) { + c.Resp.WriteHeader(http.StatusNotImplemented) + c.Resp.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(c *macaron.Context) { c.Resp.WriteHeader(http.StatusNotImplemented) - c.Resp.Write([]byte("method Category not implemented")) + c.Resp.Write([]byte("method HomePage not implemented")) } func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/macaron/mirc/routes/site.go.tmpl b/mirc/cmd/templates/macaron/mirc/routes/site.go.tmpl index bc53b37..dae19ff 100644 --- a/mirc/cmd/templates/macaron/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/macaron/mirc/routes/site.go.tmpl @@ -11,7 +11,16 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/macaron/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/macaron/mirc/routes/v2/site.go.tmpl index 2e29da1..02ba8f2 100644 --- a/mirc/cmd/templates/macaron/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/macaron/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,16 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"/articles/:category/"` - Category Get `mir:"/category/"` + Group Group `mir:"v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"/articles/:category/"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/mux/go.mod.tmpl b/mirc/cmd/templates/mux/go.mod.tmpl index 216957f..0f51cbb 100644 --- a/mirc/cmd/templates/mux/go.mod.tmpl +++ b/mirc/cmd/templates/mux/go.mod.tmpl @@ -3,7 +3,7 @@ module {{ .PkgName }} go 1.16 require ( - github.com/alimy/mir/v2 {{ .VersionOfMir "v2.7.2" }} + github.com/alimy/mir/v2 {{ .VersionOfMir "v2.8.0" }} github.com/gorilla/mux {{ .VersionOfEngine "v1.8.0" }} ) {{if notEmptyStr .MirPkgName }} diff --git a/mirc/cmd/templates/mux/mirc/auto/api/site.go.tmpl b/mirc/cmd/templates/mux/mirc/auto/api/site.go.tmpl index e3e35be..8bdf503 100644 --- a/mirc/cmd/templates/mux/mirc/auto/api/site.go.tmpl +++ b/mirc/cmd/templates/mux/mirc/auto/api/site.go.tmpl @@ -5,22 +5,26 @@ package api import ( "net/http" - "github.com/alimy/mir/v2" - mux "github.com/gorilla/mux" ) -// just use for mir.Any method to register -var httpMethods = mir.HttpMethods - type Site interface { // Chain provide middlewares for mux Chain() []mux.MiddlewareFunc Index(http.ResponseWriter, *http.Request) Articles(http.ResponseWriter, *http.Request) - - mustEmbedUnimplementedSiteServant() + Login(http.ResponseWriter, *http.Request) + Logout(http.ResponseWriter, *http.Request) + Assets(http.ResponseWriter, *http.Request) + Others(http.ResponseWriter, *http.Request) + Logs(http.ResponseWriter, *http.Request) + Status(http.ResponseWriter, *http.Request) + Admin(http.ResponseWriter, *http.Request) + Dashboard(http.ResponseWriter, *http.Request) + HomePage(http.ResponseWriter, *http.Request) + + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to mux @@ -38,6 +42,24 @@ func RegisterSiteServant(r *mux.Router, s Site) { Methods("GET"). Host("{subdomain}.example.com"). Queries("filter", "{filter}", "foo", "bar", "id", "{id:[0-9]+}") + router.HandleFunc("/login", s.Login). + Methods("POST") + router.HandleFunc("/logout", s.Logout). + Methods("POST") + router.HandleFunc("/assets", s.Assets). + Methods("HEAD", "GET") + router.HandleFunc("/others", s.Others). + Methods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "CONNECT", "OPTIONS", "TRACE") + router.HandleFunc("/logs", s.Logs). + Methods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "CONNECT", "OPTIONS", "TRACE") + router.HandleFunc("/Status", s.Status). + Methods("GET", "POST", "HEAD") + router.HandleFunc("/admin", s.Admin). + Methods("GET") + router.HandleFunc("/dashboard", s.Dashboard). + Methods("GET") + router.HandleFunc("/home", s.HomePage). + Methods("GET") } // UnimplementedSiteServant can be embedded to have forward compatible implementations. @@ -58,4 +80,49 @@ func (UnimplementedSiteServant) Articles(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Articles not implemented")) } +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method HomePage not implemented")) +} + func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/mux/mirc/auto/api/v1/site.go.tmpl b/mirc/cmd/templates/mux/mirc/auto/api/v1/site.go.tmpl index 703a99f..92b7cbf 100644 --- a/mirc/cmd/templates/mux/mirc/auto/api/v1/site.go.tmpl +++ b/mirc/cmd/templates/mux/mirc/auto/api/v1/site.go.tmpl @@ -5,14 +5,9 @@ package v1 import ( "net/http" - "github.com/alimy/mir/v2" - mux "github.com/gorilla/mux" ) -// just use for mir.Any method to register -var httpMethods = mir.HttpMethods - type Site interface { // Chain provide middlewares for mux Chain() []mux.MiddlewareFunc @@ -20,7 +15,7 @@ type Site interface { Index(http.ResponseWriter, *http.Request) Articles(http.ResponseWriter, *http.Request) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to mux diff --git a/mirc/cmd/templates/mux/mirc/auto/api/v2/site.go.tmpl b/mirc/cmd/templates/mux/mirc/auto/api/v2/site.go.tmpl index 851fe19..9f5edf9 100644 --- a/mirc/cmd/templates/mux/mirc/auto/api/v2/site.go.tmpl +++ b/mirc/cmd/templates/mux/mirc/auto/api/v2/site.go.tmpl @@ -5,20 +5,23 @@ package v2 import ( "net/http" - "github.com/alimy/mir/v2" - mux "github.com/gorilla/mux" ) -// just use for mir.Any method to register -var httpMethods = mir.HttpMethods - type Site interface { Index(http.ResponseWriter, *http.Request) Articles(http.ResponseWriter, *http.Request) - Category(http.ResponseWriter, *http.Request) + Login(http.ResponseWriter, *http.Request) + Logout(http.ResponseWriter, *http.Request) + Assets(http.ResponseWriter, *http.Request) + Others(http.ResponseWriter, *http.Request) + Logs(http.ResponseWriter, *http.Request) + Status(http.ResponseWriter, *http.Request) + Admin(http.ResponseWriter, *http.Request) + Dashboard(http.ResponseWriter, *http.Request) + HomePage(http.ResponseWriter, *http.Request) - mustEmbedUnimplementedSiteServant() + mustEmbedUnimplementedSiteServant() } // RegisterSiteServant register Site servant to mux @@ -32,7 +35,23 @@ func RegisterSiteServant(r *mux.Router, s Site) { Methods("GET"). Host("{subdomain}.example.com"). Queries("filter", "{filter}", "foo", "bar", "id", "{id:[0-9]+}") - router.HandleFunc("/category/", s.Category). + router.HandleFunc("/login", s.Login). + Methods("POST") + router.HandleFunc("/logout", s.Logout). + Methods("POST") + router.HandleFunc("/assets", s.Assets). + Methods("HEAD", "GET") + router.HandleFunc("/others", s.Others). + Methods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "CONNECT", "OPTIONS", "TRACE") + router.HandleFunc("/logs", s.Logs). + Methods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "CONNECT", "OPTIONS", "TRACE") + router.HandleFunc("/Status", s.Status). + Methods("GET", "POST", "HEAD") + router.HandleFunc("/admin", s.Admin). + Methods("GET") + router.HandleFunc("/dashboard", s.Dashboard). + Methods("GET") + router.HandleFunc("/home", s.HomePage). Methods("GET") } @@ -50,9 +69,49 @@ func (UnimplementedSiteServant) Articles(rw http.ResponseWriter, r *http.Request rw.Write([]byte("method Articles not implemented")) } -func (UnimplementedSiteServant) Category(rw http.ResponseWriter, r *http.Request) { +func (UnimplementedSiteServant) Login(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Login not implemented")) +} + +func (UnimplementedSiteServant) Logout(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logout not implemented")) +} + +func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Assets not implemented")) +} + +func (UnimplementedSiteServant) Others(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Others not implemented")) +} + +func (UnimplementedSiteServant) Logs(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Logs not implemented")) +} + +func (UnimplementedSiteServant) Status(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Status not implemented")) +} + +func (UnimplementedSiteServant) Admin(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Admin not implemented")) +} + +func (UnimplementedSiteServant) Dashboard(rw http.ResponseWriter, r *http.Request) { + rw.WriteHeader(http.StatusNotImplemented) + rw.Write([]byte("method Dashboard not implemented")) +} + +func (UnimplementedSiteServant) HomePage(rw http.ResponseWriter, r *http.Request) { rw.WriteHeader(http.StatusNotImplemented) - rw.Write([]byte("method Category not implemented")) + rw.Write([]byte("method HomePage not implemented")) } func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {} diff --git a/mirc/cmd/templates/mux/mirc/routes/site.go.tmpl b/mirc/cmd/templates/mux/mirc/routes/site.go.tmpl index d428084..9c7cc93 100644 --- a/mirc/cmd/templates/mux/mirc/routes/site.go.tmpl +++ b/mirc/cmd/templates/mux/mirc/routes/site.go.tmpl @@ -11,7 +11,16 @@ func init() { // Site site interface info type Site struct { - Chain Chain `mir:"-"` - Index Get `mir:"/index/"` - Articles Get `mir:"//{subdomain}.example.com/articles/{category}/{id:[0-9]+}?filter={filter}&foo=bar&id={id:[0-9]+}"` + Chain Chain `mir:"-"` + Index Get `mir:"/index/"` + Articles Get `mir:"//{subdomain}.example.com/articles/{category}/{id:[0-9]+}?filter={filter}&foo=bar&id={id:[0-9]+}"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/cmd/templates/mux/mirc/routes/v2/site.go.tmpl b/mirc/cmd/templates/mux/mirc/routes/v2/site.go.tmpl index 492758c..89d5d6e 100644 --- a/mirc/cmd/templates/mux/mirc/routes/v2/site.go.tmpl +++ b/mirc/cmd/templates/mux/mirc/routes/v2/site.go.tmpl @@ -11,8 +11,16 @@ func init() { // Site site v2 interface info type Site struct { - Group Group `mir:"v2"` - Index Get `mir:"/index/"` - Articles Get `mir:"//{subdomain}.example.com/articles/{category}/{id:[0-9]+}?filter={filter}&foo=bar&id={id:[0-9]+}"` - Category Get `mir:"/category/"` + Group Group `mir:"v2"` + Index Get `mir:"/index/"` + Articles Get `mir:"//{subdomain}.example.com/articles/{category}/{id:[0-9]+}?filter={filter}&foo=bar&id={id:[0-9]+}"` + Login Post `mir:"/login"` + Logout Post `mir:"/logout"` + Assets Any `mir:"/assets" method:"Head,Get"` + Others Any `mir:"/others"` + Logs Any `mir:"/logs"` + Status Any `mir:"/Status" method:"Get,Post,Head"` + Admin Get `mir:"/admin""` + Dashboard Get `mir:"/dashboard"` + HomePage Get `mir:"/home"` } diff --git a/mirc/version/version.go b/mirc/version/version.go index ce9bae4..091ab55 100644 --- a/mirc/version/version.go +++ b/mirc/version/version.go @@ -18,7 +18,7 @@ var ( BuildTime = "" // AppVer version of Mirc - AppVer = semver.MustParse("v2.7.3") + AppVer = semver.MustParse("v2.8.0") ) func ShowInfo() string {