1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-28 04:23:45 +00:00
fiber/application.go

105 lines
3.1 KiB
Go
Raw Normal View History

2020-02-08 01:05:13 +01:00
// 🚀 Fiber is an Express.js inspired web framework written in Go with 💖
2020-01-22 05:42:37 +01:00
// 📌 Please open an issue if you got suggestions or found a bug!
2020-02-08 01:05:13 +01:00
// 🖥 Links: https://github.com/gofiber/fiber, https://fiber.wiki
2020-01-20 04:33:55 +01:00
// 🦸 Not all heroes wear capes, thank you to some amazing people
2020-02-08 01:05:13 +01:00
// 💖 @valyala, @erikdubbelboer, @savsgio, @julienschmidt, @koddr
2020-01-20 04:33:55 +01:00
package fiber
import (
"flag"
"time"
"github.com/valyala/fasthttp"
2020-01-20 04:33:55 +01:00
)
const (
// Version : Fiber version
2020-02-07 23:44:16 +03:00
Version = "1.4.0"
2020-02-05 20:48:43 +01:00
website = "https://fiber.wiki"
2020-01-20 04:33:55 +01:00
// https://play.golang.org/p/r6GNeV1gbH
banner = "" +
" \x1b[1;32m _____ _ _\n" +
" \x1b[1;32m| __|_| |_ ___ ___\n" +
" \x1b[1;32m| __| | . | -_| _|\n" +
" \x1b[1;32m|__| |_|___|___|_|\x1b[1;30m%s\x1b[1;32m%s\n" +
" \x1b[1;30m%s\x1b[1;32m%v\x1b[0000m\n\n"
)
var (
prefork = flag.Bool("prefork", false, "use prefork")
child = flag.Bool("child", false, "is child process")
)
// Fiber structure
type Fiber struct {
// Server name header
Server string
httpServer *fasthttp.Server
2020-01-30 23:17:25 -05:00
// Show fiber banner
2020-01-20 04:33:55 +01:00
Banner bool
2020-01-30 23:17:25 -05:00
// https://github.com/valyala/fasthttp/blob/master/server.go#L150
2020-01-20 04:33:55 +01:00
Engine *engine
// https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/
Prefork bool
2020-01-31 15:19:57 -05:00
child bool
2020-01-20 04:33:55 +01:00
// Stores all routes
routes []*Route
2020-01-20 04:33:55 +01:00
}
// Fasthttp settings
// https://github.com/valyala/fasthttp/blob/master/server.go#L150
type engine struct {
Concurrency int
DisableKeepAlive bool
ReadBufferSize int
WriteBufferSize int
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
MaxConnsPerIP int
MaxRequestsPerConn int
TCPKeepalive bool
TCPKeepalivePeriod time.Duration
MaxRequestBodySize int
ReduceMemoryUsage bool
GetOnly bool
DisableHeaderNamesNormalizing bool
SleepWhenConcurrencyLimitsExceeded time.Duration
NoDefaultContentType bool
KeepHijackedConns bool
}
// New creates a Fiber instance
func New() *Fiber {
flag.Parse()
return &Fiber{
2020-02-07 00:43:16 +01:00
Server: "",
httpServer: nil,
Banner: true,
Prefork: *prefork,
child: *child,
2020-01-20 04:33:55 +01:00
Engine: &engine{
Concurrency: 256 * 1024,
DisableKeepAlive: false,
ReadBufferSize: 4096,
WriteBufferSize: 4096,
WriteTimeout: 0,
ReadTimeout: 0,
IdleTimeout: 0,
MaxConnsPerIP: 0,
MaxRequestsPerConn: 0,
TCPKeepalive: false,
TCPKeepalivePeriod: 0,
MaxRequestBodySize: 4 * 1024 * 1024,
ReduceMemoryUsage: false,
GetOnly: false,
DisableHeaderNamesNormalizing: false,
SleepWhenConcurrencyLimitsExceeded: 0,
NoDefaultContentType: false,
KeepHijackedConns: false,
},
}
}