server

package
v0.0.0-...-1946e7d Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 23 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectHandlerOptions

func ConnectHandlerOptions() []connect.HandlerOption

ConnectHandlerOptions returns the default options for connect handlers.

func EnableDocsFirebaseAuth

func EnableDocsFirebaseAuth(s *Server, domain string)

EnableDocsFirebaseAuth enables Firebase auth for the docs handler. The domain must be the auth domain of the Firebase project.

Firebase credentials of the browser, generally set by running the actual web app locally, will be read and added as authorization headers in requests to the server.

func HandleConnectUnary

func HandleConnectUnary[Req any, Resp any](
	s *Server,
	procedure string,
	handler func(ctx context.Context, req *Req) (*Resp, error),
	sampleRequests []*Req,
	opts ...connect.HandlerOption,
)

HandleConnectUnary mounts a connect unary handler for the given procedure with the given handler. Sample requests will be displayed in the docs interface and is recommended to be provided whenever possible.

func Main

func Main[T config.CurioStack](conf T, confFiles fs.FS, run func(ctx context.Context, conf T, b *Server) error) int

Main is the entrypoint for starting a server using CurioStack. It should be called from your main function and passed a pointer to your configuration object which embeds config.Common. The setup callback should set up handlers and such using methods on Server to define the resulting server. It must finish setup by calling Server.Start to start the server.

If you need to define default values before loading user config, they should be set on the config before passing, or otherwise it is fine to just pass a pointer to an empty struct. confFiles is a fs.FS to resolve config files as used by config.Load.

An exit code is returned, so the general pattern for this function will be to call os.Exit with the result of this function.

func Mux

func Mux(s *Server) *chi.Mux

Mux returns the chi.Mux that will be served and can be used to add route handlers.

For connect handlers it is strongly preferred to use HandleConnectUnary instead to allow registration of default interceptors and docs handler.

func NewMux

func NewMux() *chi.Mux

NewMux returns a new chi.Mux with standard middleware.

func NewServer

func NewServer(router http.Handler, conf *config.Common) *http.Server

NewServer returns a new http.Server with standard settings to serve the given router.

func Start

func Start(ctx context.Context, s *Server) error

Start starts the server, listening on the configured server address for requests based on its configuration. This method will block until program exit.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the configuration of the server that will be run.

Note that operations on Server are all functions rather than methods to allow use of generics where appropriate.

Jump to

Keyboard shortcuts

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