-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the existing Ctx API into two separate APIs for Requests and Responses. There are two goals to this change: 1. Reduce cognitive load by making it more obvious whether a Ctx method interacts with the request or the response. 2. Increase API parity with Express.
- Loading branch information
1 parent
ec48579
commit 85f5e09
Showing
7 changed files
with
295 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package fiber | ||
|
||
//go:generate ifacemaker --file req.go --struct DefaultReq --iface Req --pkg fiber --output req_interface_gen.go --not-exported true --iface-comment "Req" | ||
type DefaultReq struct { | ||
ctx *DefaultCtx | ||
} | ||
|
||
func (r *DefaultReq) Accepts(offers ...string) string { | ||
return r.ctx.Accepts(offers...) | ||
} | ||
|
||
func (r *DefaultReq) AcceptsCharsets(offers ...string) string { | ||
return r.ctx.AcceptsCharsets(offers...) | ||
} | ||
|
||
func (r *DefaultReq) AcceptsEncodings(offers ...string) string { | ||
return r.ctx.AcceptsEncodings(offers...) | ||
} | ||
|
||
func (r *DefaultReq) AcceptsLanguages(offers ...string) string { | ||
return r.ctx.AcceptsLanguages(offers...) | ||
} | ||
|
||
func (r *DefaultReq) BaseURL() string { | ||
return r.ctx.BaseURL() | ||
} | ||
|
||
func (r *DefaultReq) Body() []byte { | ||
return r.ctx.Body() | ||
} | ||
|
||
func (r *DefaultReq) Cookies(key string, defaultValue ...string) string { | ||
return r.ctx.Cookies(key, defaultValue...) | ||
} | ||
|
||
func (r *DefaultReq) Fresh() bool { | ||
return r.ctx.Fresh() | ||
} | ||
|
||
func (r *DefaultReq) Get(key string, defaultValue ...string) string { | ||
return r.ctx.Get(key, defaultValue...) | ||
} | ||
|
||
func (r *DefaultReq) Host() string { | ||
return r.ctx.Host() | ||
} | ||
|
||
func (r *DefaultReq) Hostname() string { | ||
return r.ctx.Hostname() | ||
} | ||
|
||
func (r *DefaultReq) IP() string { | ||
return r.ctx.IP() | ||
} | ||
|
||
func (r *DefaultReq) Is(extension string) bool { | ||
return r.ctx.Is(extension) | ||
} | ||
|
||
func (r *DefaultReq) IPs() []string { | ||
return r.ctx.IPs() | ||
} | ||
|
||
func (r *DefaultReq) Method() string { | ||
return r.ctx.Method() | ||
} | ||
|
||
func (r *DefaultReq) OriginalURL() string { | ||
return r.ctx.OriginalURL() | ||
} | ||
|
||
func (r *DefaultReq) Params(key string, defaultValue ...string) string { | ||
return r.ctx.Params(key, defaultValue...) | ||
} | ||
|
||
func (r *DefaultReq) Path() string { | ||
return r.ctx.Path() | ||
} | ||
|
||
func (r *DefaultReq) Protocol() string { | ||
return r.ctx.Protocol() | ||
} | ||
|
||
func (r *DefaultReq) Query(key string, defaultValue ...string) string { | ||
return r.ctx.Query(key, defaultValue...) | ||
} | ||
|
||
func (r *DefaultReq) Range(size int) (Range, error) { | ||
return r.ctx.Range(size) | ||
} | ||
|
||
func (r *DefaultReq) Route() *Route { | ||
return r.ctx.Route() | ||
} | ||
|
||
func (r *DefaultReq) Secure() bool { | ||
return r.ctx.Secure() | ||
} | ||
|
||
func (r *DefaultReq) Stale() bool { | ||
return r.ctx.Stale() | ||
} | ||
|
||
func (r *DefaultReq) Subdomains(offset ...int) []string { | ||
return r.ctx.Subdomains(offset...) | ||
} | ||
|
||
func (r *DefaultReq) XHR() bool { | ||
return r.ctx.XHR() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package fiber | ||
|
||
//go:generate ifacemaker --file res.go --struct DefaultRes --iface Res --pkg fiber --output res_interface_gen.go --not-exported true --iface-comment "Res" | ||
type DefaultRes struct { | ||
ctx *DefaultCtx | ||
} | ||
|
||
func (r *DefaultRes) Locals(key any, value ...any) any { | ||
return r.ctx.Locals(key, value...) | ||
} | ||
|
||
func (r *DefaultRes) Append(field string, values ...string) { | ||
r.ctx.Append(field, values...) | ||
} | ||
|
||
func (r *DefaultRes) Attachment(filename ...string) { | ||
r.ctx.Attachment(filename...) | ||
} | ||
|
||
func (r *DefaultRes) AutoFormat(body any) error { | ||
return r.ctx.AutoFormat(body) | ||
} | ||
|
||
func (r *DefaultRes) CBOR(body any, ctype ...string) error { | ||
return r.ctx.CBOR(body, ctype...) | ||
} | ||
|
||
func (r *DefaultRes) Cookie(cookie *Cookie) { | ||
r.ctx.Cookie(cookie) | ||
} | ||
|
||
func (r *DefaultRes) ClearCookie(key ...string) { | ||
r.ctx.ClearCookie(key...) | ||
} | ||
|
||
func (r *DefaultRes) Download(file string, filename ...string) error { | ||
return r.ctx.Download(file, filename...) | ||
} | ||
|
||
func (r *DefaultRes) Format(handlers ...ResFmt) error { | ||
return r.ctx.Format(handlers...) | ||
} | ||
|
||
func (r *DefaultRes) Get(key string, defaultValue ...string) string { | ||
return r.ctx.GetRespHeader(key, defaultValue...) | ||
} | ||
|
||
func (r *DefaultRes) JSON(body any, ctype ...string) error { | ||
return r.ctx.JSON(body, ctype...) | ||
} | ||
|
||
func (r *DefaultRes) JSONP(data any, callback ...string) error { | ||
return r.ctx.JSONP(data, callback...) | ||
} | ||
|
||
func (r *DefaultRes) Links(link ...string) { | ||
r.ctx.Links(link...) | ||
} | ||
|
||
func (r *DefaultRes) Location(path string) { | ||
r.ctx.Location(path) | ||
} | ||
|
||
func (r *DefaultRes) Render(name string, bind Map, layouts ...string) error { | ||
return r.ctx.Render(name, bind, layouts...) | ||
} | ||
|
||
func (r *DefaultRes) Send(body []byte) error { | ||
return r.ctx.Send(body) | ||
} | ||
|
||
func (r *DefaultRes) SendFile(file string, config ...SendFile) error { | ||
return r.ctx.SendFile(file, config...) | ||
} | ||
|
||
func (r *DefaultRes) SendStatus(status int) error { | ||
return r.ctx.SendStatus(status) | ||
} | ||
|
||
func (r *DefaultRes) Set(key, val string) { | ||
r.ctx.Set(key, val) | ||
} | ||
|
||
func (r *DefaultRes) Status(status int) Res { | ||
r.ctx.Status(status) | ||
return r | ||
} | ||
|
||
func (r *DefaultRes) Type(extension string, charset ...string) Res { | ||
r.ctx.Type(extension, charset...) | ||
return r | ||
} | ||
|
||
func (r *DefaultRes) Vary(fields ...string) { | ||
r.ctx.Vary(fields...) | ||
} | ||
|
||
func (r *DefaultRes) XML(data any) error { | ||
return r.ctx.XML(data) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.