utils

package
v1.6.18 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

From https://github.com/livekit/livekit/blob/master/pkg/sfu/streamallocator/trenddetector.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayIn

func ArrayIn[T comparable](val T, array []T) (exists bool, index int)

func Color

func Color(str string) string

func Colorf

func Colorf(format string, a ...any) string

func CreateJPGImage

func CreateJPGImage(img *image.RGBA, quality int) ([]byte, error)

func CreatePNGImage

func CreatePNGImage(img *image.RGBA) ([]byte, error)

func CreatePNGImageURI

func CreatePNGImageURI(img *image.RGBA) (string, error)

func GenerateUID

func GenerateUID(alphabet string, size int) (string, error)

GenerateUID is a low-level function to change alphabet and ID size.

func HttpJsonRequest

func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res any) error

func HttpJsonResponse

func HttpJsonResponse(w http.ResponseWriter, code int, res any)

func HttpRequestGET

func HttpRequestGET(url string) (string, error)

func HttpSuccess

func HttpSuccess(w http.ResponseWriter, res ...any) error

func JsonStringAutoDecode

func JsonStringAutoDecode(m any) func(rf reflect.Kind, rt reflect.Kind, data any) (any, error)

func NewUID

func NewUID(param ...int) (string, error)

NewUID generates secure URL-friendly unique ID.

func Unmarshal

func Unmarshal(in any, raw []byte, callback func() error) error

func Unzip

func Unzip(zipPath, target string) error

func Zip

func Zip(source, zipPath string) error

Types

type Generator

type Generator func([]byte) (int, error)

Generator function

var BytesGenerator Generator = rand.Read

BytesGenerator is the default bytes generator

type HTTPError

type HTTPError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`

	InternalErr error  `json:"-"`
	InternalMsg string `json:"-"`
}

HTTPError is an error with a message and an HTTP status code.

func HttpBadRequest

func HttpBadRequest(res ...string) *HTTPError

func HttpError

func HttpError(code int, res ...string) *HTTPError

func HttpForbidden

func HttpForbidden(res ...string) *HTTPError

func HttpInternalServerError

func HttpInternalServerError(res ...string) *HTTPError

func HttpNotFound

func HttpNotFound(res ...string) *HTTPError

func HttpUnauthorized

func HttpUnauthorized(res ...string) *HTTPError

func HttpUnprocessableEntity

func HttpUnprocessableEntity(res ...string) *HTTPError

func (*HTTPError) Cause

func (e *HTTPError) Cause() error

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) Msg

func (e *HTTPError) Msg(str string) *HTTPError

Sends error with custom message

func (*HTTPError) Msgf

func (e *HTTPError) Msgf(fmtSt string, args ...any) *HTTPError

Sends error with custom formated message

func (*HTTPError) WithInternalErr

func (e *HTTPError) WithInternalErr(err error) *HTTPError

WithInternalErr adds internal error information to the error

func (*HTTPError) WithInternalMsg

func (e *HTTPError) WithInternalMsg(msg string) *HTTPError

WithInternalMsg adds internal message information to the error

func (*HTTPError) WithInternalMsgf

func (e *HTTPError) WithInternalMsgf(fmtStr string, args ...any) *HTTPError

WithInternalMsg adds internal formated message information to the error

type TrendDetector added in v1.6.12

type TrendDetector struct {
	// contains filtered or unexported fields
}

func NewTrendDetector added in v1.6.12

func NewTrendDetector(params TrendDetectorParams) *TrendDetector

func (*TrendDetector) AddValue added in v1.6.12

func (t *TrendDetector) AddValue(value int64)

func (*TrendDetector) GetDirection added in v1.6.12

func (t *TrendDetector) GetDirection() TrendDirection

func (*TrendDetector) GetHighest added in v1.6.12

func (t *TrendDetector) GetHighest() int64

func (*TrendDetector) GetLowest added in v1.6.12

func (t *TrendDetector) GetLowest() int64

func (*TrendDetector) GetValues added in v1.6.12

func (t *TrendDetector) GetValues() []int64

func (*TrendDetector) Seed added in v1.6.12

func (t *TrendDetector) Seed(value int64)

func (*TrendDetector) ToString added in v1.6.12

func (t *TrendDetector) ToString() string

type TrendDetectorParams added in v1.6.12

type TrendDetectorParams struct {
	RequiredSamples        int
	DownwardTrendThreshold float64
	CollapseValues         bool
}

type TrendDirection added in v1.6.12

type TrendDirection int
const (
	TrendDirectionNeutral TrendDirection = iota
	TrendDirectionUpward
	TrendDirectionDownward
)

func (TrendDirection) String added in v1.6.12

func (t TrendDirection) String() string

Jump to

Keyboard shortcuts

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