Documentation
¶
Index ¶
- func CORSAllowAll(c *gin.Context)
- func CloudflareIPCountry(c *gin.Context) (string, bool)
- func CloudflareOriginIP(c *gin.Context) string
- func GetBoolParam(c *gin.Context, key string, defaultVal bool) (bool, error)
- func GetBoolQuery(c *gin.Context, key string, defaultVal bool) (bool, error)
- func GetInt32Param(c *gin.Context, key string, maxVal, defaultVal int32) (int32, error)
- func GetInt32Query(c *gin.Context, key string, maxVal, defaultVal int32) (int32, error)
- func GetInt64Param(c *gin.Context, key string, maxVal, defaultVal int64) (int64, error)
- func GetInt64Query(c *gin.Context, key string, maxVal, defaultVal int64) (int64, error)
- func GetIntParam(c *gin.Context, key string, maxVal, defaultVal int) (int, error)
- func GetIntQuery(c *gin.Context, key string, maxVal, defaultVal int) (int, error)
- func GetPagenation(c *gin.Context, maxPageSize, defaultPageSize int64) (int64, int64, error)
- func GetUUIDParam(c *gin.Context, key string) (uuid.UUID, error)
- func GetUint32Param(c *gin.Context, key string, maxVal, defaultVal uint32) (uint32, error)
- func GetUint32Query(c *gin.Context, key string, maxVal, defaultVal uint32) (uint32, error)
- func GetUint64Param(c *gin.Context, key string, maxVal, defaultVal uint64) (uint64, error)
- func GetUint64Query(c *gin.Context, key string, maxVal, defaultVal uint64) (uint64, error)
- func GetUintParam(c *gin.Context, key string, maxVal, defaultVal uint) (uint, error)
- func GetUintQuery(c *gin.Context, key string, maxVal, defaultVal uint) (uint, error)
- func ListenWithGracefulShutdown(ctx context.Context, log logrus.Ext1FieldLogger, router *gin.Engine, ...) error
- type Config
- type HealthCheck
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORSAllowAll ¶
CORSAllowAll sets up the CORS headers to allow all origins, methods and headers.
func CloudflareIPCountry ¶ added in v1.0.1
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
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
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
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
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
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 ¶
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 ¶
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
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
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 ¶
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 ¶
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
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
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
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
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
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
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 ¶
type HealthCheck ¶
func NewHealthCheck ¶
func NewHealthCheck() *HealthCheck
func (*HealthCheck) Health ¶
func (h *HealthCheck) Health(c *gin.Context)
func (*HealthCheck) SetUnhealthy ¶
func (h *HealthCheck) SetUnhealthy()