utils

package
v0.0.0-...-2e28ec5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 20 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 Decode

func Decode(input interface{}, output interface{}) 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

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

func NewTrendDetector

func NewTrendDetector(params TrendDetectorParams) *TrendDetector

func (*TrendDetector) AddValue

func (t *TrendDetector) AddValue(value int64)

func (*TrendDetector) GetDirection

func (t *TrendDetector) GetDirection() TrendDirection

func (*TrendDetector) GetHighest

func (t *TrendDetector) GetHighest() int64

func (*TrendDetector) GetLowest

func (t *TrendDetector) GetLowest() int64

func (*TrendDetector) GetValues

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

func (*TrendDetector) Seed

func (t *TrendDetector) Seed(value int64)

func (*TrendDetector) ToString

func (t *TrendDetector) ToString() string

type TrendDetectorParams

type TrendDetectorParams struct {
	RequiredSamples        int
	DownwardTrendThreshold float64
	CollapseValues         bool
}

type TrendDirection

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

func (TrendDirection) String

func (t TrendDirection) String() string

Jump to

Keyboard shortcuts

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