Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultCorsConfig() cors.Config
- func DuplicateFieldCheck[T any](db *gorm.DB, context *gin.Context, logger *gogger.Logger, objectForCheck *T, ...) error
- func GetJSONFieldNameOf[T any](fields ...string) ([]string, error)
- func GetSearchValuesFromContext(context *gin.Context) (url.Values, error)
- func HandleSearch(context *gin.Context, db *gorm.DB, searchHandlers SearchHandlers) (*gorm.DB, error)
- func IDsJoin(ids []ID, sep string) string
- func IsNotEmptyArray(v any) bool
- func MakeErrorResponse(context *gin.Context, code Code, err any)
- func MakeJSONRequest[T any](httpClient *http.Client, okayHttpStatusRange *HttpStatusRange, u *url.URL, ...) error
- func MakeOkayDataResponse[T any](context *gin.Context, data T)
- func MakeOkayResponse[T any](context *gin.Context, code Code, message string, data T)
- func MapFuncOverCommaSeparatedString(mapFunc func(string), css string)
- 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(patternOrEmpty 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 PickFirstValuableString(array []string) (string, bool)
- func RecoveryHandler(responseFullError bool) gin.HandlerFunc
- func RemoveDuplication[T ~[]E, E comparable](array T) T
- func SaveAsDigestedFile(folder string, filename string, reader io.Reader, length int64, ...) (Filename, FileDigest, error)
- func Setup[T any](group *gin.RouterGroup, database *gorm.DB, logger *gogger.Logger, ...) error
- func SetupDualPrimaryKeyModelController[T any](group *gin.RouterGroup, db *gorm.DB, logger *gogger.Logger, ...) error
- func StringArrayFromCommaSeparatedString(css string) []string
- func Ternary[T any](condition bool, onTrue T, onFalse T) T
- func TernaryFunc[T any](conditionFunc func() bool, onTrueFunc, onFalseFunc func() T) T
- func Wait4CtrlC() os.Signal
- type Base
- type Code
- type Coder
- type Crud
- type Crudy
- func (c *Crudy[T]) All(searchParams SearchParams) ([]T, error)
- func (c *Crudy[T]) BuildURL(uri string, searchParams SearchParams) (*url.URL, error)
- func (c *Crudy[T]) Count(searchParams SearchParams) (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 SearchParams) ([]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 DualPrimaryKeyModelHandler
- func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) Delete(id1, id2 ID) (int64, error)
- func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) GetAll(t1IDs, t2IDs []ID, params ...SearchParams) ([]DPKM, error)
- func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) Save(records []DPKM) (int64, error)
- func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) SaveAfterDelete(deleteByField string, idToDelete ID, records []DPKM) (int64, error)
- type FileDigest
- type Filename
- type HttpFileSystemConfig
- type HttpStatusRange
- type ID
- type Operator
- type R
- type SearchHandler
- func KeywordEqual(field string, vt ValueTransformer[string, any]) SearchHandler
- func KeywordIDIn(field string, vt ValueTransformer[[]ID, []ID]) SearchHandler
- func KeywordIn(field string, vt ValueTransformer[[]string, []string]) SearchHandler
- func KeywordLike(field string, vt ValueTransformer[string, any]) SearchHandler
- func KeywordStatement(field string, operator Operator, vt ValueTransformer[string, any]) SearchHandler
- func NewSoftDeleteSearchHandler(tableName string) SearchHandler
- func SortBy(field string) SearchHandler
- type SearchHandlers
- type SearchParams
- type SingleHTMLServeConfig
- type ValueTransformer
Constants ¶
View Source
const (
XFileDigest = "X-File-Digest"
)
Variables ¶
View Source
var ( NilGroupError = errors.New("group is nil") NilDatabaseError = errors.New("database is nil") )
View Source
var ( DefaultPageSizes = []uint64{10, 20, 50, 100} DefaultPageSize = uint64(50) )
View Source
var ( DefaultOkayHttpStatusRange = HttpStatusRange{http.StatusOK, http.StatusMultipleChoices} 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 IDKind = reflect.Uint64
View Source
var (
NotArrayError = fmt.Errorf("not an array")
)
View Source
var Operators = []Operator{ OperatorEqual, OperatorLike, OperatorNotLike, OperatorIn, OperatorNotIn, OperatorNull, OperatorNNull, OperatorBetween, OperatorNotBetween, OperatorGt, OperatorGte, OperatorLt, OperatorLte, OperatorNeq, }
View Source
var RestCoder = NewDefaultCoder()
Functions ¶
func DefaultCorsConfig ¶
func DuplicateFieldCheck ¶
func DuplicateFieldCheck[T any]( db *gorm.DB, context *gin.Context, logger *gogger.Logger, objectForCheck *T, objectFieldName, dbFieldName string, ) error
DuplicateFieldCheck T must extend from Base which must contain id field
func HandleSearch ¶
func IsNotEmptyArray ¶
func MakeJSONRequest ¶
func MakeOkayDataResponse ¶
func MakeOkayResponse ¶
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 PickFirstValuableString ¶
func RecoveryHandler ¶
func RecoveryHandler(responseFullError bool) gin.HandlerFunc
func RemoveDuplication ¶
func RemoveDuplication[T ~[]E, E comparable](array T) T
func SaveAsDigestedFile ¶
func SaveAsDigestedFile( folder string, filename string, reader io.Reader, length int64, validigest FileDigest, ) (Filename, FileDigest, error)
func TernaryFunc ¶
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 { DisallowNonstandardPageSize bool DefaultPageSize uint64 PageSizes []uint64 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 *uint64, pageSize *uint64, context *gin.Context, db *gorm.DB) *gorm.DB DidPage func(pageNum uint64, pageSize uint64, 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 MakeOkayResponse func(context *gin.Context, data any) MakeErrorResponse func(context *gin.Context, code Code, err any) 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 }
func (*Crudy[T]) All ¶
func (c *Crudy[T]) All(searchParams SearchParams) ([]T, error)
type CrudyBasicOptions ¶
type CrudyBasicOptions[T any] struct { CrudyOption[T] BaseURL string HttpClient *http.Client OkayHttpStatusRange *HttpStatusRange }
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 DualPrimaryKeyModelHandler ¶
type DualPrimaryKeyModelHandler[T1 any, T2 any, DPKM any] struct { ObjectFieldName1 string ObjectFieldName2 string // contains filtered or unexported fields }
DualPrimaryKeyModelHandler T1: model 1, should have ID field, connected by objectFieldName1 of DPKM T2: model 2, should have ID field, connected by objectFieldName2 of DPKM DPKM: dual primary key model
func NewDualPrimaryKeyModelHandler ¶
func NewDualPrimaryKeyModelHandler[T1 any, T2 any, DPKM any]( baseURL string, httpClient *http.Client, okayHttpStatusRange *HttpStatusRange, objectFieldName1, objectFieldName2 string, ) (*DualPrimaryKeyModelHandler[T1, T2, DPKM], error)
func (*DualPrimaryKeyModelHandler[T1, T2, DPKM]) Delete ¶
func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) Delete(id1, id2 ID) (int64, error)
func (*DualPrimaryKeyModelHandler[T1, T2, DPKM]) GetAll ¶
func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) GetAll(t1IDs, t2IDs []ID, params ...SearchParams) ([]DPKM, error)
func (*DualPrimaryKeyModelHandler[T1, T2, DPKM]) Save ¶
func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) Save(records []DPKM) (int64, error)
func (*DualPrimaryKeyModelHandler[T1, T2, DPKM]) SaveAfterDelete ¶
func (d *DualPrimaryKeyModelHandler[T1, T2, DPKM]) SaveAfterDelete(deleteByField string, idToDelete ID, records []DPKM) (int64, error)
type FileDigest ¶
type FileDigest string
type HttpFileSystemConfig ¶
type HttpStatusRange ¶
type HttpStatusRange [2]int
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(field string, vt ValueTransformer[string, any]) SearchHandler
func KeywordIDIn ¶
func KeywordIDIn(field string, vt ValueTransformer[[]ID, []ID]) SearchHandler
func KeywordIn ¶
func KeywordIn(field string, vt ValueTransformer[[]string, []string]) SearchHandler
func KeywordLike ¶
func KeywordLike(field string, vt ValueTransformer[string, any]) SearchHandler
func KeywordStatement ¶
func KeywordStatement(field string, operator Operator, vt ValueTransformer[string, any]) SearchHandler
func NewSoftDeleteSearchHandler ¶
func NewSoftDeleteSearchHandler(tableName string) SearchHandler
func SortBy ¶
func SortBy(field string) SearchHandler
type SearchHandlers ¶
type SearchHandlers = map[string]SearchHandler
func BaseSearchHandlers ¶
func BaseSearchHandlers(overrideSearchHandlers ...SearchHandlers) SearchHandlers
type SearchParams ¶
type SingleHTMLServeConfig ¶
type ValueTransformer ¶
Click to show internal directories.
Click to hide internal directories.