fs

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 23 Imported by: 23

Documentation

Index

Constants

View Source
const TraceID = "trace_id"

Variables

View Source
var AllowedFileTypes = []string{
	"text/xml",
	"text/xml; charset=utf-8",
	"text/plain",
	"text/plain; charset=utf-8",

	"image/jpeg",
	"image/pjpeg",
	"image/png",
	"image/gif",
	"image/x-icon",
	"application/pdf",
	"application/msword",
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
	"application/powerpoint",
	"application/x-mspowerpoint",
	"application/vnd.openxmlformats-officedocument.presentationml.presentation",
	"application/mspowerpoint",
	"application/vnd.ms-powerpoint",
	"application/vnd.openxmlformats-officedocument.presentationml.slideshow",
	"application/vnd.oasis.opendocument.text",
	"application/excel",
	"application/vnd.ms-excel",
	"application/x-excel",
	"application/x-msexcel",
	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",

	"audio/mpeg3",
	"audio/x-mpeg-3",
	"video/x-mpeg",
	"audio/m4a",
	"audio/ogg",
	"audio/wav",
	"audio/x-wav",
	"video/mp4",
	"video/x-m4v",
	"video/quicktime",
	"video/x-ms-asf",
	"video/x-ms-wmv",
	"application/x-troff-msvideo",
	"video/avi",
	"video/msvideo",
	"video/x-msvideo",
	"audio/mpeg",
	"video/mpeg",
	"video/ogg",
	"video/3gpp",
	"audio/3gpp",
	"video/3gpp2",
	"audio/3gpp2",
}

AllowedFileTypes is a list of allowed file types

View Source
var (
	ContextKeyTraceID = ContextKey(TraceID)
)
View Source
var (
	// PermissionTypeToStrings is a map that contains the string representation of the enum values
	PermissionTypeToStrings = [...]string{
		PermissionTypeInvalid: "invalid",
		PermissionTypeAllow:   "allow",
		PermissionTypeDeny:    "deny",
	}
)
View Source
var RoleAdmin = &Role{
	ID:   1,
	Name: "Admin",
	Root: true,
}

RoleAdmin is the admin role

View Source
var RoleGuest = &Role{
	ID:   3,
	Name: "Guest",
	Root: false,
}

RoleGuest is the guest role

View Source
var RoleUser = &Role{
	ID:   2,
	Name: "User",
	Root: false,
}

RoleUser is the user role

View Source
var SystemSchemaTypes = []any{
	Role{},
	Permission{},
	User{},
	File{},
}

Functions

func AuthProviders added in v0.2.0

func AuthProviders() []string

AuthProviders returns a sorted list of the names of the registered auth providers.

func MapValue added in v0.6.0

func MapValue[V any](m Map, key string, defaultValues ...V) V

func PermissionTypeValues

func PermissionTypeValues() []string

PermissionTypeValues returns all possible values of the enum.

func RegisterAuthProviderMaker added in v0.2.0

func RegisterAuthProviderMaker(name string, fn AuthProviderMaker)

RegisterAuthProviderMaker makes an auth provider factory available by the provided name. If RegisterAuthProviderMaker is called twice with the same name or if auth provider factory is nil, it panics.

Types

type App

type App interface {
	Hookable
	Key() string
	Name() string
	Config() *Config
	SchemaBuilder() *schema.Builder
	SystemSchemas() []any
	DB() db.Client
	Resources() *ResourcesManager
	Reload(ctx context.Context, migration *db.Migration) (err error)
	Logger() logger.Logger
	UpdateCache(ctx context.Context) error
	Roles() []*Role
	Disk(names ...string) Disk
	Disks() []Disk
	GetAuthProvider(name string) AuthProvider

	Mailer(...string) Mailer
	Mailers() []Mailer

	AddResource(resource *Resource)
	AddMiddlewares(hooks ...Middleware)
}

App is the interface that defines the methods that an app must implement

type Arg

type Arg struct {
	Type        ArgType `json:"type"`
	Required    bool    `json:"required"`
	Description string  `json:"description"`
	Example     any     `json:"example"`
}

func CreateArg added in v0.6.0

func CreateArg(t ArgType, desc string) Arg

