doris

package module
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 25 Imported by: 0

README

doris

Go Reference

HTTP server for Connect APIs and websites.

Install

go get github.com/altipla-consulting/doris

Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using make gofmt.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect deprecated

func Connect(r *routing.Router, fn RegisterFn)

Deprecated: Use NewConnectHub instead.

func ConnectCORS deprecated

func ConnectCORS(origins []string) cors.Options

Deprecated: Use NewConnectHub instead.

func ConnectOptions deprecated added in v0.1.1

func ConnectOptions(interceptors ...connect.Interceptor) []connect.HandlerOption

Deprecated: Use NewConnectHub instead.

func Error added in v0.11.1

func Error(w http.ResponseWriter, status int)

func Errorf

func Errorf(code connect.Code, msg string, args ...any) error

func Handler added in v0.11.0

func Handler(handler HandlerError) http.Handler

func ServerInterceptors

func ServerInterceptors() []connect.Interceptor

Types

type ConnectHub added in v0.3.0

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

ConnectHub helps mounting Connect APIs to their correct endpoints.

func NewConnectHub added in v0.3.0

func NewConnectHub(r *Router, opts ...ConnectHubOption) *ConnectHub

NewConnectHub creates a new hub prepared to mount Connect APIs.

func (*ConnectHub) Mount added in v0.3.0

func (hub *ConnectHub) Mount(fn MountFn)

Mount a new API.

type ConnectHubOption added in v0.3.0

type ConnectHubOption func(cnf *ConnectHub)

ConnectHubOption configures the Connect hub.

func WithCORS added in v0.3.0

func WithCORS(domains ...string) ConnectHubOption

WithCORS configures the domains authorized to access the API. The standard studio.buf.build is always authorized by default.

func WithInterceptors added in v0.3.0

func WithInterceptors(interceptors ...connect.Interceptor) ConnectHubOption

WithInterceptors configures the interceptors to configure in the APIs.

type HandlerError added in v0.11.0

type HandlerError func(w http.ResponseWriter, r *http.Request) error

type MountFn added in v0.3.0

type MountFn func(opts ...connect.HandlerOption) (string, http.Handler)

MountFn should be implemented by a global function in the API package to register itself.

type Option

type Option func(s *Server, sp *ServerPort, internal bool)

Option of a server.

func WithInternal added in v0.8.0

func WithInternal(opts ...Option) Option

WithInternal apply the options to the internal server with metrics and health checks. For example it can be used to change the port of the internal server. It only makes sense if enabled at the server level, not in any individual server port.

func WithListener added in v0.4.0

func WithListener(listener net.Listener) Option

WithListener configures the listener to use for the web server. It is useful to serve in custom configurations like a Unix socket or Tailscale.

func WithPort added in v0.7.0

func WithPort(port string) Option

WithPort changes the default port of the application. If the env variable PORT is defined it will override anything configured here.

func WithRoutingOptions

func WithRoutingOptions(opts ...routing.ServerOption) Option

WithRoutingOptions configures web server options.

type RegisterFn deprecated

type RegisterFn func() (pattern string, handler http.Handler)

Deprecated: Use NewConnectHub instead.

type Router added in v0.10.0

type Router struct {
	*routing.Server
}

func (*Router) Handle added in v0.11.0

func (r *Router) Handle(handler http.Handler)

Handle sends all request to the standard HTTP handler.

func (*Router) PathPrefixHandlerHTTP added in v0.10.0

func (r *Router) PathPrefixHandlerHTTP(path string, handler http.Handler)

PathPrefixHandlerHTTP registers a new HTTP handler for all the routes under the specified prefix.

type Server

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

Server is the root server of the application.

func NewServer

func NewServer(opts ...Option) *Server

NewServer creates a new root server in the default port. It won't start until you call Serve() on it.

func (*Server) Context

func (server *Server) Context() context.Context

Context returns a context that will be canceled when the server is stopped.

func (*Server) GoBackground added in v0.5.0

func (server *Server) GoBackground(fn func(ctx context.Context) error)

GoBackground runs a background goroutine that will be canceled when the server is stopped. The function should return when the context is canceled. If the function returns an error, the server will be stopped prematurely. The server will not exit until all background goroutines have finished.

func (*Server) RegisterPort added in v0.7.0

func (server *Server) RegisterPort(port string, opts ...Option) *ServerPort

Register a new child server in a different port.

func (*Server) Serve

func (server *Server) Serve()

Serve starts the server and blocks until it is stopped with a signal.

type ServerPort added in v0.7.0

type ServerPort struct {
	*Router
	// contains filtered or unexported fields
}

ServerPort is a child server in a different custom port.

Jump to

Keyboard shortcuts

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