core

package
v0.0.0-...-87d6203 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const EncryptionFormat = "AES-GCM-256"

Variables

View Source
var HasVideoExtension = func() func(filename string) bool {
	videoExtensions := map[string]bool{
		".3g2":  true,
		".3gp":  true,
		".amv":  true,
		".asf":  true,
		".avi":  true,
		".drc":  true,
		".f4a":  true,
		".f4b":  true,
		".f4p":  true,
		".f4v":  true,
		".flv":  true,
		".gif":  true,
		".gifv": true,
		".m2ts": true,
		".m2v":  true,
		".m4p":  true,
		".m4v":  true,
		".mk3d": true,
		".mkv":  true,
		".mng":  true,
		".mov":  true,
		".mp2":  true,
		".mp4":  true,
		".mpe":  true,
		".mpeg": true,
		".mpg":  true,
		".mpv":  true,
		".mxf":  true,
		".nsv":  true,
		".ogg":  true,
		".ogm":  true,
		".ogv":  true,
		".qt":   true,
		".rm":   true,
		".rmvb": true,
		".roq":  true,
		".svi":  true,
		".ts":   true,
		".webm": true,
		".wmv":  true,
		".yuv":  true,
	}

	return func(filename string) bool {
		_, found := videoExtensions[strings.ToLower(filepath.Ext(filename))]
		return found
	}
}()

Functions

func Base64Decode

func Base64Decode(value string) (string, error)

func Base64DecodeToByte

func Base64DecodeToByte(value string) ([]byte, error)

func Base64Encode

func Base64Encode(value string) string

func Base64EncodeByte

func Base64EncodeByte(value []byte) string

func CreateJWT

func CreateJWT[T interface{}](secret string, claims JWTClaims[T]) (string, error)

func Decrypt

func Decrypt(secret, value string) (string, error)

func Encrypt

func Encrypt(secret, value string) (string, error)

func LogError

func LogError(msg string, err error)

func PackError

func PackError(err error) error

func ParseJWT

func ParseJWT[T interface{}](secretFunc jwt.Keyfunc, encodedToken string, claims *JWTClaims[T], options ...jwt.ParserOption) (*jwt.Token, error)

func UnmarshalJSON

func UnmarshalJSON(statusCode int, body []byte, v interface{}) error

Types

type APIError

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

func NewAPIError

func NewAPIError(msg string) *APIError

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
	Token    string
}

func ParseBasicAuth

func ParseBasicAuth(token string) (BasicAuth, error)

type Error

type Error struct {
	Type ErrorType `json:"type"`

	Code ErrorCode `json:"code,omitempty"`
	Msg  string    `json:"message"`

	Method     string `json:"method,omitempty"`
	Path       string `json:"path,omitempty"`
	StatusCode int    `json:"status_code,omitempty"`

	StoreName     string `json:"store_name,omitempty"`
	UpstreamCause error  `json:"__upstream_cause__,omitempty"`

	Cause error `json:"__cause__,omitempty"`
}

func NewError

func NewError(msg string) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) GetError

func (e *Error) GetError() *Error

func (*Error) GetStatusCode

func (e *Error) GetStatusCode() int

func (*Error) InjectReq

func (e *Error) InjectReq(r *http.Request)

func (*Error) Pack

func (e *Error) Pack()

func (*Error) Send

func (e *Error) Send(w http.ResponseWriter)

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorCode

type ErrorCode string
const (
	ErrorCodeUnknown ErrorCode = "UNKNOWN"

	ErrorCodeBadGateway                  ErrorCode = "BAD_GATEWAY"
	ErrorCodeBadRequest                  ErrorCode = "BAD_REQUEST"
	ErrorCodeConflict                    ErrorCode = "CONFLICT"
	ErrorCodeForbidden                   ErrorCode = "FORBIDDEN"
	ErrorCodeGone                        ErrorCode = "GONE"
	ErrorCodeInternalServerError         ErrorCode = "INTERNAL_SERVER_ERROR"
	ErrorCodeMethodNotAllowed            ErrorCode = "METHOD_NOT_ALLOWED"
	ErrorCodeNotFound                    ErrorCode = "NOT_FOUND"
	ErrorCodeNotImplemented              ErrorCode = "NOT_IMPLEMENTED"
	ErrorCodePaymentRequired             ErrorCode = "PAYMENT_REQUIRED"
	ErrorCodeProxyAuthenticationRequired ErrorCode = "PROXY_AUTHENTICATION_REQUIRED"
	ErrorCodeServiceUnavailable          ErrorCode = "SERVICE_UNAVAILABLE"
	ErrorCodeTooManyRequests             ErrorCode = "TOO_MANY_REQUESTS"
	ErrorCodeUnauthorized                ErrorCode = "UNAUTHORIZED"
	ErrorCodeUnavailableForLegalReasons  ErrorCode = "UNAVAILABLE_FOR_LEGAL_REASONS"
	ErrorCodeUnprocessableEntity         ErrorCode = "UNPROCESSABLE_ENTITY"
	ErrorCodeUnsupportedMediaType        ErrorCode = "UNSUPPORTED_MEDIA_TYPE"

	ErrorCodeStoreLimitExceeded ErrorCode = "STORE_LIMIT_EXCEEDED"
	ErrorCodeStoreMagnetInvalid ErrorCode = "STORE_MAGNET_INVALID"
	ErrorCodeStoreNameInvalid   ErrorCode = "STORE_NAME_INVALID"
)

type ErrorType

type ErrorType string
const (
	ErrorTypeAPI      ErrorType = "api_error"
	ErrorTypeStore    ErrorType = "store_error"
	ErrorTypeUpstream ErrorType = "upstream_error"
	ErrorTypeUnknown  ErrorType = "unknown_error"
)

type JWTClaims

type JWTClaims[T interface{}] struct {
	jwt.RegisteredClaims
	Data *T `json:"data,omitempty"`
}
type MagnetLink struct {
	Hash     string // xt - exact topic
	Link     string
	Name     string   // dn - display name
	Trackers []string // tr - address tracker
}
func ParseMagnetLink(value string) (MagnetLink, error)

type StoreError

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

func NewStoreError

func NewStoreError(msg string) *StoreError

type StremThruError

type StremThruError interface {
	Pack()
	GetStatusCode() int
	GetError() *Error
	Send(w http.ResponseWriter)
}

type UpstreamError

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

func NewUpstreamError

func NewUpstreamError(msg string) *UpstreamError

Jump to

Keyboard shortcuts

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