server

package module
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSAllowAll

func CORSAllowAll(c *gin.Context)

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

func CloudflareIPCountry added in v1.0.1

func CloudflareIPCountry(c *gin.Context) (string, bool)

CloudflareIPCountry gets the country code from the Cloudflare header "CF-IPCountry", or returns "", false if the header is not set. The country code is a two-letter ISO 3166-1 alpha-2 code.

func CloudflareOriginIP added in v1.0.1

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 GetBoolParam added in v1.2.0

func GetBoolParam(c *gin.Context, key string, defaultVal bool) (bool, error)

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

func GetBoolQuery added in v1.2.0

func GetBoolQuery(c *gin.Context, key string, defaultVal bool) (bool, error)

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

func GetInt32Param added in v1.3.0

func GetInt32Param(c *gin.Context, key string, maxVal, defaultVal int32) (int32, error)

GetInt32Param gets the int parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of -1 means no max.

func GetInt32Query added in v1.3.0

func GetInt32Query(c *gin.Context, key string, maxVal, defaultVal int32) (int32, error)

GetInt32Query gets the int query parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of -1 means no max.

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 GetIntParam added in v1.3.0

func GetIntParam(c *gin.Context, key string, maxVal, defaultVal int) (int, error)

GetIntParam gets the int parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of -1 means no max.

func GetIntQuery added in v1.3.0

func GetIntQuery(c *gin.Context, key string, maxVal, defaultVal int) (int, error)

GetIntQuery gets the int query parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of -1 means no max.

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 GetUint32Param added in v1.3.0

func GetUint32Param(c *gin.Context, key string, maxVal, defaultVal uint32) (uint32, error)

GetUint32Param gets the int parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of 0 means no max.

func GetUint32Query added in v1.3.0

func GetUint32Query(c *gin.Context, key string, maxVal, defaultVal uint32) (uint32, error)

GetInt32Query gets the int query parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of 0 means no max.

func GetUint64Param added in v1.2.0

func GetUint64Param(c *gin.Context, key string, maxVal, defaultVal uint64) (uint64, error)

GetUint64Param gets the uint64 parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of 0 means no max.

func GetUint64Query added in v1.2.0

func GetUint64Query(c *gin.Context, key string, maxVal, defaultVal uint64) (uint64, error)

GetUint64Query gets the uint64 query parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of 0 means no max.

func GetUintParam added in v1.3.0

func GetUintParam(c *gin.Context, key string, maxVal, defaultVal uint) (uint, error)

GetIntParam gets the int parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of 0 means no max.

func GetUintQuery added in v1.3.0

func GetUintQuery(c *gin.Context, key string, maxVal, defaultVal uint) (uint, error)

GetIntQuery gets the int query parameter from the gin context, and returns the value or the default value if the parameter is not set. maxVal of 0 means no max.

func ListenWithGracefulShutdown

func ListenWithGracefulShutdown(ctx context.Context, log logrus.Ext1FieldLogger, router *gin.Engine, conf Config) 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. This allows for graceful shutdown of the server in a Kubernetes environment, where the health check is used to determine if the server is ready to accept traffic.

Types

type Config

type Config 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() (Config, error)

type HealthCheck

type HealthCheck struct {
	IsUnhealthy *atomic.Bool
}

func NewHealthCheck

func NewHealthCheck() *HealthCheck

func (*HealthCheck) Health

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

func (*HealthCheck) SetUnhealthy

func (h *HealthCheck) SetUnhealthy()

Jump to

Keyboard shortcuts

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