Skip to content

Commit

Permalink
mirc: adape for mir v4.1.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alimy committed Dec 26, 2023
1 parent 02c54dd commit 4c83784
Show file tree
Hide file tree
Showing 94 changed files with 3,426 additions and 934 deletions.
4 changes: 2 additions & 2 deletions mirc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/alimy/mir/mirc/v4
go 1.16

require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/Masterminds/semver/v3 v3.2.1
github.com/alimy/embedx v0.6.1
github.com/spf13/cobra v1.1.1
github.com/spf13/cobra v1.8.0
)
294 changes: 9 additions & 285 deletions mirc/go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions mirc/templates/chi/go.mod.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module {{ .PkgName }}
go 1.19

require (
github.com/alimy/mir/v4 v4.0.0
github.com/go-chi/chi/v5 v5.0.10
github.com/alimy/mir/v4 v4.1.0-beta.1
github.com/go-chi/chi/v5 v5.0.11
)

{{if notEmptyStr .MirPkgName }}
Expand Down
8 changes: 4 additions & 4 deletions mirc/templates/chi/go.sum.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/alimy/mir/v4 v4.0.0 h1:MzGfmoLjjvR69jbZEmpKJO3tUuqB0RGRv1UWPbtukBg=
github.com/alimy/mir/v4 v4.0.0/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc=
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/alimy/mir/v4 v4.1.0-beta.1 h1:TdXNCmCSqjX8jj4KW4tTCMV2Ij1PpMoguJw5pinw/zk=
github.com/alimy/mir/v4 v4.1.0-beta.1/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc=
github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA=
github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
122 changes: 114 additions & 8 deletions mirc/templates/chi/mirc/auto/api/site.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by go-mir. DO NOT EDIT.
// versions:
// - mir v4.0.0
// - mir v4.1.0

package api

Expand All @@ -24,22 +24,17 @@ type _default_ interface {
Render(http.ResponseWriter, any, mir.Error)
}

