server

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 12 Imported by: 9

Documentation

Overview

A package server is a package that contains the server implementation of the application.

Index

Constants

This section is empty.

Variables

View Source
var DefaultEnv = ServiceEnv{Name("SERVICE_NAME")}

DefaultEnv is the default environment variables to lookup the service name.

View Source
var DefaultRoues = map[string]http.Handler{
	"/debug/pprof/trace":   http.HandlerFunc(pprof.Trace),
	"/debug/pprof/":        http.HandlerFunc(pprof.Index),
	"/debug/pprof/cmdline": http.HandlerFunc(pprof.Cmdline),
	"/debug/pprof/profile": http.HandlerFunc(pprof.Profile),
	"/debug/pprof/symbol":  http.HandlerFunc(pprof.Symbol),
}

DefaultRoues are the default routes for the debug listener.

View Source
var ErrUnimplemented = errors.New("server: unimplemented")

ErrUnimplemented is returned when a listener is not implemented.

View Source
var Service = &service{}

Service is used to configure the service.

Functions

func NewDebug added in v0.1.4

func NewDebug(opts ...DebugOpt) *debug

NewDebug is a function that creates a new debug listener.

func WithContext

func WithContext(ctx context.Context) (*server, context.Context)

WithContext is creating a new server with a context.

Types

type DebugOpt added in v0.1.4

type DebugOpt func(*DebugOpts)

DebugOpt is a function that configures the debug options.

func WithAddr added in v0.1.4

func WithAddr(addr string) DebugOpt

WithAddr is adding this status addr as an option.

func WithPprof added in v0.1.4

func WithPprof() DebugOpt

WithPprof is adding this pprof routes as an option.

func WithPrometheusHandler added in v0.1.4

func WithPrometheusHandler(handler http.Handler) DebugOpt

WithPrometheusHandler is adding this prometheus http handler as an option.

type DebugOpts added in v0.1.4

type DebugOpts struct {
	// Addr is the address to listen on.
	Addr string
	// Routes configures the routes for the debug listener.
	Routes map[string]http.Handler
}

DebugOpts are the options for the debug listener.

func DefaultOpts added in v0.1.4

func DefaultOpts() *DebugOpts

DefaultOpts returns the default options for the debug listener.

func (*DebugOpts) Configure added in v0.1.4

func (o *DebugOpts) Configure(opts ...DebugOpt)

Configure is a method that configures the debug options.

type Listener

type Listener interface {
	// Start is being called on the listener
	Start(context.Context, ReadyFunc, RunFunc) func() error
}

Listener is the interface to a listener, so starting and shutdown of a listener, or any routine.

type Name

type Name string

Name is used to return the service name.

func (Name) String

func (n Name) String() string

String returns the name as a string.

type ReadyFunc

type ReadyFunc func()

ReadyFunc is the function that is called by Listener to signal that it is ready and the next Listener can be called.

type RunFunc

type RunFunc func(func() error)

RunFunc is a function that is called to attach more routines to the server.

type Server

type Server interface {
	// Run is running a new go routine
	Listen(listener Listener, ready bool)

	// Waits for the server to fail,
	// or gracefully shutdown if context is canceled
	Wait() error

	// SetLimit ...
	SetLimit(n int)
}

Server is the interface to be implemented to run the server.

s, ctx := WithContext(context.Background())
s.Listen(listener, false)

if err := s.Wait(); err != nil {
	panic(err)
}

type ServerError

type ServerError struct {
	Err error
}

ServerError ...

func NewServerError

func NewServerError(err error) *ServerError

NewServerError returns a new error.

func (*ServerError) Error

func (s *ServerError) Error() string

Error implements the error interface.

func (*ServerError) Unwrap

func (s *ServerError) Unwrap() error

Unwrap ...

type ServiceEnv

type ServiceEnv []Name

ServiceEnv is a list of environment variables to lookup the service name.

type Unimplemented

type Unimplemented struct{}

Unimplemented is the default implementation.

func (*Unimplemented) Start

func (s *Unimplemented) Start(context.Context, ReadyFunc, RunFunc) func() error

Start ...

Jump to

Keyboard shortcuts

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