mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
Add more comments
This commit is contained in:
parent
66632ccda9
commit
9657019879
45
app.go
45
app.go
@ -51,7 +51,6 @@ type (
|
|||||||
// Enables handler values to be immutable even if you return from handler
|
// Enables handler values to be immutable even if you return from handler
|
||||||
Immutable bool `default:"false"`
|
Immutable bool `default:"false"`
|
||||||
// Deprecated v1.8.2
|
// Deprecated v1.8.2
|
||||||
// Enables GZip / Deflate compression for all responses
|
|
||||||
Compression bool `default:"false"`
|
Compression bool `default:"false"`
|
||||||
// Max body size that the server accepts
|
// Max body size that the server accepts
|
||||||
BodyLimit int `default:"4 * 1024 * 1024"`
|
BodyLimit int `default:"4 * 1024 * 1024"`
|
||||||
@ -64,7 +63,10 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// New : https://fiber.wiki/application#new
|
// This method creates a new Fiber named instance.
|
||||||
|
// You can pass optional settings when creating a new instance.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#new
|
||||||
func New(settings ...*Settings) *App {
|
func New(settings ...*Settings) *App {
|
||||||
var prefork, child bool
|
var prefork, child bool
|
||||||
// Loop trought args without using flag.Parse()
|
// Loop trought args without using flag.Parse()
|
||||||
@ -97,14 +99,17 @@ func New(settings ...*Settings) *App {
|
|||||||
getBytes = func(s string) []byte { return []byte(s) }
|
getBytes = func(s string) []byte { return []byte(s) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Deprecated
|
// This function is deprecated since v1.8.2!
|
||||||
|
// Please us github.com/gofiber/compression
|
||||||
if app.Settings.Compression {
|
if app.Settings.Compression {
|
||||||
log.Println("Warning: Settings.Compression is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
|
log.Println("Warning: Settings.Compression is deprecated since v1.8.2, please use github.com/gofiber/compression instead.")
|
||||||
}
|
}
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group : https://fiber.wiki/application#group
|
// You can group routes by creating a *Group struct.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#group
|
||||||
func (app *App) Group(prefix string, handlers ...func(*Ctx)) *Group {
|
func (app *App) Group(prefix string, handlers ...func(*Ctx)) *Group {
|
||||||
if len(handlers) > 0 {
|
if len(handlers) > 0 {
|
||||||
app.registerMethod("USE", prefix, handlers...)
|
app.registerMethod("USE", prefix, handlers...)
|
||||||
@ -115,7 +120,9 @@ func (app *App) Group(prefix string, handlers ...func(*Ctx)) *Group {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static represents settings for serving static files
|
// Settings struct for serving static files
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#static
|
||||||
type Static struct {
|
type Static struct {
|
||||||
// Transparently compresses responses if set to true
|
// Transparently compresses responses if set to true
|
||||||
// This works differently than the github.com/gofiber/compression middleware
|
// This works differently than the github.com/gofiber/compression middleware
|
||||||
@ -134,13 +141,22 @@ type Static struct {
|
|||||||
Index string
|
Index string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static : https://fiber.wiki/application#static
|
// Serve static files such as images, CSS and JavaScript files, you can use the Static method.
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#static
|
||||||
func (app *App) Static(prefix, root string, config ...Static) *App {
|
func (app *App) Static(prefix, root string, config ...Static) *App {
|
||||||
app.registerStatic(prefix, root, config...)
|
app.registerStatic(prefix, root, config...)
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use : https://fiber.wiki/application#http-methods
|
// Use only match requests starting with the specified prefix
|
||||||
|
// It's optional to provide a prefix, default: "/"
|
||||||
|
// Example: Use("/product", handler)
|
||||||
|
// will match /product
|
||||||
|
// will match /product/cool
|
||||||
|
// will match /product/foo
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#http-methods
|
||||||
func (app *App) Use(args ...interface{}) *App {
|
func (app *App) Use(args ...interface{}) *App {
|
||||||
var path = ""
|
var path = ""
|
||||||
var handlers []func(*Ctx)
|
var handlers []func(*Ctx)
|
||||||
@ -212,19 +228,28 @@ func (app *App) Get(path string, handlers ...func(*Ctx)) *App {
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
// All : https://fiber.wiki/application#http-methods
|
// All matches all HTTP methods and complete paths
|
||||||
|
// Example: All("/product", handler)
|
||||||
|
// will match /product
|
||||||
|
// won't match /product/cool <-- important
|
||||||
|
// won't match /product/foo <-- important
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#http-methods
|
||||||
func (app *App) All(path string, handlers ...func(*Ctx)) *App {
|
func (app *App) All(path string, handlers ...func(*Ctx)) *App {
|
||||||
app.registerMethod("ALL", path, handlers...)
|
app.registerMethod("ALL", path, handlers...)
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSocket : https://fiber.wiki/application#websocket
|
// This function is deprecated since v1.8.2!
|
||||||
|
// Please us github.com/gofiber/websocket
|
||||||
func (app *App) WebSocket(path string, handle func(*Ctx)) *App {
|
func (app *App) WebSocket(path string, handle func(*Ctx)) *App {
|
||||||
|
log.Println("Warning: app.WebSocket() is deprecated since v1.8.2, please use github.com/gofiber/websocket instead.")
|
||||||
app.registerWebSocket(http.MethodGet, path, handle)
|
app.registerWebSocket(http.MethodGet, path, handle)
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recover : https://fiber.wiki/application#recover
|
// This function is deprecated since v1.8.2!
|
||||||
|
// Please us github.com/gofiber/recover
|
||||||
func (app *App) Recover(handler func(*Ctx)) {
|
func (app *App) Recover(handler func(*Ctx)) {
|
||||||
log.Println("Warning: app.Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
|
log.Println("Warning: app.Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
|
||||||
app.recover = handler
|
app.recover = handler
|
||||||
|
@ -167,6 +167,7 @@ func (ctx *Ctx) AcceptsCharsets(offers ...string) (offer string) {
|
|||||||
specs := strings.Split(h, ",")
|
specs := strings.Split(h, ",")
|
||||||
for _, value := range offers {
|
for _, value := range offers {
|
||||||
for _, spec := range specs {
|
for _, spec := range specs {
|
||||||
|
|
||||||
spec = strings.TrimSpace(spec)
|
spec = strings.TrimSpace(spec)
|
||||||
if strings.HasPrefix(spec, "*") {
|
if strings.HasPrefix(spec, "*") {
|
||||||
return value
|
return value
|
||||||
|
26
group.go
26
group.go
@ -35,7 +35,14 @@ func (grp *Group) Static(prefix, root string, config ...Static) *Group {
|
|||||||
return grp
|
return grp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use : https://fiber.wiki/application#http-methods
|
// Use only match requests starting with the specified prefix
|
||||||
|
// It's optional to provide a prefix, default: "/"
|
||||||
|
// Example: Use("/product", handler)
|
||||||
|
// will match /product
|
||||||
|
// will match /product/cool
|
||||||
|
// will match /product/foo
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#http-methods
|
||||||
func (grp *Group) Use(args ...interface{}) *Group {
|
func (grp *Group) Use(args ...interface{}) *Group {
|
||||||
var path = ""
|
var path = ""
|
||||||
var handlers []func(*Ctx)
|
var handlers []func(*Ctx)
|
||||||
@ -117,22 +124,31 @@ func (grp *Group) Get(path string, handlers ...func(*Ctx)) *Group {
|
|||||||
return grp
|
return grp
|
||||||
}
|
}
|
||||||
|
|
||||||
// All : https://fiber.wiki/application#http-methods
|
// All matches all HTTP methods and complete paths
|
||||||
|
// Example: All("/product", handler)
|
||||||
|
// will match /product
|
||||||
|
// won't match /product/cool <-- important
|
||||||
|
// won't match /product/foo <-- important
|
||||||
|
//
|
||||||
|
// https://fiber.wiki/application#http-methods
|
||||||
func (grp *Group) All(path string, handlers ...func(*Ctx)) *Group {
|
func (grp *Group) All(path string, handlers ...func(*Ctx)) *Group {
|
||||||
path = groupPaths(grp.prefix, path)
|
path = groupPaths(grp.prefix, path)
|
||||||
grp.app.registerMethod("ALL", path, handlers...)
|
grp.app.registerMethod("ALL", path, handlers...)
|
||||||
return grp
|
return grp
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSocket : https://fiber.wiki/application#websocket
|
// This function is deprecated since v1.8.2!
|
||||||
|
// Please us github.com/gofiber/websocket
|
||||||
func (grp *Group) WebSocket(path string, handle func(*Ctx)) *Group {
|
func (grp *Group) WebSocket(path string, handle func(*Ctx)) *Group {
|
||||||
|
log.Println("Warning: app.WebSocket() is deprecated since v1.8.2, please use github.com/gofiber/websocket instead.")
|
||||||
path = groupPaths(grp.prefix, path)
|
path = groupPaths(grp.prefix, path)
|
||||||
grp.app.registerWebSocket(http.MethodGet, path, handle)
|
grp.app.registerWebSocket(http.MethodGet, path, handle)
|
||||||
return grp
|
return grp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recover : https://fiber.wiki/application#recover
|
// This function is deprecated since v1.8.2!
|
||||||
|
// Please us github.com/gofiber/recover
|
||||||
func (grp *Group) Recover(handler func(*Ctx)) {
|
func (grp *Group) Recover(handler func(*Ctx)) {
|
||||||
log.Println("Warning: Recover(handler) is deprecated since v1.8.2, please use middleware.Recover(handler, error) instead.")
|
log.Println("Warning: Recover() is deprecated since v1.8.2, please use github.com/gofiber/recover instead.")
|
||||||
grp.app.recover = handler
|
grp.app.recover = handler
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user