Documentation ¶
Index ¶
- Variables
- type CorsLogger
- type Server
- func (server Server) AddFrontend(path string, rootFS fs.FS, rootPath string) error
- func (server Server) AddRoute(method, path string, handler http.Handler)
- func (server Server) AddRouteWithFunc(method, path string, handlerFunc http.HandlerFunc)
- func (server Server) IsReady() bool
- func (server *Server) Start(context context.Context) (shutdown chan error, stop chan os.Signal, err error)
- func (server Server) SubRouter(path string) *mux.Router
- type ServerOptions
Constants ¶
This section is empty.
Variables ¶
View Source
var VERSION = "1.0.9"
VERSION is the version of the package
Functions ¶
This section is empty.
Types ¶
type CorsLogger ¶ added in v1.0.2
type CorsLogger struct {
Logger *logger.Logger
}
CORS Logger
func (CorsLogger) Printf ¶ added in v1.0.2
func (corsLogger CorsLogger) Printf(format string, args ...interface{})
type Server ¶
type Server struct { // ShutdownTimeout is the maximum amount of time to wait for the // server to shutdown. Default: 15 seconds ShutdownTimeout time.Duration // contains filtered or unexported fields }
Server defines a Web Server
func (Server) AddFrontend ¶
AddFrontend adds a frontend to the server
The frontend is a static website that will be served by the server.
func (Server) AddRouteWithFunc ¶
func (server Server) AddRouteWithFunc(method, path string, handlerFunc http.HandlerFunc)
AddRouteWithFunc adds a route to the server
func (*Server) Start ¶
func (server *Server) Start(context context.Context) (shutdown chan error, stop chan os.Signal, err error)
Start starts the server
Callers should wait on the returned shutdown channel.
Callers can stop the server programatically by sending a signal on the returned stop channel.
type ServerOptions ¶
type ServerOptions struct { Address string // The address to listen on, Default: all interfaces Port int // The port to listen on, Default: 80 ProbePort int // The port to listen on for the health probe, Default: 0 (disabled) // The gorilla/mux router to use. // If not specified, a new one is created. Router *mux.Router // HealthRootPath is the root path for the health probe. // By default: "/healthz" HealthRootPath string // DisableGeneralOptionsHandler, if true, passes "OPTIONS *" // requests to the Handler, otherwise responds with 200 OK // and Content-Length: 0. DisableGeneralOptionsHandler bool // TLSConfig optionally provides a TLS configuration for use // by ServeTLS and ListenAndServeTLS. Note that this value is // cloned by ServeTLS and ListenAndServeTLS, so it's not // possible to modify the configuration with methods like // tls.Config.SetSessionTicketKeys. To use // SetSessionTicketKeys, use Server.Serve with a TLS Listener // instead. TLSConfig *tls.Config // ReadTimeout is the maximum duration for reading the entire // request, including the body. A zero or negative value means // there will be no timeout. // // Because ReadTimeout does not let Handlers make per-request // decisions on each request body's acceptable deadline or // upload rate, most users will prefer to use // ReadHeaderTimeout. It is valid to use them both. ReadTimeout time.Duration // ReadHeaderTimeout is the amount of time allowed to read // request headers. The connection's read deadline is reset // after reading the headers and the Handler can decide what // is considered too slow for the body. If ReadHeaderTimeout // is zero, the value of ReadTimeout is used. If both are // zero, there is no timeout. ReadHeaderTimeout time.Duration // WriteTimeout is the maximum duration before timing out // writes of the response. It is reset whenever a new // request's header is read. Like ReadTimeout, it does not // let Handlers make decisions on a per-request basis. // A zero or negative value means there will be no timeout. WriteTimeout time.Duration // IdleTimeout is the maximum amount of time to wait for the // next request when keep-alives are enabled. If IdleTimeout // is zero, the value of ReadTimeout is used. If both are // zero, there is no timeout. IdleTimeout time.Duration // ShutdownTimeout is the maximum amount of time to wait for the // server to shutdown. Default: 15 seconds ShutdownTimeout time.Duration // MaxHeaderBytes controls the maximum number of bytes the // server will read parsing the request header's keys and // values, including the request line. It does not limit the // size of the request body. // If zero, DefaultMaxHeaderBytes is used. MaxHeaderBytes int // TLSNextProto optionally specifies a function to take over // ownership of the provided TLS connection when an ALPN // protocol upgrade has occurred. The map key is the protocol // name negotiated. The Handler argument should be used to // handle HTTP requests and will initialize the Request's TLS // and RemoteAddr if not already set. The connection is // automatically closed when the function returns. // If TLSNextProto is not nil, HTTP/2 support is not enabled // automatically. TLSNextProto map[string]func(*http.Server, *tls.Conn, http.Handler) // ConnState specifies an optional callback function that is // called when a client connection changes state. See the // ConnState type and associated constants for details. ConnState func(net.Conn, http.ConnState) // Logger is the logger used by this server // If not specified, nothing gets logged. Logger *logger.Logger // ErrorLog specifies an optional logger for errors accepting // connections, unexpected behavior from handlers, and // underlying FileSystem errors. // If nil, logging is done via the Logger defined above. ErrorLog *log.Logger // BaseContext optionally specifies a function that returns // the base context for incoming requests on this server. // The provided Listener is the specific Listener that's // about to start accepting requests. // If BaseContext is nil, the default is context.Background(). // If non-nil, it must return a non-nil context. BaseContext func(net.Listener) context.Context // ConnContext optionally specifies a function that modifies // the context used for a new connection c. The provided ctx // is derived from the base context and has a ServerContextKey // value. ConnContext func(ctx context.Context, c net.Conn) context.Context // Configurable Handler to be used when no route matches. NotFoundHandler http.Handler // Configurable Handler to be used when the request method // does not match the route. MethodNotAllowedHandler http.Handler // AllowedCORSHeaders is the list of allowed headers AllowedCORSHeaders []string // AllowedCORSMethods is the list of allowed methods AllowedCORSMethods []string // AllowedCORSOrigins is the list of allowed origins AllowedCORSOrigins []string // ExposedCORSHeader is the list of headers that are safe to expose to // the API of a CORS API specification ExposedCORSHeaders []string // CORSMaxAge indicates how long (in seconds) the results of a preflight // request can be cached CORSMaxAge time.Duration // CORSAllowCredentials indicates whether the request can include user credentials // like cookies, HTTP authentication or client side SSL certificates CORSAllowCredentials bool // AllowOriginFunc is a custom function to validate the origin AllowOriginFunc func(origin string) bool // CPRSAllowPrivateNetwork indicates whether to acceptrequests // over a private network CORSAllowPrivateNetwork bool // CORSOptionsPasthrough instructs preflight to let other potential next handlers to // process the OPTIONS method. Turn this on if your application handles OPTIONS. CORSOptionsPasthrough bool // CORSOptionsSuccessStatus provides a status code to use for // successful OPTIONS requests, instead of http.StatusNoContent (204) CORSOptionsSuccessStatus int }
ServerOptions defines the options for the server
Source Files ¶
Click to show internal directories.
Click to hide internal directories.