server

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTagToRootScope

func AddTagToRootScope(c *gin.Context, tags map[string]string)

AddTagToRootScope adds tags to the root scope of the current request's Sentry hub.

func CORSAllowAll

func CORSAllowAll(c *gin.Context)

CORSAllowAll sets up the CORS headers to allow all origins, methods and headers.

func CloudflareOriginIP added in v1.2.0

func CloudflareOriginIP(c *gin.Context) string

CloudflareOriginIP gets the origin IP from the Cloudflare header, or falls back to the client IP if the header is not set.

func GetInt64Param

func GetInt64Param(c *gin.Context, key string, maxVal, defaultVal int64) (int64, error)

GetInt64Param gets the int64 parameter from the gin context, and returns the value or the default value if the parameter is not set.

func GetInt64Query

func GetInt64Query(c *gin.Context, key string, maxVal, defaultVal int64) (int64, error)

GetInt64Query gets the int64 query parameter from the gin context, and returns the value or the default value if the parameter is not set.

func GetPagenation

func GetPagenation(c *gin.Context, maxPageSize, defaultPageSize int64) (int64, int64, error)

GetPagenation takes the query parameters "page" and "pageSize" from the gin context, and returns the values or an error if the parameters are invalid. Defaults page to 0, and pageSize to defaultPageSize if not set. Returns page, pageSize, error

func GetUUIDParam

func GetUUIDParam(c *gin.Context, key string) (uuid.UUID, error)

GetUUIDParam gets the uuid parameter from the gin context Param call, and parses then returns the value or an error if the parameter is not set or invalid.

func ListenWithGracefulShutdown

func ListenWithGracefulShutdown(ctx context.Context, log logrus.Ext1FieldLogger, router *gin.Engine, conf ServerConfig) error

ListenWithGracefulShutdown listens on the given address with the given gin router, and will shutdown gracefully when a SIGINT or SIGTERM signal is received. Also setups up a health check endpoint on the given path, which will be unhealthy when the server is shutting down.

func SafeMetricsAdd

func SafeMetricsAdd(log logrus.Ext1FieldLogger, metric *ginmetrics.Metric, labelValues []string, value float64)

SafeMetricsAdd increased the given metric by value with the given label values, and logs an error if the increase fails. All parameters can safely be nil, if metric is nil, this function does nothing.

func SafeMetricsGauge

func SafeMetricsGauge(log logrus.Ext1FieldLogger, metric *ginmetrics.Metric, labelValues []string, value float64)

SafeMetricsGauge sets the given metric to the given value with the given label values, and logs an error if the set fails.

func SafeMetricsInc

func SafeMetricsInc(log logrus.Ext1FieldLogger, metric *ginmetrics.Metric, labelValues []string)

SafeMetricsInc increments the given metric with the given label values, and logs an error if the increment fails. All parameters can safely be nil, if metric is nil, this function does nothing.

func SetupMetrics

func SetupMetrics(otherRouter *gin.Engine, path, listen string, durations []float64) *ginmetrics.Monitor

SetupMetrics sets up a ginmetrics.Monitor with the given parameters, will expose the metrics on the given path and listen on the given address.

Types

type Database

type Database interface {
	PingContext(ctx context.Context) error
}

type EthClient

type EthClient interface {
	BlockNumber(ctx context.Context) (uint64, error)
}

type HealthCheck

type HealthCheck struct {
	IsUnhealthy *atomic.Bool
}

func NewHealthCheck

func NewHealthCheck() *HealthCheck

func (*HealthCheck) Health

func (h *HealthCheck) Health(c *gin.Context)

type ServerConfig

type ServerConfig struct {
	ReadTimeout     time.Duration `env:"READ_TIMEOUT" env-default:"5s"`
	ShutdownTimeout time.Duration `env:"SHUTDOWN_TIMEOUT" env-default:"15s"`
	Listen          string        `env:"LISTEN" env-default:":8080"`
	HealthCheckPath string        `env:"HEALTH_CHECK_PATH" env-default:"/health"`
}

func LoadServerConfigFromEnv

func LoadServerConfigFromEnv() (ServerConfig, error)

type StatusChecker

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

func NewStatusChecker

func NewStatusChecker(log logrus.Ext1FieldLogger) *StatusChecker

func (*StatusChecker) AddDatabase

func (sc *StatusChecker) AddDatabase(key string, db Database) error

func (*StatusChecker) AddEthClient

func (sc *StatusChecker) AddEthClient(key string, ec EthClient) error

func (*StatusChecker) AddFn

func (sc *StatusChecker) AddFn(key string, fn func(context.Context) error) error

func (*StatusChecker) Check

func (sc *StatusChecker) Check(c *gin.Context)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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