type ArgType

type ArgType int

ArgType define the data type of a field

const (
	TypeInvalid ArgType = iota
	TypeBool
	TypeTime
	TypeJSON
	TypeUUID
	TypeBytes
	TypeEnum
	TypeString
	TypeText
	TypeInt8
	TypeInt16
	TypeInt32
	TypeInt
	TypeInt64
	TypeUint8
	TypeUint16
	TypeUint32
	TypeUint
	TypeUint64
	TypeFloat32
	TypeFloat64
)

func (ArgType) Common

func (t ArgType) Common() string

Common returns the common type of a field

func (ArgType) MarshalJSON

func (t ArgType) MarshalJSON() ([]byte, error)

MarshalJSON marshal an enum value to the quoted json string value

func (ArgType) String

func (t ArgType) String() string

String returns the string representation of a type.

func (*ArgType) UnmarshalJSON

func (t *ArgType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

func (ArgType) Valid

func (t ArgType) Valid() bool

Valid reports if the given type if known type.

type Args

type Args map[string]Arg

func (Args) Clone

func (a Args) Clone() Args

type AuthConfig added in v0.2.0

type AuthConfig struct {
	EnabledProviders []string       `json:"enabled_providers"`
	Providers        map[string]Map `json:"providers"`
}

func (*AuthConfig) Clone added in v0.2.0

func (ac *AuthConfig) Clone() *AuthConfig

type AuthProvider added in v0.2.0

type AuthProvider interface {
	Name() string
	Login(Context) (any, error)
	Callback(Context) (*User, error)
	VerifyIDToken(Context, IDToken) (*User, error)
}

func CreateAuthProvider added in v0.2.0

func CreateAuthProvider(name string, config Map, redirectURL string) (AuthProvider, error)

CreateAuthProvider creates an auth provider by the provided name.

type AuthProviderMaker added in v0.2.0

type AuthProviderMaker func(Map, string) (AuthProvider, error)

type Config

type Config struct {
	Dir               string         `json:"dir"`
	AppName           string         `json:"app_name"`
	AppKey            string         `json:"app_key"`
	Port              string         `json:"port"`
	BaseURL           string         `json:"base_url"`
	DashURL           string         `json:"dash_url"`
	APIBaseName       string         `json:"api_base_name"`
	DashBaseName      string         `json:"dash_base_name"`
	Logger            logger.Logger  `json:"-"`
	LoggerConfig      *logger.Config `json:"logger_config"` // If Logger is set, LoggerConfig will be ignored
	DB                db.Client      `json:"-"`
	DBConfig          *db.Config     `json:"db_config"` // If DB is set, DBConfig will be ignored
	StorageConfig     *StorageConfig `json:"storage_config"`
	AuthConfig        *AuthConfig    `json:"auth_config"`
	MailConfig        *MailConfig    `json:"mail_config"`
	SystemSchemas     []any          `json:"-"` // types to build the system schemas
	Hooks             *Hooks         `json:"-"`
	HideResourcesInfo bool           `json:"hide_resources_info"`
}

func (*Config) Clone

func (ac *Config) Clone() *Config

type Context

type Context interface {
	context.Context
	TraceID() string
	User() *User
	Local(string, ...any) (val any)
	Logger() logger.Logger
	Bind(any) error
	SetArg(string, string) string
	Args() map[string]string
	Arg(name string, defaults ...string) string
	ArgInt(name string, defaults ...int) int
	Body() ([]byte, error)
	Payload() (*entity.Entity, error)
	BodyParser(out any) error
	FormValue(key string, defaultValue ...string) string
	Resource() *Resource
	AuthToken() string
	Next() error
	Result(...*Result) *Result
	Files() ([]*File, error)
	Redirect(string) error
	WSClient() WSClient
	IP() string
}

Context is the interface that defines the methods that a context must implement

type ContextKey added in v0.5.0

type ContextKey string

func (ContextKey) String added in v0.5.0

func (c ContextKey) String() string

type Disk

type Disk interface {
	Name() string
	Root() string
	URL(filepath string) string
	Delete(c context.Context, filepath string) error
	Put(c context.Context, file *File) (*File, error)
	PutReader(c context.Context, in io.Reader, size uint64, mime, dst string) (*File, error)
	PutMultipart(c context.Context, m *multipart.FileHeader, dsts ...string) (*File, error)
	LocalPublicPath() string
}

Disk is the interface that defines the methods that a disk must implement

type DiskBase added in v0.4.0

type DiskBase struct {
	DiskName string `json:"name"`
	Root     string
}

DiskBase is designed to be embedded in other disk-related structs that implement the fs.Disk interface. It provides a common set of functionalities for handling files, such as MIME type checking and generating upload paths.

Fields:

  • DiskName: A unique identifier for the disk, typically assigned from config.Name.
  • Root: The root directory path where files managed by this disk are stored, typically assigned from config.Root.

Methods:

  • Name(): Returns the DiskName of the disk. This can be used to retrieve the identifier of the disk.
  • IsAllowedMime(mime string): Checks if the provided MIME type is allowed for upload based on a predefined list of allowed file types. Returns true if the MIME type is allowed, false otherwise.
  • UploadFilePath(filename string): Generates a path for uploading a file based on the current time and the provided filename. The path includes the year and month as directories, followed by a timestamp and the sanitized filename.

Usage: DiskBase is intended to be used as a foundational component for managing file storage. It can be embedded in other structs to provide them with basic file handling capabilities. The GetURL function should be implemented to suit the specific needs of the application, allowing for flexible URL generation strategies.

Example:

type CustomDisk struct {
    fs.DiskBase
    // Additional fields and methods specific to CustomDisk
}

func (*DiskBase) IsAllowedMime added in v0.4.0

func (r *DiskBase) IsAllowedMime(mime string) bool

func (*DiskBase) Name added in v0.4.0

func (r *DiskBase) Name() string

func (*DiskBase) UploadFilePath added in v0.4.0

func (r *DiskBase) UploadFilePath(filename string) string

type DiskConfig

type DiskConfig struct {
	Name            string        `json:"name"`
	Driver          string        `json:"driver"`
	Root            string        `json:"root"`
	BaseURL         string        `json:"base_url"`
	PublicPath      string        `json:"public_path"`
	GetBaseURL      func() string `json:"-"`
	Provider        string        `json:"provider"`
	Endpoint        string        `json:"endpoint"`
	Region          string        `json:"region"`
	Bucket          string        `json:"bucket"`
	AccessKeyID     string        `json:"access_key_id"`
	SecretAccessKey string        `json:"secret_access_key"`
	ACL             string        `json:"acl"`
}

DiskConfig holds the disk configuration

func (*DiskConfig) Clone

func (dc *DiskConfig) Clone() *DiskConfig

Clone returns a clone of the disk configuration

type File

type File struct {
	ID        uint64     `json:"id,omitempty"`
	Disk      string     `json:"disk,omitempty"`
	Name      string     `json:"name,omitempty"`
	Path      string     `json:"path,omitempty"`
	Type      string     `json:"type,omitempty"`
	Size      uint64     `json:"size,omitempty"`
	UserID    uint64     `json:"user_id,omitempty"`
	User      *User      `` /* 137-byte string literal not displayed */
	URL       string     `json:"url,omitempty" fs:"-"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	Reader    io.Reader  `json:"-"`
	// contains filtered or unexported fields
}

File holds the file data

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Body       []byte
	Header     http.Header
	File       string
	Stream     *bytes.Buffer
}

type Handler

type Handler func(c Context) (any, error)

Handler is a function that resolves a request

type HandlerFn

type HandlerFn[Input, Output any] func(c Context, input Input) (Output, error)

HandlerFn is a function that generates a resolver function

type Hookable added in v0.5.0

type Hookable interface {
	Hooks() *Hooks

	OnPreResolve(hooks ...Middleware)
	OnPostResolve(hooks ...Middleware)

	OnPreDBQuery(hooks ...db.PreDBQuery)
	OnPostDBQuery(hooks ...db.PostDBQuery)

	OnPreDBExec(hooks ...db.PreDBExec)
	OnPostDBExec(hooks ...db.PostDBExec)

	OnPreDBCreate(hooks ...db.PreDBCreate)
	OnPostDBCreate(hooks ...db.PostDBCreate)

	OnPreDBUpdate(hooks ...db.PreDBUpdate)
	OnPostDBUpdate(hooks ...db.PostDBUpdate)

	OnPreDBDelete(hooks ...db.PreDBDelete)
	OnPostDBDelete(hooks ...db.PostDBDelete)
}

type Hooks

type Hooks struct {
	DBHooks     *db.Hooks
	PreResolve  []ResolveHook
	PostResolve []ResolveHook
}

Hooks is a struct that contains app hooks

func (*Hooks) Clone added in v0.5.0

func (h *Hooks) Clone() *Hooks

type IDToken added in v0.7.5

type IDToken struct {
	IDToken string `json:"id_token"`
}

type Mail added in v0.6.0

type Mail struct {
	Subject string
	Body    string
	To      []string
	CC      []string
	BCC     []string
}

type MailConfig added in v0.6.0

type MailConfig struct {
	SenderName        string `json:"sender_name"`
	SenderMail        string `json:"sender_mail"`
	DefaultClientName string `json:"default_client"`
	Clients           []Map  `json:"clients"`
}

func (*MailConfig) Clone added in v0.6.0

func (m *MailConfig) Clone() *MailConfig

type Mailer added in v0.6.0

type Mailer interface {
	Send(mail *Mail, froms ...mail.Address) error
	Name() string
	Driver() string
}

type Map

type Map = map[string]any

Map is a shortcut for map[string]any

type Meta

type Meta struct {
	// Http method empty means the method is not set/allowed
	Get     string `json:"get,omitempty"`     // Only use for restful method GET
	Head    string `json:"head,omitempty"`    // Only use for restful method HEAD
	Post    string `json:"post,omitempty"`    // Only use for restful method POST
	Put     string `json:"put,omitempty"`     // Only use for restful method PUT
	Delete  string `json:"delete,omitempty"`  // Only use for restful method DELETE
	Connect string `json:"connect,omitempty"` // Only use for restful method CONNECT
	Options string `json:"options,omitempty"` // Only use for restful method OPTIONS
	Trace   string `json:"trace,omitempty"`   // Only use for restful method TRACE
	Patch   string `json:"patch,omitempty"`   // Only use for restful method PATCH

	// WS
	WS string `json:"ws,omitempty"` // Only use for websocket

	Prefix     string     `json:"prefix,omitempty"` // Only use for group resource
	Args       Args       `json:"args,omitempty"`
	Public     bool       `json:"public,omitempty"`
	Signatures Signatures `json:"-"`
}

Meta hold extra data, ex: request method, path, etc

func (*Meta) Clone

func (m *Meta) Clone() *Meta

type Middleware

type Middleware func(c Context) error

Middleware is a function that can be used to add middleware to a resource

type Permission

type Permission struct {
	ID          int                              `json:"id,omitempty"`
	RoleID      uint64                           `json:"role_id,omitempty"`
	Resource    string                           `json:"resource,omitempty"`
	Value       string                           `json:"value,omitempty"`
	Modifier    string                           `json:"modifier,omitempty" fs:"type=json;optional"`
	Role        *Role                            `` /* 143-byte string literal not displayed */
	CreatedAt   *time.Time                       `json:"created_at,omitempty"`
	UpdatedAt   *time.Time                       `json:"updated_at,omitempty"`
	DeletedAt   *time.Time                       `json:"deleted_at,omitempty"`
	RuleProgram *expr.Program[*Permission, bool] `json:"-"` // The compiled rule program
	// contains filtered or unexported fields
}

Permission is a struct that contains the permission data

func (*Permission) Check added in v0.6.0

func (p *Permission) Check(c context.Context, config expr.Config) error

func (*Permission) Compile added in v0.6.0

func (p *Permission) Compile() (err error)

func (*Permission) IsAllowed added in v0.6.0

func (p *Permission) IsAllowed() bool

func (*Permission) IsDenied added in v0.6.0

func (p *Permission) IsDenied() bool

type PermissionType

type PermissionType uint

PermissionType is an enum that represents the type of a permission

const (
	PermissionTypeInvalid PermissionType = iota
	PermissionTypeAllow
	PermissionTypeDeny
)

func GetPermissionTypeFromName

func GetPermissionTypeFromName(name string) PermissionType

GetPermissionTypeFromName returns the type from a string.

func (PermissionType) MarshalJSON

func (p PermissionType) MarshalJSON() ([]byte, error)

MarshalJSON marshal an enum value to the quoted json string value

func (PermissionType) String

func (p PermissionType) String() string

String returns the string representation of a type.

func (*PermissionType) UnmarshalJSON

func (p *PermissionType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

func (PermissionType) Valid

func (p PermissionType) Valid() bool

Valid reports if the given type if known type.

type ResolveHook

type ResolveHook = Middleware

ResolveHook is a function that can be used to add hooks to a resource

type Resource

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

Resource is a resource that can be used to define a resource tree

func Connect

func Connect[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Connect is a shortcut to create a new resource with rest method CONNECT and using name as the connect path

func Delete

func Delete[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Delete is a shortcut to create a new resource with rest method DELETE and using name as the delete path

func Get

func Get[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Get is a shortcut to create a new resource with rest method GET and using name as the get path

func Head[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Head is a shortcut to create a new resource with rest method HEAD and using name as the head path

func NewResource

func NewResource[Input, Output any](
	name string,
	handler HandlerFn[Input, Output],
	metas ...*Meta,
) *Resource

NewResource creates a new resource with the given name, handler and meta

handler is a function that takes a context and an input and returns an output and an error
If the solver input type is not "any", the input will be parsed from the context

func Options

func Options[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Options is a shortcut to create a new resource with rest method OPTIONS and using name as the options path

func Patch

func Patch[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Patch is a shortcut to create a new resource with rest method PATCH and using name as the patch path

func Post

func Post[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Post is a shortcut to create a new resource with rest method POST and using name as the post path

func Put

func Put[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Put is a shortcut to create a new resource with rest method PUT and using name as the put path

func Trace

func Trace[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

Trace is a shortcut to create a new resource with rest method TRACE and using name as the trace path

func WS added in v0.3.0

func WS[Input, Output any](name string, handler HandlerFn[Input, Output], metas ...*Meta) *Resource

WS is a shortcut to create a new resource with rest method WS and using name as the ws path

func (*Resource) Add

func (r *Resource) Add(resources ...*Resource) (self *Resource)

Add adds a new resource to the current resource as a child and returns the current resource

func (*Resource) AddResource

func (r *Resource) AddResource(name string, handler Handler, metas ...*Meta) (self *Resource)

AddResource adds a new resource to the current resource as a child and returns the current resource extras can be used to pass additional information to the resource. Currently supported extras are:

  • *Meta: used to pass meta information to the resource, example: &Meta{"rest.POST": "/login"}
  • *Signature: used to pass input and output signatures to the resource, example: &Signature{Input: LoginData{}, Output: LoginResponse{}}

func (*Resource) Clone

func (r *Resource) Clone() *Resource

Clone clones the resource and all sub resources

func (*Resource) Find

func (r *Resource) Find(resourceID string) *Resource

Find returns the resource with the given id The id is in the format of "group1.group2.group3.resource" While group1, group2 and group3 are name of the groups and resource is the name of the resource

func (*Resource) Group

func (r *Resource) Group(name string, metas ...*Meta) (group *Resource)

Group creates a new resource group and adds it to the current resource as a child and returns the group resource

func (*Resource) Handler

func (r *Resource) Handler() Handler

Handler returns the resolver of the resource

func (*Resource) ID

func (r *Resource) ID() string

ID returns the id of the resource

func (*Resource) Init

func (r *Resource) Init() error

Init validates the resource and all sub resources

func (*Resource) IsGroup

func (r *Resource) IsGroup() bool

IsGroup returns true if the resource is a group

func (*Resource) IsPublic

func (r *Resource) IsPublic() bool

IsPublic returns true if the resource is white listed

func (*Resource) MarshalJSON

func (r *Resource) MarshalJSON() ([]byte, error)

MarshalJSON marshals the resource to json

func (*Resource) Meta

func (r *Resource) Meta() *Meta

Meta returns the meta of the resource

func (*Resource) Name

func (r *Resource) Name() string

Name returns the name of the resource

func (*Resource) Print

func (r *Resource) Print()

Print prints the resource and all sub resources

func (*Resource) Remove

func (r *Resource) Remove(name string) (self *Resource)

func (*Resource) Resources

func (r *Resource) Resources() []*Resource

Resources returns the sub resources of the resource

func (*Resource) Signature

func (r *Resource) Signature() Signatures

Signature returns the signature of the resource

func (*Resource) String

func (r *Resource) String() string

String returns a string representation of the resource

type ResourcesManager

type ResourcesManager struct {
	*Resource

	Middlewares []Middleware
	Hooks       func() *Hooks
}

ResourcesManager is a resource manager that can be used to manage resources

func NewResourcesManager

func NewResourcesManager() *ResourcesManager

NewResourcesManager creates a new resources manager

func (*ResourcesManager) Clone

func (rs *ResourcesManager) Clone() *ResourcesManager

Clone clones the resource manager and all sub resources

func (*ResourcesManager) Init

func (rs *ResourcesManager) Init() error

Init validates the resource and all sub resources

type Result

type Result struct {
	Error *errors.Error `json:"error,omitempty"`
	Data  any           `json:"data,omitempty"`
}

Result is a struct that contains the result of a resolver

func NewResult

func NewResult(data any, err error) *Result

NewResult creates a new result struct

type Role

type Role struct {
	ID          uint64        `json:"id,omitempty"`
	Name        string        `json:"name,omitempty"`
	Description string        `json:"description,omitempty" fs:"optional"`
	Root        bool          `json:"root,omitempty" fs:"optional"`
	Users       []*User       `json:"users,omitempty" fs.relation:"{'type':'m2m','schema':'user','field':'roles','owner':true}"`
	Permissions []*Permission `json:"permissions,omitempty" fs.relation:"{'type':'o2m','schema':'permission','field':'role','owner':true}"`

	Rule        string                     `json:"rule" fs:"optional"`
	RuleProgram *expr.Program[*Role, bool] `json:"-"` // The compiled rule program

	CreatedAt *time.Time `json:"created_at,omitempty" fs:"default=NOW()"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	// contains filtered or unexported fields
}

Role is a struct that contains the role data

func (*Role) Check added in v0.6.0

func (r *Role) Check(c context.Context, config expr.Config) error

func (*Role) Compile added in v0.6.0

func (r *Role) Compile() (err error)

type Signature

type Signature struct {
	Type any
	Name string
}

Signature hold the information of a signature

type Signatures

type Signatures = []any

Signatures hold the input and output types of a resolver

  • The first element is the input type

  • The second element is the output type

  • Each element is a type of any or a *Signature

For example:

- []any{&LoginData{}, &LoginResponse{}} // The input type is *LoginData and the output type is *LoginResponse

- []any{int, string} // The input type is int and the output type is string

- []any{&Signature{Type: dynamicStruct, Name: "Dynamic"}, int}: dynamic struct doesn't have name, use *Signature to define it

type StaticFs

type StaticFs struct {
	Root       http.FileSystem
	BasePath   string
	PathPrefix string
}

type StorageConfig

type StorageConfig struct {
	DefaultDisk string        `json:"default_disk"`
	Disks       []*DiskConfig `json:"disks"`
}

StorageConfig holds the storage configuration

func (*StorageConfig) Clone

func (sc *StorageConfig) Clone() *StorageConfig

Clone returns a clone of the storage configuration

type SyncMap added in v0.3.0

type SyncMap[K any, V any] struct {
	// contains filtered or unexported fields
}

func NewSyncMap added in v0.3.0

func NewSyncMap[K, V any]() *SyncMap[K, V]

func (*SyncMap[K, V]) Delete added in v0.3.0

func (sm *SyncMap[K, V]) Delete(key K)

func (*SyncMap[K, V]) Keys added in v0.3.0

func (sm *SyncMap[K, V]) Keys() []K

func (*SyncMap[K, V]) Len added in v0.3.0

func (sm *SyncMap[K, V]) Len() int

func (*SyncMap[K, V]) Load added in v0.3.0

func (sm *SyncMap[K, V]) Load(key K) (value V, ok bool)

func (*SyncMap[K, V]) LoadOrStore added in v0.3.0

func (sm *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

func (*SyncMap[K, V]) Store added in v0.3.0

func (sm *SyncMap[K, V]) Store(key K, value V)

type Traceable added in v0.5.0

type Traceable interface {
	TraceID() string
}

type User

type User struct {
	ID        uint64 `json:"id,omitempty"`
	Username  string `json:"username,omitempty" fs:"optional"`
	Email     string `json:"email,omitempty" fs:"optional"`
	FirstName string `json:"first_name,omitempty" fs:"optional"`
	LastName  string `json:"last_name,omitempty" fs:"optional"`
	Password  string `` /* 198-byte string literal not displayed */

	Active               bool   `json:"active,omitempty" fs:"optional"`
	Provider             string `json:"provider,omitempty" fs:"optional"`
	ProviderID           string `json:"provider_id,omitempty" fs:"optional"`
	ProviderUsername     string `json:"provider_username,omitempty" fs:"optional"`
	ProviderProfileImage string `json:"provider_profile_image,omitempty" fs:"optional"`

	RoleIDs []uint64 `json:"role_ids,omitempty"`
	Roles   []*Role  `json:"roles,omitempty" fs.relation:"{'type':'m2m','schema':'role','field':'users','owner':false}"`
	Files   []*File  `json:"files,omitempty" fs.relation:"{'type':'o2m','schema':'file','field':'user','owner':true}"`

	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	// contains filtered or unexported fields
}

User is a struct that contains user data

func (*User) IsRoot

func (u *User) IsRoot() bool

func (*User) JwtClaim

func (u *User) JwtClaim(key string, exps ...time.Time) (string, time.Time, error)

JwtClaim generates a jwt claim

type UserJwtClaims

type UserJwtClaims struct {
	jwt.RegisteredClaims

	User *User `json:"user"`
}

UserJwtClaims is a struct that contains the user jwt claims

type WSClient added in v0.3.0

type WSClient interface {
	ID() string
	Write(message []byte, messageTypes ...WSMessageType) error
	Read() (messageType WSMessageType, message []byte, err error)
	Close(msgs ...string) error
	IsCloseNormal(err error) bool
}

type WSCloseType added in v0.3.0

type WSCloseType int
const (
	WSCloseTypeInvalid WSCloseType = iota + 999
	WSCloseNormalClosure
	WSCloseGoingAway
	WSCloseProtocolError
	WSCloseUnsupportedData
	WSCloseSkipReserved
	WSCloseNoStatusReceived
	WSCloseAbnormalClosure
	WSCloseInvalidFramePayloadData
	WSClosePolicyViolation
	WSCloseMessageTooBig
	WSCloseMandatoryExtension
	WSCloseInternalServerErr
	WSCloseServiceRestart
	WSCloseTryAgainLater
	WSCloseSkipBadGateway
	WSCloseTLSHandshake
)

func WSCloseTypeFromInt added in v0.3.0

func WSCloseTypeFromInt(i int) WSCloseType

func (WSCloseType) Int added in v0.3.0

func (t WSCloseType) Int() int

Int returns the int value of the type

func (WSCloseType) Valid added in v0.3.0

func (t WSCloseType) Valid() bool

Valid reports if the given type if known type.

type WSMessageType added in v0.3.0

type WSMessageType int
const (
	WSMessageInvalid WSMessageType = 0
	WSMessageText    WSMessageType = 1
	WSMessageBinary  WSMessageType = 2
	WSMessageClose   WSMessageType = 8
	WSMessagePing    WSMessageType = 9
	WSMessagePong    WSMessageType = 10
)

func WSMessageTypeFromInt added in v0.3.0

func WSMessageTypeFromInt(i int) WSMessageType

func (WSMessageType) Int added in v0.3.0

func (t WSMessageType) Int() int

Int returns the int value of the type

func (WSMessageType) Valid added in v0.3.0

func (t WSMessageType) Valid() bool

Valid reports if the given type if known type.

Jump to

Keyboard shortcuts

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