crud

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SettingsConfigKey = "crud"
	DefaultApiView    = "api"
)
View Source
const HttpStatusClientClosedRequest = 499

Variables

View Source
var ErrModelNotChanged = fmt.Errorf("nothing has changed on model")

Functions

func AddCreateHandler

func AddCreateHandler(config cfg.Config, logger log.Logger, d *httpserver.Definitions, version int, basePath string, handler CreateHandler)

func AddCrudHandlers

func AddCrudHandlers(config cfg.Config, logger log.Logger, d *httpserver.Definitions, version int, basePath string, handler Handler)

func AddDeleteHandler

func AddDeleteHandler(config cfg.Config, logger log.Logger, d *httpserver.Definitions, version int, basePath string, handler BaseHandler)

func AddListHandler

func AddListHandler(config cfg.Config, logger log.Logger, d *httpserver.Definitions, version int, basePath string, handler ListHandler)

func AddReadHandler

func AddReadHandler(config cfg.Config, logger log.Logger, d *httpserver.Definitions, version int, basePath string, handler BaseHandler)

func AddUpdateHandler

func AddUpdateHandler(config cfg.Config, logger log.Logger, d *httpserver.Definitions, version int, basePath string, handler UpdateHandler)

func GetApiViewFromHeader

func GetApiViewFromHeader(reqHeaders http.Header) string

func NewCreateHandler

func NewCreateHandler(config cfg.Config, logger log.Logger, transformer CreateHandler) gin.HandlerFunc

func NewDeleteHandler

func NewDeleteHandler(config cfg.Config, logger log.Logger, transformer BaseHandler) gin.HandlerFunc

func NewListHandler

func NewListHandler(_ cfg.Config, logger log.Logger, transformer ListHandler) gin.HandlerFunc

func NewReadHandler

func NewReadHandler(_ cfg.Config, logger log.Logger, transformer BaseHandler) gin.HandlerFunc

func NewUpdateHandler

func NewUpdateHandler(config cfg.Config, logger log.Logger, transformer UpdateHandler) gin.HandlerFunc

Types

type BaseCreateHandler

type BaseCreateHandler interface {
	GetCreateInput() any
	TransformCreate(ctx context.Context, input any, model db_repo.ModelBased) (err error)
}

type BaseHandler

type BaseHandler interface {
	GetRepository() Repository
	GetModel() db_repo.ModelBased
	TransformOutput(ctx context.Context, model db_repo.ModelBased, apiView string) (output any, err error)
}

type BaseListHandler

type BaseListHandler interface {
	List(ctx context.Context, qb *db_repo.QueryBuilder, apiView string) (out any, err error)
}

type BaseUpdateHandler

type BaseUpdateHandler interface {
	GetUpdateInput() any
	TransformUpdate(ctx context.Context, input any, model db_repo.ModelBased) (err error)
}

type CreateHandler

type CreateHandler interface {
	BaseHandler
	BaseCreateHandler
}

type ListHandler

type ListHandler interface {
	BaseHandler
	BaseListHandler
}

type Output

type Output struct {
	Total   int `json:"total"`
	Results any `json:"results"`
}

type Repository

type Repository interface {
	Create(ctx context.Context, value db_repo.ModelBased) error
	Read(ctx context.Context, id *uint, out db_repo.ModelBased) error
	Update(ctx context.Context, value db_repo.ModelBased) error
	Delete(ctx context.Context, value db_repo.ModelBased) error
	Query(ctx context.Context, qb *db_repo.QueryBuilder, result any) error
	Count(ctx context.Context, qb *db_repo.QueryBuilder, model db_repo.ModelBased) (int, error)
	GetMetadata() db_repo.Metadata
}

type Settings added in v0.29.1

type Settings struct {
	// Applies to create, update and delete handlers.
	// Write timeout is the maximum duration before canceling any write operation.
	WriteTimeout time.Duration `cfg:"write_timeout" default:"10m" validate:"min=1000000000"`
}

Settings structure for all CRUDL handler.

type UpdateHandler

type UpdateHandler interface {
	BaseHandler
	BaseUpdateHandler
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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