std

package
v0.0.0-...-814ee21 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version string

can be set from outside within go build command -ldflags="-X github.com/fratschi/go-microservice/internal/std.Version=${SERVICE_VERSION}"

Functions

func Cors

func Cors(c CorsConfig) *cors.Cors

func HandleVersionV1

func HandleVersionV1(router chi.Router)

func JsonLogRecoverer

func JsonLogRecoverer(next http.Handler) http.Handler

JsonLogRecoverer logs the panic (and a backtrace) as json and returns an HTTP 500 (Internal Server Error) status if possible.

func WaitForTermination

func WaitForTermination()

WaitForTermination waits for the TERM or INT signal to stop the services.

func WaitForTerminationCallback

func WaitForTerminationCallback(callback func(signal string))

WaitForTerminationCallback waits for the TERM or INT signal to stop the services. If signal is received, the callback is executed

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, status int, err error)

func WriteErrorResponseLog

func WriteErrorResponseLog(w http.ResponseWriter, status int, msg string, err error)

func WriteMessageResponse

func WriteMessageResponse(w http.ResponseWriter, status int, msg string)

func WriteMessageResponseLog

func WriteMessageResponseLog(w http.ResponseWriter, status int, msg string)

Types

type ConfigLoader

type ConfigLoader interface {
	LoadConfig(cfg interface{}) error
	LoadConfigData([]byte, interface{}) error
	Paths(p ...string) ConfigLoader
	File(f string) ConfigLoader
}

func NewConfigLoader

func NewConfigLoader() ConfigLoader

type ConfigLoaderImpl

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

func (ConfigLoaderImpl) File

func (ConfigLoaderImpl) LoadConfig

func (c ConfigLoaderImpl) LoadConfig(cfg interface{}) error

func (ConfigLoaderImpl) LoadConfigData

func (c ConfigLoaderImpl) LoadConfigData(data []byte, cfg interface{}) error

func (ConfigLoaderImpl) Paths

func (c ConfigLoaderImpl) Paths(p ...string) ConfigLoader

type CorsConfig

type CorsConfig struct {
	AllowedOrigins []string `yaml:"allowedOrigins"`
	AllowedHeaders []string `yaml:"allowedHeaders"`
	AllowedMethods []string `yaml:"allowedMethods"`
	ExposedHeaders []string `yaml:"exposedHeaders"`
	MaxAge         int      `yaml:"maxAge"`
}

type ErrorResponse

type ErrorResponse struct {
	// Code is a short, machine-readable identifier that indicates the type of error that occurred.
	Code string `json:"code"`
	// Message provides more human-readable information about what went wrong.
	Message string `json:"message"`
}

ErrorResponse is a Go structure that encapsulates error information for the rest interfaces.

func (ErrorResponse) Bytes

func (e ErrorResponse) Bytes() []byte

Bytes returns the json information of the error as bytes

type Probe

type Probe func() (string, bool)

type ProbeService

type ProbeService struct {
	Start []Probe
	Live  []Probe
	Ready []Probe
}

func NewProbeService

func NewProbeService() *ProbeService

NewProbeService creates a new probe services.

func (*ProbeService) AddLive

func (p *ProbeService) AddLive(probe Probe)

AddLive adds a liveness probe to the list of executed probes when the endpoint /live is called

func (*ProbeService) AddReady

func (p *ProbeService) AddReady(probe Probe)

AddReady adds a readiness probe to the list of executed probes when the endpoint /ready is called

func (*ProbeService) AddStart

func (p *ProbeService) AddStart(probe Probe)

AddStart adds a start probe to the list of executed probes when the endpoint /start is called

func (*ProbeService) HandleProbes

func (p *ProbeService) HandleProbes(router chi.Router)

HandleProbes configures the router for the three probes endpoints.

Jump to

Keyboard shortcuts

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