Documentation
¶
Index ¶
- Constants
- Variables
- func ContainsByBase[T IBase](array []T, one T) bool
- func ContainsByID[T IBase](array []T, id ID) bool
- func DefaultCorsConfig() cors.Config
- func MakeErrorResponse(context *gin.Context, code Code, err any)
- func MakeJSONRequest[T any, RR any](crudy *Crudy[T], u *url.URL, method string, body io.Reader, res *R[RR]) error
- func MapFuncOverCommaSeparatedString(mapFunc func(string), css string)
- func New[T any](group *gin.RouterGroup, database *gorm.DB, crud Crud[T]) error
- func NewCors() gin.HandlerFunc
- func NewHardDeleteHandler[T any](coder Coder) func(context *gin.Context, db *gorm.DB) bool
- func NewHttpFileSystem(group *gin.RouterGroup, folder string, config *HttpFileSystemConfig) error
- func NewSingleHTMLServe(group *gin.RouterGroup, indexHTMLFile string, config *SingleHTMLServeConfig) error
- func NewSoftDeleteHandler[T any](coder Coder) func(context *gin.Context, db *gorm.DB) bool
- func NowString(pattern *string) string
- func NumericValidate(value string) any
- func OverflowedArrayTrimmer[T any](array []T, max int) []T
- func OverflowedArrayTrimmerFilter[T any](max int) func([]T) []T
- func Pick[T any](arr []T, index int, defaultValue T) T
- func Pointer[T any](t T) *T
- func RecoveryHandler(responseFullError bool) gin.HandlerFunc
- func SaveAsDigestedFile(folder string, filename string, reader io.Reader, length int64, ...) (Filename, FileDigest, error)
- func StringArrayFromCommaSeparatedString(css string) []string
- func Ternary[T any](condition bool, onTrue T, onFalse T) T
- func ValuableArray(array []string) (bool, string)
- func ValuableString(str *string, ifEmptyValue string) string
- func Wait4CtrlC() os.Signal
- type Base
- type Code
- type Coder
- type Crud
- type Crudy
- func (c *Crudy[T]) All(searchParams map[string]string) ([]T, error)
- func (c *Crudy[T]) BuildURL(uri string, searchParams map[string]string) (*url.URL, error)
- func (c *Crudy[T]) Count(searchParams map[string]string) (uint64, error)
- func (c *Crudy[T]) Delete(id ID) (bool, error)
- func (c *Crudy[T]) One(id ID) (*T, error)
- func (c *Crudy[T]) Page(current, size uint64, searchParams map[string]string) ([]T, error)
- func (c *Crudy[T]) Save(t *T) (*T, error)
- type CrudyBasicOptions
- type CrudyOption
- type CrudyPageOptions
- type DefaultCoder
- func (d *DefaultCoder) BadRequest() Code
- func (d *DefaultCoder) Conflict() Code
- func (d *DefaultCoder) From(code string) Code
- func (d *DefaultCoder) FromStatus(status int) Code
- func (d *DefaultCoder) InternalServerError() Code
- func (d *DefaultCoder) MethodNotAllowed() Code
- func (d *DefaultCoder) NotFound() Code
- func (d *DefaultCoder) OK() Code
- type FileDigest
- type Filename
- type HttpFileSystemConfig
- type IBase
- type ID
- type Operator
- type R
- type SearchHandler
- func KeywordEqual(name string, vt ValueTransformer[string, any]) SearchHandler
- func KeywordIDIn(name string, vt ValueTransformer[[]ID, []ID]) SearchHandler
- func KeywordIn(name string, vt ValueTransformer[[]string, []string]) SearchHandler
- func KeywordLike(name string, vt ValueTransformer[string, any]) SearchHandler
- func KeywordStatement(name string, operator Operator, vt ValueTransformer[string, any]) SearchHandler
- func NewSoftDeleteSearchHandler(tableName string) SearchHandler
- func SortBy(name string) SearchHandler
- type SearchHandlers
- type SingleHTMLServeConfig
- type ValueTransformer
Constants ¶
View Source
const (
XFileDigest = "X-File-Digest"
)
Variables ¶
View Source
var ( NilGroupError = errors.New("engine is nil") NilRepositoryError = errors.New("database is nil") )
View Source
var ( DefaultPageSizes = []int64{10, 20, 50, 100} DefaultPageSize = DefaultPageSizes[0] )
View Source
var ( DefaultOkCodes = []int{200} ErrorBaseURLRequired = errors.New("BaseURL is required") )
View Source
var ( ErrorIncompleteWrite = errors.New("incomplete write") ErrorFileExists = errors.New("file already exists") ErrorFileIsDir = errors.New("file is a directory") ErrorUploadNotAllowed = errors.New("upload not allowed") ErrorFileDigestMismatch = errors.New("digest mismatch") )
View Source
var RestCoder = NewDefaultCoder()
Functions ¶
func ContainsByBase ¶
func ContainsByID ¶
func DefaultCorsConfig ¶
func MakeJSONRequest ¶
func NewCors ¶
func NewCors() gin.HandlerFunc
func NewHardDeleteHandler ¶
func NewHttpFileSystem ¶
func NewHttpFileSystem(group *gin.RouterGroup, folder string, config *HttpFileSystemConfig) error
func NewSingleHTMLServe ¶
func NewSingleHTMLServe(group *gin.RouterGroup, indexHTMLFile string, config *SingleHTMLServeConfig) error
func NewSoftDeleteHandler ¶
func NumericValidate ¶
func OverflowedArrayTrimmer ¶
func RecoveryHandler ¶
func RecoveryHandler(responseFullError bool) gin.HandlerFunc
func SaveAsDigestedFile ¶
func SaveAsDigestedFile( folder string, filename string, reader io.Reader, length int64, validigest FileDigest, ) (Filename, FileDigest, error)
func ValuableArray ¶
func ValuableString ¶
func Wait4CtrlC ¶
Types ¶
type Coder ¶
type Coder interface { OK() Code InternalServerError() Code BadRequest() Code NotFound() Code MethodNotAllowed() Code Conflict() Code From(code string) Code FromStatus(status int) Code }
func NewDefaultCoder ¶
func NewDefaultCoder() Coder
type Crud ¶
type Crud[T any] struct { DisallowAnyPageSize bool DefaultPageSize int64 PageSizes []int64 SearchHandlers SearchHandlers EnableGetAll bool DisableGetOne bool DisableCount bool DisablePage bool DisableSave bool DisableDelete bool WillGetAll func(context *gin.Context, db *gorm.DB) *gorm.DB DidGetAll func(records []T, context *gin.Context, db *gorm.DB) WillGetOne func(context *gin.Context, db *gorm.DB) *gorm.DB DidGetOne func(record *T, context *gin.Context, db *gorm.DB) WillCount func(context *gin.Context, db *gorm.DB) *gorm.DB DidCount func(count *int64, context *gin.Context, db *gorm.DB) WillPage func(pageNum *int64, pageSize *int64, context *gin.Context, db *gorm.DB) *gorm.DB DidPage func(pageNum int64, pageSize int64, list []T, context *gin.Context, db *gorm.DB) WillSave func(record *T, context *gin.Context, db *gorm.DB) DidSave func(record *T, context *gin.Context, db *gorm.DB) WillDelete func(context *gin.Context, db *gorm.DB) OnDelete func(context *gin.Context, db *gorm.DB) bool DidDelete func(context *gin.Context, db *gorm.DB) Coder Coder MakeOkResponse func(context *gin.Context, data any) MakeErrorResponse func(context *gin.Context, code Code, err error) GetCensors func(context *gin.Context, db *gorm.DB) ([]*censored.Censor, error) // contains filtered or unexported fields }
type Crudy ¶
type Crudy[T any] struct { // contains filtered or unexported fields }
type CrudyBasicOptions ¶
type CrudyBasicOptions[T any] struct { CrudyOption[T] BaseURL string HttpClient *http.Client OkCodes *[]int }
func (CrudyBasicOptions[T]) Apply ¶
func (b CrudyBasicOptions[T]) Apply(crudy *Crudy[T]) error
type CrudyOption ¶
type CrudyPageOptions ¶
type CrudyPageOptions[T any] struct { CrudyOption[T] DefaultSize uint64 }
func (CrudyPageOptions[T]) Apply ¶
func (b CrudyPageOptions[T]) Apply(crudy *Crudy[T]) error
type DefaultCoder ¶
type DefaultCoder struct {
Coder
}
func (*DefaultCoder) BadRequest ¶
func (d *DefaultCoder) BadRequest() Code
func (*DefaultCoder) Conflict ¶
func (d *DefaultCoder) Conflict() Code
func (*DefaultCoder) From ¶
func (d *DefaultCoder) From(code string) Code
func (*DefaultCoder) FromStatus ¶
func (d *DefaultCoder) FromStatus(status int) Code
func (*DefaultCoder) InternalServerError ¶
func (d *DefaultCoder) InternalServerError() Code
func (*DefaultCoder) MethodNotAllowed ¶
func (d *DefaultCoder) MethodNotAllowed() Code
func (*DefaultCoder) NotFound ¶
func (d *DefaultCoder) NotFound() Code
func (*DefaultCoder) OK ¶
func (d *DefaultCoder) OK() Code
type FileDigest ¶
type FileDigest string
type HttpFileSystemConfig ¶
type Operator ¶
type Operator string
const ( OperatorEqual Operator = "=" OperatorLike Operator = "LIKE" OperatorNotLike Operator = "NOT LIKE" OperatorIn Operator = "IN" OperatorNotIn Operator = "NOT IN" OperatorNull Operator = "IS NULL" OperatorNNull Operator = "IS NOT NULL" OperatorBetween Operator = "BETWEEN" OperatorNotBetween Operator = "NOT BETWEEN" OperatorGt Operator = ">" OperatorGte Operator = ">=" OperatorLt Operator = "<" OperatorLte Operator = "<=" OperatorNeq Operator = "!=" )
type SearchHandler ¶
func KeywordEqual ¶
func KeywordEqual(name string, vt ValueTransformer[string, any]) SearchHandler
func KeywordIDIn ¶
func KeywordIDIn(name string, vt ValueTransformer[[]ID, []ID]) SearchHandler
func KeywordIn ¶
func KeywordIn(name string, vt ValueTransformer[[]string, []string]) SearchHandler
func KeywordLike ¶
func KeywordLike(name string, vt ValueTransformer[string, any]) SearchHandler
func KeywordStatement ¶
func KeywordStatement(name string, operator Operator, vt ValueTransformer[string, any]) SearchHandler
func NewSoftDeleteSearchHandler ¶
func NewSoftDeleteSearchHandler(tableName string) SearchHandler
func SortBy ¶
func SortBy(name string) SearchHandler
type SearchHandlers ¶
type SearchHandlers = map[string]SearchHandler
type SingleHTMLServeConfig ¶
type ValueTransformer ¶
Click to show internal directories.
Click to hide internal directories.