http

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = types.Module{
	{CreateFunc: NewHTTPConfig},
	{CreateFunc: NewHTTP},
	{CreateFunc: Adapter},
}

Functions

func Handler

func Handler(opts ...Option) http.Handler

Handler returns an http.Handler

func HandlerFunc

func HandlerFunc(opts ...Option) http.HandlerFunc

HandlerFunc returns an http.HandlerFunc to mount the API implementation at a specific route

func ReadReleaseIDFromPath

func ReadReleaseIDFromPath(path string) (string, error)

Types

type AdapterIn

type AdapterIn struct {
	dig.In

	Server *Server
}

type AdapterOut

type AdapterOut struct {
	dig.Out

	Server types.Runnable `group:"servers"`
}

func Adapter

func Adapter(in AdapterIn) AdapterOut

type Checker

type Checker interface {
	Check(ctx context.Context) error
}

Checker checks the status of the dependency and returns error. In case the dependency is working as expected, return nil.

type CheckerFunc

type CheckerFunc func(ctx context.Context) error

func (CheckerFunc) Check

func (c CheckerFunc) Check(ctx context.Context) error

Check Implements the Checker interface to allow for any func() error method to be passed as a Checker

type Config

type Config struct {
	ListenAddr       string
	KeepaliveTime    time.Duration
	KeepaliveTimeout time.Duration
	ReleaseID        string
}

func NewHTTPConfig

func NewHTTPConfig(cfg *config.Config) Config

type CustomServer

type CustomServer interface {
	GetServerName() string
	StartServer(r *mux.Router) error
}

type CustomServerList

type CustomServerList struct {
	dig.In

	CustomServers []CustomServer `group:"custom_http_servers"`
}

type Option

type Option func(*health)

Option adds optional parameter for the HealthcheckHandlerFunc

func WithChecker

func WithChecker(name string, s Checker) Option

WithChecker adds a status checker that needs to be added as part of healthcheck. i.e database, cache or any external dependency

func WithObserver

func WithObserver(name string, s Checker) Option

WithObserver adds a status checker but it does not fail the entire status.

func WithReleaseID

func WithReleaseID(releaseID string) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout configures the global timeout for all individual checkers.

type Server

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

func NewHTTP

func NewHTTP(config Config, logger *zap.Logger, customServerList CustomServerList) (*Server, error)

func (*Server) Start

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

func (*Server) Stop

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

Jump to

Keyboard shortcuts

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