Skip to content

Commit

Permalink
optimize primitive logic for generator
Browse files Browse the repository at this point in the history
  • Loading branch information
alimy committed Dec 14, 2023
1 parent f54b37e commit 14eeeb8
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 84 deletions.
5 changes: 5 additions & 0 deletions core/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ func (f *FieldDescriptor) HttpMethodArgs() string {
return utils.QuoteJoin(f.HttpMethods, ",")
}

// JustUseContext whether just use context
func (f *FieldDescriptor) JustUseContext() bool {
return f.IsUseContext && len(f.InOuts) == 0
}

// OrInOut in or out
func (f *FieldDescriptor) OrInOut() bool {
return f.In != nil || f.Out != nil
Expand Down
63 changes: 47 additions & 16 deletions examples/mirc/auto/api/site.go

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

16 changes: 8 additions & 8 deletions examples/mirc/auto/api/v1/site.go

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

61 changes: 43 additions & 18 deletions examples/mirc/auto/api/v2/site.go

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

35 changes: 27 additions & 8 deletions examples/mirc/auto/api/v3/site.go

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

15 changes: 8 additions & 7 deletions examples/mirc/routes/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ type Site struct {
PrevTweets func(Post, Get, Head, TweetsReq) TweetsResp `mir:"/tweets/prev/"`
Login func(Post, LoginReq) LoginResp `mir:"/user/login/"`
Logout func(Post, LogoutReq) `mir:"/user/logout/"`
ImageUpload func(Post, Context) `mir:"/upload/image"`
FileUpload func(Post, Chain, Context) `mir:"/upload/file"`
SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple"`
Assets func(Get, Context) `mir:"/assets"`
AnyStaticks func(Any, Context) `mir:"/staticks"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"`
ImageUpload func(Post, Context) `mir:"/upload/image/:name/"`
FileUpload func(Post, Chain, Context) `mir:"/upload/file/:name/"`
SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple/:name/"`
Assets func(Get, Context, LoginReq) `mir:"/assets/:name/"`
Statics func(Get, Context) `mir:"/statics/:name/"`
AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"`
}
8 changes: 4 additions & 4 deletions examples/mirc/routes/v1/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ type Site struct {
AnyTopics func(Chain) `mir:"/topics/"`
Articles func(Head, Get, Post, Chain) `mir:"/articles/:category/"`
Logout func(Post) `mir:"/user/logout/"`
Assets func(Get, Context) `mir:"/assets"`
AnyStaticks func(Any, Context) `mir:"/staticks"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"`
Assets func(Get, Context) `mir:"/assets/:name/"`
AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"`
}

// Admin admin v1 interface info
Expand Down
14 changes: 7 additions & 7 deletions examples/mirc/routes/v2/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ type Site struct {
PrevTweets func(Post, Get, Head, TweetsReq) TweetsResp `mir:"/tweets/prev/"`
Login func(Post, LoginReq) LoginResp `mir:"/user/login/"`
Logout func(Post) `mir:"/user/logout/"`
ImageUpload func(Post, Context) `mir:"/upload/image"`
FileUpload func(Post, Chain, Context) `mir:"/upload/file"`
SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple"`
Assets func(Get, Context) `mir:"/assets"`
AnyStaticks func(Any, Context) `mir:"/staticks"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"`
ImageUpload func(Post, Context) `mir:"/upload/image/:name/"`
FileUpload func(Post, Chain, Context) `mir:"/upload/file/:name/"`
SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple/:name/"`
Assets func(Get, Context, LoginReq) `mir:"/assets/:name/"`
AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"`
}
9 changes: 5 additions & 4 deletions examples/mirc/routes/v3/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ type Site struct {
PrevTweets func(Post, Get, Head, model.TweetsReq) model.TweetsResp `mir:"/tweets/prev/"`
Login func(Post, model.LoginReq) model.LoginResp `mir:"/user/login/"`
Logout func(Post) `mir:"/user/logout/"`
Assets func(Get, Context) `mir:"/assets"`
AnyStaticks func(Any, Context) `mir:"/staticks"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"`
Assets func(Get, Context) `mir:"/assets/:name/"`
Statics func(Get, Context, model.LoginReq) `mir:"/statics/:name/"`
AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"`
ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"`
MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"`
}
Loading

0 comments on commit 14eeeb8

Please sign in to comment.