common

package
v0.0.0-...-09899ef Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func GetRandomName(retry int) string

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

func Paginate(c *gin.Context, db *gorm.DB, model interface{}) *gorm.DB

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 Render

func Render(obj interface{}, status int, c *gin.Context)

Render an object and status using the given gin context

func RenderError

func RenderError(message string, status int, c *gin.Context)

RenderError writes an error message and status using the given gin context

func RequireParams

func RequireParams(requiredParams []string, c *gin.Context) error

RequireParams renders an error if any of the given parameters are not present in the given gin context

func ResolvePublicIP

func ResolvePublicIP() (*string, error)

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

func StringOrNil(str string) *string

StringOrNil returns a pointer to the string, or nil if the given string is empty

func TrackAPICall

func TrackAPICall(c *gin.Context, subject string) error

TrackAPICall tracks the api call for the given subject and gin context

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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