serve

package module
v0.0.0-...-617c99b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 8 Imported by: 0

README

serve

Http server framework for rapid development and deployment - web, REST, websockets, etc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServeTLSWithTimeouts

func ListenAndServeTLSWithTimeouts(addr, certFile, keyFile string, handler http.Handler) error

ListenAndServeTLSWithTimeouts starts a secure web server with timeouts. The default http server does not have timeouts by default, which leaves the server open to certain attacks that would start a connection, but then very slowly read or write. Timeout values are taken from global variables defined in config, which you can set at init time.

func ListenAndServeWithTimeouts

func ListenAndServeWithTimeouts(addr string, handler http.Handler) error

ListenAndServeWithTimeouts starts a web server with timeouts. The default http server does not have timeouts, which leaves the server open to certain attacks that would start a connection, but then very slowly read or write. Timeout values are taken from global variables defined in config, which you can set at init time. This non-secure version is appropriate if you are serving behind another server, like apache or nginx.

func Shutdown

func Shutdown(ctx context.Context) error

Shutdown performs a graceful shutdown of the server, returning any errors found.

Types

type ServerBase

type ServerBase struct {
	base.Base
}

func (*ServerBase) DefaultHandler

func (a *ServerBase) DefaultHandler() http.Handler

DefaultHandler is the last handler on the default call chain. It returns a simple not found error. Note that the html root handler registered in embedder.go also handles situations where an http path is not found. You can override this handler by duplicating it in your app object.

func (*ServerBase) HSTSHandler

func (a *ServerBase) HSTSHandler(next http.Handler) http.Handler

HSTSHandler sets the browser to HSTS mode using the given timeout. HSTS will force a browser to accept only HTTPS connections for everything coming from your domain, if the initial page was served over HTTPS. Many browsers already do this. What this additionally does is prevent the user from overriding this. Also, if your certificate is bad or expired, it will NOT allow the user the option of using your website anyway. This should be safe to send in development mode if your local server is not using HTTPS, since the header is ignored if a page is served over HTTP.

Once the HSTS policy has been sent to the browser, it will remember it for the amount of time specified, even if the header is not sent again. However, you can override it by sending another header, and clear it by setting the timeout to 0. Set the timeout to -1 to turn it off. You can also completely override this by implementing this function in your app.go file.

func (*ServerBase) Init

func (a *ServerBase) Init(self ServerBaseI)

func (*ServerBase) MakeHandler

func (a *ServerBase) MakeHandler() http.Handler

func (*ServerBase) ServeAppMux

func (a *ServerBase) ServeAppMux(next http.Handler) http.Handler

ServeAppMux serves up the http2.AppMuxer, which handles REST calls, and dynamically created files.

To use your own AppMuxer, override this function in app.go and create your own.

func (*ServerBase) ServePatternMux

func (a *ServerBase) ServePatternMux(next http.Handler) http.Handler

ServePatternMux serves up the http2.PatternMuxer.

The pattern muxer routes patterns early in the handler stack. It is primarily for handlers that do not need the session manager or buffered output, things like static files.

The default version injects a standard http muxer. Override to use your own muxer.

type ServerBaseI

type ServerBaseI interface {
	Init()
	DefaultHandler() http.Handler
	HSTSHandler(next http.Handler) http.Handler
	ServeAppMux(next http.Handler) http.Handler
	ServePatternMux(next http.Handler) http.Handler
}

ServerBaseI defines the virtual functions that are callable on the Server.

Directories

Path Synopsis
Package config contains configurable default values for various aspects of goradd.
Package config contains configurable default values for various aspects of goradd.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL