base

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Uint64Converter

func Uint64Converter(a any) uint64

func UintConverter

func UintConverter(a any) uint

Types

type BeforeEditHook

type BeforeEditHook[M any, K comparable] func(ctx http.Context, id K, m M) (M, error)

type BeforeFindHook

type BeforeFindHook[M any] func(ctx http.Context, filters *[]base.Filter) error

type BeforeStoreHook

type BeforeStoreHook[M any] func(ctx http.Context, m M) (M, error)

type Controller

type Controller[M any, K comparable] struct {
	Repo CrudRepository[M, K]
	// contains filtered or unexported fields
}

func NewBaseController

func NewBaseController[M any, K comparable](repo CrudRepository[M, K], converter PrimaryKeyConverter[K], options ...OptionFunc[M, K]) *Controller[M, K]

func (*Controller[M, K]) Destroy

func (r *Controller[M, K]) Destroy(ctx http.Context) http.Response

func (*Controller[M, K]) Index

func (r *Controller[M, K]) Index(ctx http.Context) http.Response

func (*Controller[M, K]) Show

func (r *Controller[M, K]) Show(ctx http.Context) http.Response

func (*Controller[M, K]) Store

func (r *Controller[M, K]) Store(ctx http.Context) http.Response

func (*Controller[M, K]) Update

func (r *Controller[M, K]) Update(ctx http.Context) http.Response

type CrudRepository

type CrudRepository[M any, K comparable] interface {
	List(ctx http.Context, filters []base.Filter) ([]*M, error)
	Show(ctx http.Context, id K, m *M) error
	Store(ctx context.Context, m *M) error
	Edit(ctx http.Context, id K, m *M) error
	Delete(ctx context.Context, id K) error
}

type OptionFunc

type OptionFunc[M any, K comparable] func(controller *Controller[M, K])

func WithBeforeEdit

func WithBeforeEdit[M any, K comparable](hook BeforeEditHook[M, K]) OptionFunc[M, K]

func WithBeforeFind

func WithBeforeFind[M any, K comparable](hook BeforeFindHook[M]) OptionFunc[M, K]

func WithBeforeStore

func WithBeforeStore[M any, K comparable](hook BeforeStoreHook[M]) OptionFunc[M, K]

func WithRouteKey

func WithRouteKey[M any, K comparable](routeKey string) OptionFunc[M, K]

func WithScoped

func WithScoped[M any, K comparable](filters ...base.FilterItem) OptionFunc[M, K]

type PrimaryKeyConverter

type PrimaryKeyConverter[K comparable] func(any) K

Jump to

Keyboard shortcuts

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