httpserver

package
v0.0.0-...-ceb351d Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHTTPAddress for http server
	DefaultHTTPAddress = ":8080"
)

Variables

This section is empty.

Functions

func RequestResponseHandler

func RequestResponseHandler(endpoint Endpoint) func(ctx *gin.Context)

Types

type Config

type Config struct {
	Address string
}

Config keeps the server configuration

type Endpoint

type Endpoint struct {
	Method  string
	Path    string
	Handler HandlerFunc
}

type HandlerFunc

type HandlerFunc func(ctx *gin.Context) (interface{}, error, int)

type Opt

type Opt func(*Option)

Opt is used to set the dependencies configurations for the server

func WithConfig

func WithConfig(c Config) Opt

WithConfig will set the Server Config in dependencies

func WithObservabilityServices

func WithObservabilityServices(s *observability.Observability) Opt

WithObservabilityServices will set Metrics, tracer and logger

func WithRoutes

func WithRoutes(routes map[string]Routes) Opt

WithRoutes takes the route configuration and registers with the route handler specified in the route configuration

type Option

type Option struct {
	// Observability holds the observability services
	// used by server: tracing, metrics and logger
	// this will be used by all services of server
	*observability.Observability

	// Config holds all the configurations for server
	Config Config

	// Routes holds mapping of relative paths to their
	// corresponding route configurations.
	Routes map[string]Routes
}

Option struct holds all the external package dependency for the server. Options is a separate struct as this can become really big in future We avoid singletons by this simple approach

func NewOption

func NewOption(opts ...Opt) *Option

NewOption will create a new server Deps object and apply all the options to that object and returns pointer to the Deps

type Routes

type Routes struct {
	Group     string
	Endpoints []Endpoint
}

type Server

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

Server is the struct to keep gin loosely coupled gin will be present in this layer and each package's server.go only

func New

func New(ctx context.Context, opt ...Opt) (*Server, error)

New creates a new server

func (*Server) GetGinEngine

func (s *Server) GetGinEngine() *gin.Engine

func (*Server) Run

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

Run starts the server

func (*Server) Shutdown

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

Shutdown the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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