ginx

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Overview

Package ginx provides shared functions used with gin to help reduce code duplication using an opinionated gin server setup.

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultServerShutdownTimeout sets the default for how long we give the sever
	// to shutdown before forcefully stopping the server.
	DefaultServerShutdownTimeout = 5 * time.Second
)

Functions

func DefaultEngine

func DefaultEngine(lgr *zap.Logger, f LogFunc) *gin.Engine

DefaultEngine returns a base gin engine for processing requests. This setups logging, requestid, and otel middleware.

func MustViperFlags

func MustViperFlags(v *viper.Viper, flags *pflag.FlagSet, defaultListen string)

MustViperFlags returns the cobra flags and wires them up with viper to prevent code duplication

Types

type CheckFunc

type CheckFunc func(ctx context.Context) error

CheckFunc is a function that can be used to check the status of a service.

type Config

type Config struct {
	Listen string `mapstructure:"listen"`
}

Config is used to configure a new ginx server

type LogFunc

type LogFunc func(c *gin.Context) []zapcore.Field

LogFunc is a function that can be used to add additional fields to the log output.

type Server

type Server struct {
	DB    *sqlx.DB
	Debug bool
	// contains filtered or unexported fields
}

Server implements the HTTP Server

func NewServer

func NewServer(lgr *zap.Logger, cfg Config, version *versionx.Details) Server

NewServer will return an opinionated gin server for processing API requests.

func (Server) AddHandler

func (s Server) AddHandler(h handler) Server

AddHandler provides the ability to add additional HTTP handlers that process requests. The handler that is provided should have a Routes(*gin.RouterGroup) function, which allows the routes to be added to the server.

func (Server) AddReadinessCheck

func (s Server) AddReadinessCheck(name string, f CheckFunc) Server

AddReadinessCheck will accept a function to be ran during calls to /readyx. These functions should accept a context and only return an error. When adding a readiness check a name is also provided, this name will be used when returning the state of all the checks

func (Server) Run

func (s Server) Run()

Run will start the server listening on the specified address and listens for os signals to shutdown the server

Jump to

Keyboard shortcuts

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