server

package
v0.0.0-...-d408576 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRequestTimeout = 100 * time.Second

Variables

This section is empty.

Functions

func BindRequest

func BindRequest[T validatable](c echo.Context) (T, error)

func SetResponse

func SetResponse[T any](c echo.Context, code int, data T) error

func SetResponseError

func SetResponseError(c echo.Context, code int, err HTTPError) error

func SetResponseList

func SetResponseList[T any](c echo.Context, code int, data []T, nextCursor string) error

Types

type HTTPError

type HTTPError struct {
	Code     int      `json:"-"`
	Internal string   `json:"-"`
	Message  string   `json:"message"`
	Details  []string `json:"details,omitempty"`
}

func (HTTPError) Error

func (e HTTPError) Error() string

type Handler

type Handler interface {
	Register(g *echo.Group)
}

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
}

type Option

type Option func(opts *options) error

Option optionally configures a Server.

func WithCORS

func WithCORS(origins ...string) Option

WithCORS configures the server to authorize Cross-Origin Resource Sharing (CORS) for the provided origins.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets a custom Logger.

func WithMiddleware

func WithMiddleware(middlewares ...echo.MiddlewareFunc) Option

WithMiddleware adds custom middleware to the server.

func WithRequestLogKeys

func WithRequestLogKeys(keys ...string) Option

WithRequestLogKeys adds extra log keys outside the defaults to be included in request logs.

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

WithRequestTimeout sets the timeout for request handlers.

func WithTLS

func WithTLS(certFile string, keyFile string, caCertFile string) Option

WithTLS configures the server to use TLS with the specified certificate, key, and optional CA certificate for mTLS. If caCertFile is provided, the server requires client certificates and validates them against the CA.

type RequestLoggerConfigFunc

type RequestLoggerConfigFunc func(logger log.Logger) middleware.RequestLoggerConfig

RequestLoggerConfigFunc configures request logging middleware on a Server.

type Response

type Response[T any] struct {
	Data T `json:"data"`
}

type ResponseError

type ResponseError struct {
	Error HTTPError `json:"error"`
}

type ResponseList

type ResponseList[T any] struct {
	Data           []T     `json:"data"`
	NextPageCursor *string `json:"next_page_cursor,omitempty"`
}

type Server

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

Server serves an API for managing NATS operators, accounts, and users.

func NewServer

func NewServer(port int, opts ...Option) (*Server, error)

NewServer creates a new Server with the given options.

func (*Server) Add

func (s *Server) Add(method string, path string, handler echo.HandlerFunc)

func (*Server) Address

func (s *Server) Address() string

Address returns the server address which clients can connect to.

func (*Server) Any

func (s *Server) Any(path string, handler echo.HandlerFunc)

func (*Server) Register

func (s *Server) Register(pathPrefix string, h Handler, middleware ...echo.MiddlewareFunc)

func (*Server) Start

func (s *Server) Start() error

Start begins serving on the configured host and port.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully shuts down the server.

func (*Server) WaitHealthy

func (s *Server) WaitHealthy(maxRetries int, interval time.Duration) error

func (*Server) WebsSocketAddress

func (s *Server) WebsSocketAddress() string

WebsSocketAddress returns the server WebSocket address which clients can connect to.

Jump to

Keyboard shortcuts

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