internal

package
v0.0.0-...-57178c3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: ISC Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const SystemAccount = "bwXbluwC"

SystemAccount stores bluwhaze's internal system account ID

Variables

View Source
var (
	// GenerationDuration measures the runtime for playlist generation
	GenerationDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:    "generate_playlist_request_duration_seconds",
		Help:    "Histogram for the runtime of generating the playlist.",
		Buckets: []float64{0.1, 0.2, 0.4, 0.6, 1, 2, 5, 10},
	})

	// FeedbackRequest measures the feedback request latencies
	FeedbackRequest = prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:    "fb_req",
		Help:    "Histogram for the runtime of requesting feedback.",
		Buckets: []float64{0.1, 0.2, 0.4, 0.6, 1, 2, 5, 10},
	})

	// FeedbackInstrumentPreference is a counter for feedback instrument preferences
	FeedbackInstrumentPreference = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "fb_inst_pref",
			Help: "A counter vec for feedback requested instrument preferences.",
		},
		[]string{"inst"},
	)

	// FeedbackRequestSize is a counter feedback files sent
	FeedbackRequestSize = prometheus.NewCounter(
		prometheus.CounterOpts{
			Name: "fb_size",
			Help: "A counter for feedback files sent.",
		},
	)

	// FeedbackGenrePreference is a counter for feedback genre preferences
	FeedbackGenrePreference = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "fb_genr_pref",
			Help: "A counter vec for feedback requested genre preferences.",
		},
		[]string{"genr"},
	)

	// RequestGauge represents a gauge of reqeusts
	RequestGauge = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "in_flight_requests",
		Help: "A gauge of requests currently being served by the wrapped handler.",
	})

	// RequestCounter is a counter for wrapped requests
	RequestCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "api_requests_total",
			Help: "A counter for requests to the wrapped handler.",
		},
		[]string{"code", "method"},
	)

	// RequestDuration is a histogram of latencies
	RequestDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "request_duration_seconds",
			Help:    "A histogram of latencies for requests.",
			Buckets: []float64{0.05, 0.1, 0.2, 0.25, .5, 1, 2.5, 5, 10},
		},
		[]string{"method"},
	)

	// ResponseSize is a histogram of response sizes
	ResponseSize = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "response_size_bytes",
			Help:    "A histogram of response sizes for requests.",
			Buckets: []float64{200, 500, 1000, 25000, 50000, 1000000, 5000000},
		},
		[]string{},
	)
)

TODO: not all of these need to be globals

View Source
var ConfigFile string

ConfigFile points to the config file

View Source
var Data *config

Data contains the global configuration

View Source
var Db *gorm.DB

Db contains the global database connection

View Source
var DebugMode bool

DebugMode sets the database debug mode

View Source
var Exists = struct{}{}

Exists allows you to mark the existence inside the set

View Source
var Localizer *i18n.Localizer

Localizer is an i18n localizer

View Source
var Log *log.Logger

Log provides global logging

View Source
var LogFile string

LogFile points to the log file

View Source
var Token tokenSecrets

Token contains the JWT secrets

Functions

func Decode

func Decode(r io.ReadCloser, v interface{}) error

Decode tries to decode the interface as json

func Encode

func Encode(w http.ResponseWriter, v interface{}, status int)

Encode writes the encoded value

func FileSize

func FileSize(recID string, opener string) (int64, string)

FileSize returns a filesize for a feedback recording

func GetConf

func GetConf(c interface{}, path string) error

GetConf parses the specified yaml config file with provided struct

func Init

func Init(cfgPath string, name string)

Init initializes the log file

func InitMetrics

func InitMetrics()

InitMetrics registers the metrics variables

func LoadConfig

func LoadConfig(testConfig bool)

LoadConfig loads the secrets from the config file

func NewJSONError

func NewJSONError(c int, m string) error

NewJSONError returns a new JSONError

func SetupLocalizer

func SetupLocalizer()

SetupLocalizer sets up the i18n localizer

func Trace

func Trace(s string) (string, time.Time)

Trace starts a timer

func Un

func Un(s string, startTime time.Time)

Un stops the timer

func Write

func Write(w http.ResponseWriter, jse error)

Write writes the error to the http response

Types

type CacheConfig

type CacheConfig struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
}

CacheConfig contains the cache server settings

type DatabaseConfig

type DatabaseConfig struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	DbName   string `yaml:"dbname"`
	Password string `yaml:"password"`
}

DatabaseConfig contains the database connection information

type DbHTTPErr

type DbHTTPErr struct {
	Codename    string
	Description string
	HTTPStatus  int
}

DbHTTPErr contains a mapping of database errors with HTTP statuses

type EmailConfig

type EmailConfig struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

EmailConfig contains the email connection information

type ErrorInfo

type ErrorInfo struct {
	Code       string `json:"code"`
	HTTPStatus int    `json:"-"`
	Message    string `json:"message"`
}

ErrorInfo contains error information

type JSONError

type JSONError struct {
	Err ErrorInfo `json:"error"`
}

JSONError is a JSON error

func (*JSONError) Error

func (jse *JSONError) Error() string

Error implements the error interface for JSONError

type ServerConfig

type ServerConfig struct {
	AccountsURL            string `yaml:"accounts_url"`
	APIURL                 string `yaml:"api_url"`
	FeedbackRecordingsPath string `yaml:"feedback_recordings_path"`
	DeployMigrations       string `yaml:"deploy_migrations"`
}

ServerConfig contains general server configuration

type Set

type Set map[string]struct{}

Set is a "set"

func SetFromSlice

func SetFromSlice(slice []string) Set

SetFromSlice returns a set from a string slice

func SetIntersection

func SetIntersection(a Set, b Set) Set

SetIntersection returns the intersection of two sets

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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