core

package
v0.0.0-...-72e33f6 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActorTypeSystem = "system"
	ActorTypeUser   = "user"
	ActorTypePublic = "public"
)

Variables

View Source
var (
	ErrNotFound  = fmt.Errorf("not found")
	ErrForbidden = fmt.Errorf("forbidden")
)
View Source
var ErrLockResourceLocked = fmt.Errorf("resource locked")
View Source
var Locations []string = []string{} /* 598 elements not displayed */
View Source
var RuntimeToken string

RuntimeToken is a token that is generated at runtime to authenticate the application with itself.

Functions

func Address

func Address(host string, port int) string

func ErrorToNullString

func ErrorToNullString(err error) sql.NullString

func First

func First(s ...string) string

func FlagChannel

func FlagChannel(c chan<- struct{})

func IgnoreError

func IgnoreError[T any](data T, err error) T

func Int64ToNullInt64

func Int64ToNullInt64(i int64) sql.NullInt64

func IsFieldErrors

func IsFieldErrors(err error) bool

func IsForbidden

func IsForbidden(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func NewNullInt64

func NewNullInt64(i int64) sql.NullInt64

func NewNullString

func NewNullString(s string) sql.NullString

func NewTimeRange

func NewTimeRange(start, end time.Time) (models.TimeRange, error)

func SplitAddress

func SplitAddress(address string) (host string, port string)

func StringToNullString

func StringToNullString(s string) sql.NullString

func ValidateStruct

func ValidateStruct(ctx context.Context, s any) error

func ValidateStructPartial

func ValidateStructPartial(ctx context.Context, s any, fields ...string) error

func WithPublicActor

func WithPublicActor(ctx context.Context) context.Context

WithPublicActor sets actor to public.

func WithSystemActor

func WithSystemActor(ctx context.Context) context.Context

WithSystemActor sets actor to system.

func WithUserActor

func WithUserActor(ctx context.Context, userID int64, admin bool) context.Context

WithUserActor sets actor to user.

Types

type Actor

type Actor struct {
	Type   ActorType
	UserID int64
	Admin  bool
}

func AssertAdmin

func AssertAdmin(ctx context.Context) (Actor, error)

func AssertAdminOrUser

func AssertAdminOrUser(ctx context.Context, userID int64) (Actor, error)

func UseActor

func UseActor(ctx context.Context) Actor

type ActorType

type ActorType string

type FieldError

type FieldError struct {
	Field string
	// contains filtered or unexported fields
}

func NewFieldError

func NewFieldError(field, message string) FieldError

func ToFieldError

func ToFieldError(field, err validator.FieldError) FieldError

func (FieldError) Error

func (e FieldError) Error() string

func (FieldError) Message

func (e FieldError) Message() string

type FieldErrors

type FieldErrors []FieldError

func AsFieldErrors

func AsFieldErrors(err error) (FieldErrors, bool)

func (FieldErrors) Error

func (e FieldErrors) Error() string

type LockStore

type LockStore[T comparable] struct {
	// contains filtered or unexported fields
}

LockStore handles concurrent resource locking.

func NewLockStore

func NewLockStore[T comparable]() *LockStore[T]

func (*LockStore[T]) GetLock

func (s *LockStore[T]) GetLock(slug T) bool

func (*LockStore[T]) ListLock

func (s *LockStore[T]) ListLock(slugs ...T) []bool

func (*LockStore[T]) ListSlug

func (s *LockStore[T]) ListSlug() []T

func (*LockStore[T]) Lock

func (s *LockStore[T]) Lock(ctx context.Context, slug T) (LockUnlockFunc, error)

Lock blocks until it is able to lock the resource.

func (*LockStore[T]) TryLock

func (s *LockStore[T]) TryLock(slug T) (LockUnlockFunc, error)

TryLock tries to lock the resource if it is available.

type LockUnlockFunc

type LockUnlockFunc = func()

type MultiReadCloser

type MultiReadCloser struct {
	io.Reader
	Closers []func() error
}

func (MultiReadCloser) Close

func (c MultiReadCloser) Close() error

Jump to

Keyboard shortcuts

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