Documentation
¶
Index ¶
- func CORSAllowAll(c *gin.Context)
- func CloudflareIPCountry(c *gin.Context) (string, bool)
- func CloudflareOriginIP(c *gin.Context) string
- 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 GetPagenation(c *gin.Context, maxPageSize, defaultPageSize int64) (int64, int64, error)
- func GetUUIDParam(c *gin.Context, key string) (uuid.UUID, 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 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 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 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()