helpers

package
v0.0.0-...-6cd009c Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const RateConfigName string = "rate_limit_config"
View Source
const RateConfigNameCacheKey string = "cached_rate_limit_config"

Variables

View Source
var Redis = &RedisDB{}

Functions

func BuildUrl

func BuildUrl(url string) string

func ContainsString

func ContainsString(arr *[]string, target *string) bool

func EnforceHTTP

func EnforceHTTP(url string) string

func GetUserIP

func GetUserIP(r *http.Request) string

func LowestUnixTime

func LowestUnixTime() int64

func NotValidShortString

func NotValidShortString(short *string) bool

func RateLimit

func RateLimit(r *http.Request, auth string, defaultLimit *URLLimit) (time.Duration, error)

func RedisSetup

func RedisSetup()

func RemoverDomainError

func RemoverDomainError(url string) bool

func SendJSONError

func SendJSONError(w http.ResponseWriter, statusCode int, errorMessage string)

func SetHeaders

func SetHeaders(type_ string, w http.ResponseWriter, status int)

func SetupTracker

func SetupTracker(dur time.Duration, maxEvents int, eventsLength int)

func SystemUnderMaintenance

func SystemUnderMaintenance(revalidate bool) bool

func TimeRemaining

func TimeRemaining(duration time.Duration) string

Types

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type RateConfig

type RateConfig struct {
	Name  string               `json:"name"`
	Limit map[string]*URLLimit `json:"limit"`
	ID    primitive.ObjectID   `json:"_id,omitempty"  bson:"_id,omitempty"`
}

func GetRateConfig

func GetRateConfig(revalidateCache bool) *RateConfig

type RateLimitLog

type RateLimitLog struct {
	Used     int           `json:"used"`
	Limit    int           `json:"limit"`
	CoolDown time.Duration `json:"cooldown"`
}

type RedisDB

type RedisDB struct {
	Client *redis.Client
}

func (RedisDB) GetJSON

func (r RedisDB) GetJSON(key string, dest interface{}) error

func (RedisDB) SetJSON

func (r RedisDB) SetJSON(key string, value interface{}, expiry time.Duration) error

type SystemConfig

type SystemConfig struct {
	Name        SystemConfigKey    `json:"name"`
	Maintenance bool               `json:"maintenance"`
	ID          primitive.ObjectID `json:"_id,omitempty"  bson:"_id,omitempty"`
}

func GetDefaultSystemConfig

func GetDefaultSystemConfig() *SystemConfig

func GetSystemConfig

func GetSystemConfig(revalidateCache bool) *SystemConfig

type SystemConfigKey

type SystemConfigKey string
const SystemConfigName SystemConfigKey = "system_limit_config"
const SystemConfigNameCacheKey SystemConfigKey = "cached_system_limit_config"

type TrackEventType

type TrackEventType string

type TrackerType

type TrackerType struct {
	// contains filtered or unexported fields
}
var Tracker *TrackerType

func (*TrackerType) CaptureRedirectEvent

func (eq *TrackerType) CaptureRedirectEvent(device string, ip string, os string, referrer string, urlId string, timestamp int64)

func (*TrackerType) StartFlush

func (eq *TrackerType) StartFlush()

type URLLimit

type URLLimit struct {
	Value  int `json:"value"`
	Expiry int `json:"expiry"`
}

Jump to

Keyboard shortcuts

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