type LogoutReq struct {
type LoginReq struct {
AgentInfo AgentInfo `json:"agent_info"`
Name string `json:"name"`
Passwd string `json:"passwd"`
}

type AgentInfo struct {
Platform string `json:"platform"`
UserAgent string `json:"user_agent"`
}

type LoginReq struct {
AgentInfo AgentInfo `json:"agent_info"`
Name string `json:"name"`
Passwd string `json:"passwd"`
}

type LoginResp struct {
UserInfo
ServerInfo ServerInfo `json:"server_info"`
Expand All @@ -54,6 +49,11 @@ type UserInfo struct {
Name string `json:"name"`
}

type LogoutReq struct {
AgentInfo AgentInfo `json:"agent_info"`
Name string `json:"name"`
}

type TweetsReq struct {
Date string `json:"date"`
}
Expand All @@ -74,6 +74,14 @@ type Site interface {
// Chain provide middlewares for chi
Chain() chi.Middlewares

MultiAttachments(http.ResponseWriter, *http.Request)
ManyResources(http.ResponseWriter, *http.Request)
AnyStaticks(http.ResponseWriter, *http.Request)
Statics(http.ResponseWriter, *http.Request)
Assets(http.ResponseWriter, *http.Request, *LoginReq) mir.Error
SimpleUpload(http.ResponseWriter, *http.Request, *LoginReq) (*LoginResp, mir.Error)
FileUpload(http.ResponseWriter, *http.Request)
ImageUpload(http.ResponseWriter, *http.Request)
Logout(*LogoutReq) mir.Error
Login(*LoginReq) (*LoginResp, mir.Error)
PrevTweets(*TweetsReq) (*TweetsResp, mir.Error)
Expand All @@ -86,6 +94,9 @@ type Site interface {
}

type SiteChain interface {
ChainMultiAttachments() chi.Middlewares
ChainSimpleUpload() chi.Middlewares
ChainFileUpload() chi.Middlewares
ChainIndex() chi.Middlewares

mustEmbedUnimplementedSiteChain()
Expand All @@ -106,6 +117,51 @@ func RegisterSiteServant(e chi.Router, s Site, m ...SiteChain) {
router.Use(middlewares...)

// register routes info to router
{
h := s.MultiAttachments
router := router.With(cc.ChainMultiAttachments()...)
router.MethodFunc("OPTIONS", "/attachments/:name/", h)
router.MethodFunc("HEAD", "/attachments/:name/", h)
router.MethodFunc("GET", "/attachments/:name/", h)
}
{
h := s.ManyResources

router.MethodFunc("GET", "/resources/:name/", h)
router.MethodFunc("OPTIONS", "/resources/:name/", h)
router.MethodFunc("HEAD", "/resources/:name/", h)
}
router.HandleFunc("/anystaticks/:name/", s.AnyStaticks)
router.MethodFunc("GET", "/statics/:name/", s.Statics)
router.MethodFunc("GET", "/assets/:name/", func(rw http.ResponseWriter, hr *http.Request) {
select {
case <-hr.Context().Done():
return
default:
}
req := new(LoginReq)
if err := s.Bind(hr, req); err != nil {
s.Render(rw, nil, err)
return
}
s.Render(rw, nil, s.Assets(rw, hr, req))
})
router.With(cc.ChainSimpleUpload()...).MethodFunc("POST", "/upload/simple/:name/", func(rw http.ResponseWriter, hr *http.Request) {
select {
case <-hr.Context().Done():
return
default:
}
req := new(LoginReq)
if err := s.Bind(hr, req); err != nil {
s.Render(rw, nil, err)
return
}
resp, err := s.SimpleUpload(rw, hr, req)
s.Render(rw, resp, err)
})
router.With(cc.ChainFileUpload()...).MethodFunc("POST", "/upload/file/:name/", s.FileUpload)
router.MethodFunc("POST", "/upload/image/:name/", s.ImageUpload)
router.MethodFunc("POST", "/user/logout/", func(rw http.ResponseWriter, hr *http.Request) {
select {
case <-hr.Context().Done():
Expand Down Expand Up @@ -203,6 +259,44 @@ func (UnimplementedSiteServant) Chain() chi.Middlewares {
return nil
}

func (UnimplementedSiteServant) MultiAttachments(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) ManyResources(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) AnyStaticks(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) Statics(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) Assets(rw http.ResponseWriter, hr *http.Request, req *LoginReq) mir.Error {
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}

func (UnimplementedSiteServant) SimpleUpload(rw http.ResponseWriter, hr *http.Request, req *LoginReq) (*LoginResp, mir.Error) {
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}

func (UnimplementedSiteServant) FileUpload(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) ImageUpload(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) Logout(req *LogoutReq) mir.Error {
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}
Expand Down Expand Up @@ -236,6 +330,18 @@ func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {}
// UnimplementedSiteChain can be embedded to have forward compatible implementations.
type UnimplementedSiteChain struct{}

func (b *UnimplementedSiteChain) ChainMultiAttachments() chi.Middlewares {
return nil
}

func (b *UnimplementedSiteChain) ChainSimpleUpload() chi.Middlewares {
return nil
}

func (b *UnimplementedSiteChain) ChainFileUpload() chi.Middlewares {
return nil
}

func (b *UnimplementedSiteChain) ChainIndex() chi.Middlewares {
return nil
}
Expand Down
68 changes: 66 additions & 2 deletions mirc/templates/chi/mirc/auto/api/v1/site.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by go-mir. DO NOT EDIT.
// versions:
// - mir v4.0.0
// - mir v4.1.0

package v1

Expand Down Expand Up @@ -30,6 +30,12 @@ type Site interface {
// Chain provide middlewares for chi
Chain() chi.Middlewares

MultiAttachments(http.ResponseWriter, *http.Request)
ManyResources(http.ResponseWriter, *http.Request)
AnyStaticks(http.ResponseWriter, *http.Request)
Statics(http.ResponseWriter, *http.Request)
FileUpload(http.ResponseWriter, *http.Request)
ImageUpload(http.ResponseWriter, *http.Request)
Logout() mir.Error
Articles() mir.Error
AnyTopics() mir.Error
Expand All @@ -39,6 +45,8 @@ type Site interface {
}

type SiteChain interface {
ChainMultiAttachments() chi.Middlewares
ChainFileUpload() chi.Middlewares
ChainArticles() chi.Middlewares
ChainAnyTopics() chi.Middlewares
ChainIndex() chi.Middlewares
Expand All @@ -62,6 +70,24 @@ func RegisterSiteServant(e chi.Router, s Site, m ...SiteChain) {
router.Use(middlewares...)

// register routes info to router
{
h := s.MultiAttachments
router := router.With(cc.ChainMultiAttachments()...)
router.MethodFunc("OPTIONS", "/attachments/:name/", h)
router.MethodFunc("HEAD", "/attachments/:name/", h)
router.MethodFunc("GET", "/attachments/:name/", h)
}
{
h := s.ManyResources

router.MethodFunc("OPTIONS", "/resources/:name/", h)
router.MethodFunc("HEAD", "/resources/:name/", h)
router.MethodFunc("GET", "/resources/:name/", h)
}
router.HandleFunc("/anystaticks/:name/", s.AnyStaticks)
router.MethodFunc("GET", "/statics/:name/", s.Statics)
router.With(cc.ChainFileUpload()...).MethodFunc("POST", "/upload/file/:name/", s.FileUpload)
router.MethodFunc("POST", "/upload/image/:name/", s.ImageUpload)
router.MethodFunc("POST", "/user/logout/", func(rw http.ResponseWriter, hr *http.Request) {
select {
case <-hr.Context().Done():
Expand All @@ -82,9 +108,9 @@ func RegisterSiteServant(e chi.Router, s Site, m ...SiteChain) {
s.Render(rw, nil, s.Articles())
}
router := router.With(cc.ChainArticles()...)
router.MethodFunc("POST", "/articles/:category/", h)
router.MethodFunc("GET", "/articles/:category/", h)
router.MethodFunc("HEAD", "/articles/:category/", h)
router.MethodFunc("POST", "/articles/:category/", h)
}
router.With(cc.ChainAnyTopics()...).HandleFunc("/topics/", func(rw http.ResponseWriter, hr *http.Request) {
select {
Expand Down Expand Up @@ -113,6 +139,36 @@ func (UnimplementedSiteServant) Chain() chi.Middlewares {
return nil
}

func (UnimplementedSiteServant) MultiAttachments(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) ManyResources(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) AnyStaticks(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) Statics(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) FileUpload(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) ImageUpload(rw http.ResponseWriter, hr *http.Request) {
rw.WriteHeader(http.StatusNotImplemented)
rw.Write([]byte("method not implemented"))
}

func (UnimplementedSiteServant) Logout() mir.Error {
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}
Expand All @@ -134,6 +190,14 @@ func (UnimplementedSiteServant) mustEmbedUnimplementedSiteServant() {}
// UnimplementedSiteChain can be embedded to have forward compatible implementations.
type UnimplementedSiteChain struct{}

func (b *UnimplementedSiteChain) ChainMultiAttachments() chi.Middlewares {
return nil
}

func (b *UnimplementedSiteChain) ChainFileUpload() chi.Middlewares {
return nil
}

func (b *UnimplementedSiteChain) ChainArticles() chi.Middlewares {
return nil
}
Expand Down
Loading

0 comments on commit 4c83784

Please sign in to comment.