Documentation ¶
Index ¶
- Variables
- func CORSMiddleware() gin.HandlerFunc
- func GetRandomName(retry int) string
- func Paginate(c *gin.Context, db *gorm.DB, model interface{}) *gorm.DB
- func Render(obj interface{}, status int, c *gin.Context)
- func RenderError(message string, status int, c *gin.Context)
- func RequireParams(requiredParams []string, c *gin.Context) error
- func ResolvePublicIP() (*string, error)
- func RunAPIUsageDaemon(bufferSize int, flushIntervalMillis uint, delegate UsageDelegate) error
- func StringOrNil(str string) *string
- func TrackAPICall(c *gin.Context, subject string) error
- type APICall
- type UsageDelegate
Constants ¶
This section is empty.
Variables ¶
var ( // Log is the configured logger Log *logger.Logger )
Functions ¶
func CORSMiddleware ¶
func CORSMiddleware() gin.HandlerFunc
CORSMiddleware is a working middlware for using CORS with gin
func GetRandomName ¶
GetRandomName generates a random name from the list of adjectives and surnames in this package formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`
func Paginate ¶
Paginate the current request given the page number and results per page; returns the modified SQL query and adds x-total-results-count header to the response
func RenderError ¶
RenderError writes an error message and status using the given gin context
func RequireParams ¶
RequireParams renders an error if any of the given parameters are not present in the given gin context
func ResolvePublicIP ¶
ResolvePublicIP resolves the public IP of the caller
func RunAPIUsageDaemon ¶
func RunAPIUsageDaemon(bufferSize int, flushIntervalMillis uint, delegate UsageDelegate) error
RunAPIUsageDaemon initializes and starts a new API usage daemon using the given delegate; returns an error if there is already an API usage daemon running as it is currently treated as a singleton
func StringOrNil ¶
StringOrNil returns a pointer to the string, or nil if the given string is empty
Types ¶
type APICall ¶
type APICall struct { Sub string `json:"sub"` Method string `json:"method"` Host string `json:"host"` Path string `json:"path"` RemoteAddr string `json:"remote_addr"` StatusCode int `json:"status_code"` ContentLength *uint `json:"content_length"` Timestamp time.Time `json:"timestamp"` }
APICall struct
type UsageDelegate ¶
type UsageDelegate interface {
Track(*APICall)
}
UsageDelegate interface for API call tracking interface