Documentation
¶
Index ¶
- Constants
- func NewHttpServerConfigRoute() *httpServerConfigRoute
- type CallbackError
- type CallbackLimitReached
- type Config
- type ConfigCORS
- type ConfigCompression
- type ConfigHost
- type ConfigHostWebsocket
- type ConfigLimiter
- type ConfigServer
- type ConfigStatic
- type HttpServer
- func (instance *HttpServer) All(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
- func (instance *HttpServer) Configuration() *Config
- func (instance *HttpServer) Configure(httpPort, httpsPort int, certPem, certKey, wwwRoot string, ...) *HttpServer
- func (instance *HttpServer) ConfigureCors(settings map[string]interface{})
- func (instance *HttpServer) ConfigureFromFile(filename string) error
- func (instance *HttpServer) ConfigureFromJson(text string) error
- func (instance *HttpServer) ConfigureFromMap(settings map[string]interface{}) error
- func (instance *HttpServer) ConfigureHosts(settings ...map[string]interface{})
- func (instance *HttpServer) ConfigureServer(settings map[string]interface{})
- func (instance *HttpServer) ConfigureSimpleStatic(port int, wwwRoot string) *HttpServer
- func (instance *HttpServer) ConfigureStatic(settings ...map[string]interface{})
- func (instance *HttpServer) Delete(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
- func (instance *HttpServer) Get(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
- func (instance *HttpServer) Group(route string, callbacks ...func(ctx *fiber.Ctx) error)
- func (instance *HttpServer) HandleAll(route string, handler IHttpHandler) *HttpServer
- func (instance *HttpServer) HandleDelete(route string, handler IHttpHandler) *HttpServer
- func (instance *HttpServer) HandleGet(route string, handler IHttpHandler) *HttpServer
- func (instance *HttpServer) HandleMiddleware(route string, handler IHttpHandler) *HttpServer
- func (instance *HttpServer) HandlePost(route string, handler IHttpHandler) *HttpServer
- func (instance *HttpServer) HandlePut(route string, handler IHttpHandler) *HttpServer
- func (instance *HttpServer) IsOpen() bool
- func (instance *HttpServer) Join() (err error)
- func (instance *HttpServer) Middleware(route string, callback func(ctx *fiber.Ctx) error) *HttpServer
- func (instance *HttpServer) Post(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
- func (instance *HttpServer) Put(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
- func (instance *HttpServer) Restart() []error
- func (instance *HttpServer) Start(settings ...map[string]interface{}) []error
- func (instance *HttpServer) Stop() (err error)
- func (instance *HttpServer) StopWithTimeout(timeout time.Duration) (err error)
- func (instance *HttpServer) Use(middleware ...fiber.Handler) *HttpServer
- func (instance *HttpServer) Websocket(route string, handler WsConnectionHandler) *HttpServer
- type HttpServerError
- type HttpWebsocket
- type HttpWebsocketConn
- func (instance *HttpWebsocketConn) ClientByUUID(uuid string) *HttpWebsocketConn
- func (instance *HttpWebsocketConn) ClientsCount() int
- func (instance *HttpWebsocketConn) ClientsUUIDs() []string
- func (instance *HttpWebsocketConn) Conn() *websocket.Conn
- func (instance *HttpWebsocketConn) IsAlive() bool
- func (instance *HttpWebsocketConn) Join()
- func (instance *HttpWebsocketConn) Locals(key string) interface{}
- func (instance *HttpWebsocketConn) OnDisconnect(callback WsEventHandler)
- func (instance *HttpWebsocketConn) OnMessage(callback WsEventHandler)
- func (instance *HttpWebsocketConn) Send(messageType int, data []byte)
- func (instance *HttpWebsocketConn) SendData(data []byte)
- func (instance *HttpWebsocketConn) SendDataTo(uuid string, data []byte)
- func (instance *HttpWebsocketConn) SendText(text string)
- func (instance *HttpWebsocketConn) SendTextTo(uuid string, text string)
- func (instance *HttpWebsocketConn) SendTo(uuid string, messageType int, data []byte)
- func (instance *HttpWebsocketConn) Shutdown(err error) error
- type HttpWebsocketEventPayload
- type IHttpHandler
- type Message
- type ServerMonitor
- type WsConnectionHandler
- type WsEventHandler
Constants ¶
View Source
const ( // TextMessage denotes a text data message. The text message payload is // interpreted as UTF-8 encoded text data. TextMessage = 1 // BinaryMessage denotes a binary data message. BinaryMessage = 2 // CloseMessage denotes a close control message. The optional message // payload contains a numeric code and text. Use the FormatCloseMessage // function to format a close message payload. CloseMessage = 8 // PingMessage denotes a ping control message. The optional message payload // is UTF-8 encoded text. PingMessage = 9 // PongMessage denotes a pong control message. The optional message payload // is UTF-8 encoded text. PongMessage = 10 )
Source @url:https://github.com/gorilla/websocket/blob/master/conn.go#L61 The message types are defined in RFC 6455, section 11.8.
View Source
const ( OnDisconnectEvent = "on_disconnect" OnMessageEvent = "on_message" )
View Source
const EventOnFileChanged = "on_file_changed"
Variables ¶
This section is empty.
Functions ¶
func NewHttpServerConfigRoute ¶
func NewHttpServerConfigRoute() *httpServerConfigRoute
Types ¶
type CallbackError ¶
type CallbackError func(serverError *HttpServerError)
type CallbackLimitReached ¶
type CallbackLimitReached func(ctx *fiber.Ctx) error
type Config ¶
type Config struct { Server *ConfigServer `json:"server"` Cors *ConfigCORS `json:"cors"` Compression *ConfigCompression `json:"compression"` Limiter *ConfigLimiter `json:"limiter"` Hosts []*ConfigHost `json:"hosts"` Static []*ConfigStatic `json:"static"` }
type ConfigCORS ¶
type ConfigCORS struct { Enabled bool `json:"enabled"` // AllowOrigin defines a list of origins that may access the resource. AllowOrigins []string `json:"allow_origins"` // default: []string{"*"} // AllowMethods defines a list methods allowed when accessing the resource. This is used in response to a preflight request. AllowMethods []string `json:"allow_methods"` // default: []string{"GET", "POST", "HEAD", "PUT", "DELETE", "PATCH"} // AllowCredentials indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials. AllowCredentials bool `json:"allow_credentials"` // default: false // ExposeHeaders defines a whitelist headers that clients are allowed to access. ExposeHeaders []string `json:"expose_headers"` // default: nil // MaxAge indicates how long (in seconds) the results of a preflight request can be cached. MaxAge int `json:"max_age"` // default: 0 }
type ConfigCompression ¶
type ConfigHost ¶
type ConfigHost struct { Address string `json:"addr"` TLS bool `json:"tls"` // TLS SslCert string `json:"ssl_cert"` SslKey string `json:"ssl_key"` // websocket Websocket *ConfigHostWebsocket `json:"websocket"` }
type ConfigHostWebsocket ¶
type ConfigHostWebsocket struct { Enabled bool `json:"enabled"` // Specifies the duration for the handshake to complete. HandshakeTimeout time.Duration `json:"handshake_timeout"` // default: 0 milliseconds // specifies the server's supported protocols in order of preference. If this field is not nil, then the Upgrade // method negotiates a subprotocol by selecting the first match in this list with a protocol requested by the client. Subprotocols []string `json:"subprotocols"` // default: nil // Origins is a string slice of origins that are acceptable, by default all origins are allowed. Origins []string `json:"origins"` // default: []string{"*"} // ReadBufferSize specify I/O buffer sizes in bytes. ReadBufferSize int `json:"read_buffer_size"` // default: 1024 // WriteBufferSize specify I/O buffer sizes in bytes. WriteBufferSize int `json:"write_buffer_size"` // default: 1024 // EnableCompression specify if the server should attempt to negotiate per message compression (RFC 7692) EnableCompression bool `json:"enable_compression"` // default:false }
type ConfigLimiter ¶
type ConfigLimiter struct { Enabled bool `json:"enabled"` // Max number of recent connections during `Duration` seconds before sending a 429 response // // Default: 5 Max int `json:"max"` // Duration is the time on how long to keep records of requests in memory // // Default: 1 * time.Minute Duration time.Duration `json:"duration"` }
type ConfigServer ¶
type ConfigServer struct { // SETTINGS // Request ID adds an identifier to the request using the X-Request-ID header ( uuid.New().String() ) EnableRequestId bool `json:"enable_request_id"` // // Enables use of the SO_REUSEPORT socket option. This will spawn multiple Go processes listening on the same port. learn more about socket sharding // https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/ Prefork bool `json:"prefork"` // default: false // Enables the Http HTTP header with the given value. ServerHeader string `json:"server_header"` // default: "" // When enabled, the router treats /foo and /foo/ as different. Otherwise, the router treats /foo and /foo/ as the same. StrictRouting bool `json:"strict_routing"` // default: false // When enabled, /Foo and /foo are different routes. When disabled, /Fooand /foo are treated the same. CaseSensitive bool `json:"case_sensitive"` // default: false // When enabled, all values returned by context methods are immutable. By default they are valid until you return from the handler, see issue #185. Immutable bool `json:"immutable"` // default: false // Sets the maximum allowed size for a request body, if the size exceeds the configured limit, it sends 413 - Request Entity Too Large response. BodyLimit int `json:"body_limit"` // default: 4 * 1024 * 1024 // The amount of time allowed to read the full request including body. Default timeout is unlimited. ReadTimeout time.Duration `json:"read_timeout"` // default: 0 // The maximum duration before timing out writes of the response. Default timeout is unlimited. WriteTimeout time.Duration `json:"write_timeout"` // default: 0 // The maximum amount of time to wait for the next request when keep-alive is enabled. If IdleTimeout is zero, the value of ReadTimeout is used. IdleTimeout time.Duration `json:"idle_timeout"` // default: 0 // Maximum number of concurrent connections. Concurrency int `json:"concurrency"` // default: 256 * 1024 // Disable keep-alive connections. The server will close incoming connections after sending the first response to the client. DisableKeepalive bool `json:"disable_keepalive"` // default: false // When set to true, it will not print out debug information and startup message DisableStartupMessage bool `json:"disable_startup_message"` // default false }
ConfigServer https://dev.to/koddr/go-fiber-by-examples-delving-into-built-in-functions-1p3k
type ConfigStatic ¶
type ConfigStatic struct { Enabled bool `json:"enabled"` Prefix string `json:"prefix"` Root string `json:"root"` Index string `json:"index"` Compress bool `json:"compress"` // When set to true, enables byte range requests. ByteRange bool `json:"byte_range"` // default: false // When set to true, enables directory browsing. Browse bool `json:"browse"` // default: false. // Expiration duration for inactive file handlers. Use a negative time.Duration to disable it CacheDurationSec int64 `json:"cache_duration_sec"` // default: 10 * time.Second // The value for the Cache-Control HTTP header that is set on the file response. MaxAge is defined in seconds. MaxAge int `json:"max_age"` // default: 0 }
type HttpServer ¶
type HttpServer struct {
// contains filtered or unexported fields
}
func NewHttpServer ¶
func NewHttpServer(workspace string, callbackError CallbackError, callbackLimit CallbackLimitReached) *HttpServer
func (*HttpServer) All ¶
func (instance *HttpServer) All(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
func (*HttpServer) Configuration ¶
func (instance *HttpServer) Configuration() *Config
func (*HttpServer) Configure ¶
func (instance *HttpServer) Configure(httpPort, httpsPort int, certPem, certKey, wwwRoot string, enableWebsocket bool) *HttpServer
func (*HttpServer) ConfigureCors ¶
func (instance *HttpServer) ConfigureCors(settings map[string]interface{})
func (*HttpServer) ConfigureFromFile ¶
func (instance *HttpServer) ConfigureFromFile(filename string) error
func (*HttpServer) ConfigureFromJson ¶
func (instance *HttpServer) ConfigureFromJson(text string) error
func (*HttpServer) ConfigureFromMap ¶
func (instance *HttpServer) ConfigureFromMap(settings map[string]interface{}) error
func (*HttpServer) ConfigureHosts ¶
func (instance *HttpServer) ConfigureHosts(settings ...map[string]interface{})
func (*HttpServer) ConfigureServer ¶
func (instance *HttpServer) ConfigureServer(settings map[string]interface{})
func (*HttpServer) ConfigureSimpleStatic ¶
func (instance *HttpServer) ConfigureSimpleStatic(port int, wwwRoot string) *HttpServer
func (*HttpServer) ConfigureStatic ¶
func (instance *HttpServer) ConfigureStatic(settings ...map[string]interface{})
func (*HttpServer) Delete ¶
func (instance *HttpServer) Delete(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
func (*HttpServer) Get ¶
func (instance *HttpServer) Get(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
func (*HttpServer) Group ¶
func (instance *HttpServer) Group(route string, callbacks ...func(ctx *fiber.Ctx) error)
func (*HttpServer) HandleAll ¶
func (instance *HttpServer) HandleAll(route string, handler IHttpHandler) *HttpServer
func (*HttpServer) HandleDelete ¶
func (instance *HttpServer) HandleDelete(route string, handler IHttpHandler) *HttpServer
func (*HttpServer) HandleGet ¶
func (instance *HttpServer) HandleGet(route string, handler IHttpHandler) *HttpServer
func (*HttpServer) HandleMiddleware ¶
func (instance *HttpServer) HandleMiddleware(route string, handler IHttpHandler) *HttpServer
func (*HttpServer) HandlePost ¶
func (instance *HttpServer) HandlePost(route string, handler IHttpHandler) *HttpServer
func (*HttpServer) HandlePut ¶
func (instance *HttpServer) HandlePut(route string, handler IHttpHandler) *HttpServer
func (*HttpServer) IsOpen ¶
func (instance *HttpServer) IsOpen() bool
func (*HttpServer) Join ¶
func (instance *HttpServer) Join() (err error)
func (*HttpServer) Middleware ¶
func (instance *HttpServer) Middleware(route string, callback func(ctx *fiber.Ctx) error) *HttpServer
func (*HttpServer) Post ¶
func (instance *HttpServer) Post(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
func (*HttpServer) Put ¶
func (instance *HttpServer) Put(route string, callbacks ...func(ctx *fiber.Ctx) error) *HttpServer
func (*HttpServer) Restart ¶
func (instance *HttpServer) Restart() []error
func (*HttpServer) Start ¶
func (instance *HttpServer) Start(settings ...map[string]interface{}) []error
func (*HttpServer) Stop ¶
func (instance *HttpServer) Stop() (err error)
func (*HttpServer) StopWithTimeout ¶
func (instance *HttpServer) StopWithTimeout(timeout time.Duration) (err error)
func (*HttpServer) Use ¶
func (instance *HttpServer) Use(middleware ...fiber.Handler) *HttpServer
func (*HttpServer) Websocket ¶
func (instance *HttpServer) Websocket(route string, handler WsConnectionHandler) *HttpServer
type HttpServerError ¶
type HttpWebsocket ¶
type HttpWebsocket struct {
// contains filtered or unexported fields
}
func NewHttpWebsocket ¶
func NewHttpWebsocket(app *fiber.App, cfgHost *ConfigHost, cfgRoutes []*httpServerConfigRouteWebsocket) *HttpWebsocket
func (*HttpWebsocket) Init ¶
func (instance *HttpWebsocket) Init()
type HttpWebsocketConn ¶
type HttpWebsocketConn struct { UUID string // contains filtered or unexported fields }
func NewHttpWebsocketConn ¶
func NewHttpWebsocketConn(conn *websocket.Conn, pool map[string]*HttpWebsocketConn) *HttpWebsocketConn
func (*HttpWebsocketConn) ClientByUUID ¶
func (instance *HttpWebsocketConn) ClientByUUID(uuid string) *HttpWebsocketConn
func (*HttpWebsocketConn) ClientsCount ¶
func (instance *HttpWebsocketConn) ClientsCount() int
func (*HttpWebsocketConn) ClientsUUIDs ¶
func (instance *HttpWebsocketConn) ClientsUUIDs() []string
func (*HttpWebsocketConn) Conn ¶
func (instance *HttpWebsocketConn) Conn() *websocket.Conn
func (*HttpWebsocketConn) IsAlive ¶
func (instance *HttpWebsocketConn) IsAlive() bool
func (*HttpWebsocketConn) Join ¶
func (instance *HttpWebsocketConn) Join()
func (*HttpWebsocketConn) Locals ¶
func (instance *HttpWebsocketConn) Locals(key string) interface{}
func (*HttpWebsocketConn) OnDisconnect ¶
func (instance *HttpWebsocketConn) OnDisconnect(callback WsEventHandler)
func (*HttpWebsocketConn) OnMessage ¶
func (instance *HttpWebsocketConn) OnMessage(callback WsEventHandler)
func (*HttpWebsocketConn) Send ¶
func (instance *HttpWebsocketConn) Send(messageType int, data []byte)
func (*HttpWebsocketConn) SendData ¶
func (instance *HttpWebsocketConn) SendData(data []byte)
func (*HttpWebsocketConn) SendDataTo ¶
func (instance *HttpWebsocketConn) SendDataTo(uuid string, data []byte)
func (*HttpWebsocketConn) SendText ¶
func (instance *HttpWebsocketConn) SendText(text string)
func (*HttpWebsocketConn) SendTextTo ¶
func (instance *HttpWebsocketConn) SendTextTo(uuid string, text string)
func (*HttpWebsocketConn) SendTo ¶
func (instance *HttpWebsocketConn) SendTo(uuid string, messageType int, data []byte)
func (*HttpWebsocketConn) Shutdown ¶
func (instance *HttpWebsocketConn) Shutdown(err error) error
type HttpWebsocketEventPayload ¶
type HttpWebsocketEventPayload struct { Websocket *HttpWebsocketConn // sender Message *Message Error error }
type IHttpHandler ¶
type IHttpHandler interface {
Handle(ctx *fiber.Ctx) error
}
type ServerMonitor ¶
type ServerMonitor struct {
// contains filtered or unexported fields
}
func NewMonitor ¶
func NewMonitor(files []string) *ServerMonitor
func (*ServerMonitor) OnFileChanged ¶
func (instance *ServerMonitor) OnFileChanged(callback func(event *gg_events.Event))
func (*ServerMonitor) Start ¶
func (instance *ServerMonitor) Start()
func (*ServerMonitor) Stop ¶
func (instance *ServerMonitor) Stop()
type WsConnectionHandler ¶
type WsConnectionHandler func(c *HttpWebsocketConn)
type WsEventHandler ¶
type WsEventHandler func(payload *HttpWebsocketEventPayload)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.