setup

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefinition

func CreateDefinition[Entity database.Mutator](
	cfg *CreateConfig[Entity],
	url string,
	stack endpoint.Stack,
	emitterLogger event.EmitterLogger,
) *endpoint.DefaultDefinition

CreateDefinition creates a definition for the create endpoint.

func CreateErrors

func CreateErrors() errutil.ExpectedErrors

func DefaultCreateHandler

func DefaultCreateHandler[Entity database.Mutator](
	connFn db.ConnFn,
	mutatorRepo db.MutatorRepository[Entity],
	txManager db.TxManager[Entity],
	outputFactoryFn func() services.CreateOutputer[Entity],
	beforeCallback services.BeforeCreateCallback[Entity],
	afterCreateFn services.AfterCreate[Entity],
) *services.CreateHandler[Entity]

DefaultCreateHandler sets up an endpoint handler for the create operation.

func DefaultDeleteHandler

func DefaultDeleteHandler[Entity database.Mutator](
	connFn db.ConnFn,
	entityFn func(opts ...db.EntityOption[Entity]) Entity,
	apiToDBFields inpututil.APIToDBFields,
	outputFactoryFn func() services.DeleteOutputer,
	beforeCallback services.BeforeDeleteCallback[Entity],
	mutatorRepo db.MutatorRepository[Entity],
	txManager db.TxManager[*int64],
	afterDeleteFn services.AfterDelete,
) *services.DeleteHandler[Entity]

DefaultDeleteHandler sets up an endpoint handler for the delete operation.

func DefaultGetHandler

func DefaultGetHandler[Entity database.Getter](
	connFn db.ConnFn,
	readerRepo db.ReaderRepository[Entity],
	txManager db.TxManager[Entity],
	entityFn func(opts ...db.EntityOption[Entity]) Entity,
	apiToDBFields inpututil.APIToDBFields,
	outputFactoryFn func() services.GetOutputer[Entity],
	beforeCallback services.BeforeGetCallback,
	afterGetFn services.AfterGet[Entity],
) *services.GetHandler[Entity]

DefaultGetHandler sets up an endpoint handler for the get operation.

func DefaultUpdateHandler

func DefaultUpdateHandler[Entity database.Mutator](
	connFn db.ConnFn,
	entityFn func(opts ...db.EntityOption[Entity]) Entity,
	apiToDBFields inpututil.APIToDBFields,
	outputFactoryFn func() services.UpdateOutputer,
	beforeCallback services.BeforeUpdateCallback[Entity],
	mutatorRepo db.MutatorRepository[Entity],
	txManager db.TxManager[*int64],
	afterUpdateFn services.AfterUpdate[Entity],
) *services.UpdateHandler[Entity]

DefaultUpdateHandler sets up an endpoint handler for the update operation.

func DeleteDefinition

func DeleteDefinition[Entity database.Mutator](
	cfg *DeleteConfig[Entity],
	url string,
	stack endpoint.Stack,
	emitterLogger event.EmitterLogger,
) *endpoint.DefaultDefinition

DeleteDefinition creates a definition for the delete endpoint.

func DeleteErrors

func DeleteErrors() errutil.ExpectedErrors

func GetDefinition

func GetDefinition[Entity database.Getter](
	cfg *GetConfig[Entity],
	url string,
	stack endpoint.Stack,
	emitterLogger event.EmitterLogger,
) *endpoint.DefaultDefinition

GetDefinition creates a definition for the get endpoint.

func GetErrors

func GetErrors() errutil.ExpectedErrors

func UpdateDefinition

func UpdateDefinition[Entity database.Mutator](
	cfg *UpdateConfig[Entity],
	url string,
	stack endpoint.Stack,
	emitterLogger event.EmitterLogger,
) *endpoint.DefaultDefinition

UpdateDefinition creates a definition for the update endpoint.

func UpdateErrors

func UpdateErrors() errutil.ExpectedErrors

Types

type CRUDConfig

type CRUDConfig[Entity database.CRUDEntity] struct {
	SystemID      string
	URL           string
	Stack         endpoint.Stack
	EmitterLogger event.EmitterLogger

	ConnFn        db.ConnFn
	APIToDBFields inpututil.APIToDBFields

	ConversionRules map[string]func(any) any
	CustomRules     map[string]func(any) error

	Create *CreateConfig[Entity]
	Get    *GetConfig[Entity]
	Update *UpdateConfig[Entity]
	Delete *DeleteConfig[Entity]
}

CRUDConfig holds all the settings for the CRUD endpoints.

func NewDefaultCRUDConfig

func NewDefaultCRUDConfig[Entity database.CRUDEntity](
	cfg *DefaultCRUDConfig[Entity],
) *CRUDConfig[Entity]

NewDefaultCRUDConfig returns a new CRUDConfig using the default settings.

func (*CRUDConfig[Entity]) MustValidate

func (cfg *CRUDConfig[Entity]) MustValidate() *CRUDConfig[Entity]

MustValidate validates the config and sets defaults and returns a new config. It panics if validation fails.

func (*CRUDConfig[Entity]) Validate

func (cfg *CRUDConfig[Entity]) Validate() (*CRUDConfig[Entity], error)

Validate validates the config and sets defaults and returns a new config.

func (*CRUDConfig[Entity]) ValidateMainCRUDConfig

func (cfg *CRUDConfig[Entity]) ValidateMainCRUDConfig() (
	*CRUDConfig[Entity], error,
)

ValidateMainCRUDConfig validates the main config and sets defaults It returns a new config with the defaults set.

type CRUDDefinitions

type CRUDDefinitions struct {
	Endpoints map[CRUDOperation]endpoint.Definition
}

CRUDDefinitions holds a collection of enabled endpoint definitions.

func NewCRUDDefinitions

func NewCRUDDefinitions[Entity database.CRUDEntity](
	cfg *CRUDConfig[Entity],
) *CRUDDefinitions

NewCRUDDefinitions creates endpoint definitions based on the enabled ops.

type CRUDOperation

type CRUDOperation string

CRUDOperation defines the type of CRUD operations.

const (
	OpCreate CRUDOperation = "create"
	OpGet    CRUDOperation = "get"
	OpUpdate CRUDOperation = "update"
	OpDelete CRUDOperation = "delete"
)

Supported CRUD operations.

type CRUDOption

type CRUDOption[Entity database.CRUDEntity] func(*CRUDConfig[Entity])

CRUDOption represents a functional option for configuring CRUDConfig.

type CreateConfig

type CreateConfig[Entity database.Mutator] struct {
	// Default config for the create input handler.
	DefaultInputHandlerConfig *DefaultCreateInputHandlerConfig[Entity]
	// Override config for the create handler logic.
	InputHandlerFactoryFn func() endpoint.InputHandler[services.CreateInputer[Entity]]

	// Default config for the create handler logic.
	DefaultHandlerLogicConfig *DefaultCreateHandlerLogicConfig[Entity]
	// Override for the create handler logic.
	HandlerLogicFnFactoryFn func() endpoint.HandlerLogicFn[services.CreateInputer[Entity]]

	ErrorHandlerFactoryFn  func() endpoint.ErrorHandler
	OutputHandlerFactoryFn func() endpoint.OutputHandler
}

CreateConfig holds the configuration for the create endpoint.

func (*CreateConfig[Entity]) Validate

func (cfg *CreateConfig[Entity]) Validate(
	systemID string,
	emitterLogger event.EmitterLogger,
	conversionRules map[string]func(any) any,
	customRules map[string]func(any) error,
	connFn db.ConnFn,
) (*CreateConfig[Entity], error)

Validate validates and sets defaults for the create config. It returns a new config with the defaults set.

type CreateHandler

type CreateHandler[Entity database.Mutator] interface {
	Handle(
		w http.ResponseWriter, r *http.Request, i *services.CreateInputer[Entity],
	) (any, error)
}

CreateHandler is the handler interface for the create endpoint.

type DefaultCRUDConfig

type DefaultCRUDConfig[Entity database.CRUDEntity] struct {
	SystemID              string
	URL                   string
	ConnFn                db.ConnFn
	EntityFn              func(...db.EntityOption[Entity]) Entity
	APIToDBFields         inpututil.APIToDBFields
	AllAPIFields          input.APIFields
	CreateAPIFields       input.APIFields
	CreateInputFactoryFn  func() services.CreateInputer[Entity]
	CreateOutputFactoryFn func() services.CreateOutputer[Entity]
	GetAPIFields          input.APIFields
	GetOutputFactoryFn    func() services.GetOutputer[Entity]
	UpdateAPIFields       input.APIFields
	DeleteAPIFields       input.APIFields
}

DefaultCRUDConfig holds the default settings for the CRUD endpoints.

type DefaultCreateHandlerLogicConfig

type DefaultCreateHandlerLogicConfig[Entity database.Mutator] struct {
	OutputFactoryFn func() services.CreateOutputer[Entity]
	BeforeCallback  services.BeforeCreateCallback[Entity]
	AfterCallback   services.AfterCreate[Entity]
	TxManager       db.TxManager[Entity]
	MutatorRepo     db.MutatorRepository[Entity]
}

DefaultCreateHandlerLogicConfig holds the default configuration for the create handler logic.

func (*DefaultCreateHandlerLogicConfig[Entity]) Validate

func (cfg *DefaultCreateHandlerLogicConfig[Entity]) Validate() (*DefaultCreateHandlerLogicConfig[Entity], error)

Validate validates and sets defaults for the create handler logic config. It returns a new config with the defaults set.

type DefaultCreateInputHandlerConfig

type DefaultCreateInputHandlerConfig[Entity database.Mutator] struct {
	APIFields      input.APIFields
	InputFactoryFn func() services.CreateInputer[Entity]
}

DefaultCreateInputHandlerConfig holds the default configuration for the create input handler.

func (*DefaultCreateInputHandlerConfig[Entity]) Validate

func (cfg *DefaultCreateInputHandlerConfig[Entity]) Validate() (*DefaultCreateInputHandlerConfig[Entity], error)

Validate validates and sets defaults for the create input handler config. It returns a new config with the defaults set.

type DefaultDeleteHandlerLogicConfig

type DefaultDeleteHandlerLogicConfig[Entity database.Mutator] struct {
	OutputFactoryFn func() services.DeleteOutputer
	BeforeCallback  services.BeforeDeleteCallback[Entity]
	AfterCallback   services.AfterDelete
	EntityFn        func(...db.EntityOption[Entity]) Entity
}

DefaultDeleteHandlerLogicConfig holds the default configuration for the delete handler logic.

func (*DefaultDeleteHandlerLogicConfig[Entity]) Validate

func (cfg *DefaultDeleteHandlerLogicConfig[Entity]) Validate() (*DefaultDeleteHandlerLogicConfig[Entity], error)

Validate validates and sets defaults for the delete handler logic config. It returns a new config with the defaults set.

type DefaultDeleteInput

type DefaultDeleteInput struct {
	Selectors apidb.APISelectors `json:"selectors"`
}

func NewDeleteInput

func NewDeleteInput() *DefaultDeleteInput

func (*DefaultDeleteInput) GetSelectors

func (d *DefaultDeleteInput) GetSelectors() apidb.APISelectors

type DefaultDeleteInputHandlerConfig

type DefaultDeleteInputHandlerConfig struct {
	APIFields      input.APIFields
	InputFactoryFn func() services.DeleteInputer
}

DefaultDeleteInputHandlerConfig holds the default configuration for the delete input handler.

func (*DefaultDeleteInputHandlerConfig) Validate

Validate validates and sets defaults for the delete input handler config. It returns a new config with the defaults set.

type DefaultDeleteOutput

type DefaultDeleteOutput struct {
	Count int64 `json:"count"`
}

func NewDefaultDeleteOutput

func NewDefaultDeleteOutput() *DefaultDeleteOutput

func (*DefaultDeleteOutput) SetCount

func (d *DefaultDeleteOutput) SetCount(count int64)

type DefaultGetHandlerLogicConfig

type DefaultGetHandlerLogicConfig[Entity database.Getter] struct {
	OutputFactoryFn func() services.GetOutputer[Entity]
	BeforeCallback  services.BeforeGetCallback
	AfterGetFn      services.AfterGet[Entity]
	EntityFn        func(...db.EntityOption[Entity]) Entity
	TxManager       db.TxManager[Entity]
	ReaderRepo      db.ReaderRepository[Entity]
}

DefaultGetHandlerLogicConfig holds the default configuration for the get handler logic.

func (*DefaultGetHandlerLogicConfig[Entity]) Validate

func (cfg *DefaultGetHandlerLogicConfig[Entity]) Validate() (*DefaultGetHandlerLogicConfig[Entity], error)

Validate validates and sets defaults for the get handler logic config. It returns a new config with the defaults set.

type DefaultGetInput

type DefaultGetInput struct {
	Selectors apidb.APISelectors `json:"selectors"`
	Orders    apidb.Orders       `json:"orders"`
	Page      *apidb.Page        `json:"page"`
	Count     bool               `json:"count"`
}

DefaultGetInput is the default input for the get endpoint.

func NewGetInput

func NewGetInput() *DefaultGetInput

NewGetInput returns a new DefaultGetInput.

func (*DefaultGetInput) GetCount

func (i *DefaultGetInput) GetCount() bool

GetCount returns the count for the get db.

func (*DefaultGetInput) GetOrders

func (i *DefaultGetInput) GetOrders() apidb.Orders

GetOrders returns the orders for the get db.

func (*DefaultGetInput) GetPage

func (i *DefaultGetInput) GetPage() *apidb.Page

GetPage returns the page for the get db.

func (*DefaultGetInput) GetSelectors

func (i *DefaultGetInput) GetSelectors() apidb.APISelectors

GetSelectors returns the selectors for the get db.

type DefaultGetInputHandlerConfig

type DefaultGetInputHandlerConfig struct {
	APIFields      input.APIFields
	InputFactoryFn func() services.GetInputer
}

DefaultGetInputHandlerConfig holds the default configuration for the get input handler.

func (*DefaultGetInputHandlerConfig) Validate

Validate validates and sets defaults for the get input handler config. It returns a new config with the defaults set.

type DefaultGetOutput

type DefaultGetOutput[Entity database.Getter] struct {
	Entities []Entity `json:"entities"`
	Count    int      `json:"count"`
}

func NewDefaultGetOutput

func NewDefaultGetOutput[Entity database.Getter]() *DefaultGetOutput[Entity]

func (*DefaultGetOutput[Entity]) SetCount

func (o *DefaultGetOutput[Entity]) SetCount(count int)

func (*DefaultGetOutput[Entity]) SetEntities

func (o *DefaultGetOutput[Entity]) SetEntities(entities []Entity)

type DefaultUpdateHandlerLogicConfig

type DefaultUpdateHandlerLogicConfig[Entity database.Mutator] struct {
	OutputFactoryFn func() services.UpdateOutputer
	BeforeCallback  services.BeforeUpdateCallback[Entity]
	AfterUpdateFn   services.AfterUpdate[Entity]
	EntityFn        func(...db.EntityOption[Entity]) Entity
}

DefaultUpdateHandlerLogicConfig holds the default configuration for the update handler logic.

func (*DefaultUpdateHandlerLogicConfig[Entity]) Validate

func (cfg *DefaultUpdateHandlerLogicConfig[Entity]) Validate() (*DefaultUpdateHandlerLogicConfig[Entity], error)

Validate validates and sets defaults for the update handler logic config. It returns a new config with the defaults set.

type DefaultUpdateInput

type DefaultUpdateInput struct {
	Selectors apidb.APISelectors `json:"selectors"`
	Updates   apidb.APIUpdates   `json:"updates"`
	Upsert    bool               `json:"upsert"`
}

func NewDefaultUpdateInput

func NewDefaultUpdateInput() *DefaultUpdateInput

func (*DefaultUpdateInput) GetSelectors

func (u *DefaultUpdateInput) GetSelectors() apidb.APISelectors

func (*DefaultUpdateInput) GetUpdates

func (u *DefaultUpdateInput) GetUpdates() apidb.APIUpdates

func (*DefaultUpdateInput) GetUpsert

func (u *DefaultUpdateInput) GetUpsert() bool

type DefaultUpdateInputHandlerConfig

type DefaultUpdateInputHandlerConfig struct {
	APIFields      input.APIFields
	InputFactoryFn func() services.UpdateInputer
}

DefaultUpdateInputHandlerConfig holds the default configuration for the update input handler.

func (*DefaultUpdateInputHandlerConfig) Validate

Validate validates and sets defaults for the update input handler config. It returns a new config with the defaults set.

type DefaultUpdateOutput

type DefaultUpdateOutput struct {
	Count int64 `json:"count"`
}

func NewDefaultUpdateOutput

func NewDefaultUpdateOutput() *DefaultUpdateOutput

func (*DefaultUpdateOutput) SetCount

func (u *DefaultUpdateOutput) SetCount(count int64)

type DeleteConfig

type DeleteConfig[Entity database.Mutator] struct {
	// Default config for the delete input handler.
	DefaultInputHandlerConfig *DefaultDeleteInputHandlerConfig
	// Override for the delete input handler.
	InputHandlerFactoryFn func() endpoint.InputHandler[services.DeleteInputer]

	// Default config for the delete handler logic.
	DefaultHandlerLogicConfig *DefaultDeleteHandlerLogicConfig[Entity]
	// Override for the delete handler logic.
	HandlerLogicFnFactoryFn func() endpoint.HandlerLogicFn[services.DeleteInputer]

	ErrorHandlerFactoryFn  func() endpoint.ErrorHandler
	OutputHandlerFactoryFn func() endpoint.OutputHandler
}

DeleteConfig holds the configuration for the delete endpoint.

func (*DeleteConfig[Entity]) Validate

func (cfg *DeleteConfig[Entity]) Validate(
	systemID string,
	emitterLogger event.EmitterLogger,
	conversionRules map[string]func(any) any,
	customRules map[string]func(any) error,
	connFn db.ConnFn,
	apiToDBFields inpututil.APIToDBFields,
) (*DeleteConfig[Entity], error)

Validate validates and sets defaults for the delete config. It returns a new config with the defaults set.

type DeleteHandler

type DeleteHandler interface {
	Handle(
		w http.ResponseWriter, r *http.Request, i services.DeleteInputer,
	) (any, error)
}

DeleteHandler is the handler interface for the delete endpoint.

type GetConfig

type GetConfig[Entity database.Getter] struct {
	// Default config for the get input handler.
	DefaultInputHandlerConfig *DefaultGetInputHandlerConfig
	// Override for the get input handler.
	InputHandlerFactoryFn func() endpoint.InputHandler[services.GetInputer]

	// Default config for the get handler logic.
	DefaultHandlerLogicConfig *DefaultGetHandlerLogicConfig[Entity]
	// Override for the get handler logic.
	HandlerLogicFnFactoryFn func() endpoint.HandlerLogicFn[services.GetInputer]

	ErrorHandlerFactoryFn  func() endpoint.ErrorHandler
	OutputHandlerFactoryFn func() endpoint.OutputHandler
}

GetConfig holds the configuration for the get endpoint.

func (*GetConfig[Entity]) Validate

func (cfg *GetConfig[Entity]) Validate(
	systemID string,
	emitterLogger event.EmitterLogger,
	conversionRules map[string]func(any) any,
	customRules map[string]func(any) error,
	connFn db.ConnFn,
	apiToDBFields inpututil.APIToDBFields,
) (*GetConfig[Entity], error)

Validate validates and sets defaults for the get config. It returns a new config with the defaults set.

type GetHandler

type GetHandler interface {
	Handle(
		w http.ResponseWriter, r *http.Request, i *services.GetInputer,
	) (any, error)
}

GetHandler is the handler interface for the get endpoint.

type UpdateConfig

type UpdateConfig[Entity database.Mutator] struct {
	// Default config for the update input handler.
	DefaultInputHandlerConfig *DefaultUpdateInputHandlerConfig
	// Override for the update input handler.
	InputHandlerFactoryFn func() endpoint.InputHandler[services.UpdateInputer]

	// Default config for the update handler logic.
	DefaultHandlerLogicConfig *DefaultUpdateHandlerLogicConfig[Entity]
	// Override for the update handler logic.
	HandlerLogicFnFactoryFn func() endpoint.HandlerLogicFn[services.UpdateInputer]

	ErrorHandlerFactoryFn  func() endpoint.ErrorHandler
	OutputHandlerFactoryFn func() endpoint.OutputHandler
}

UpdateConfig holds the configuration for the update endpoint.

func (*UpdateConfig[Entity]) Validate

func (cfg *UpdateConfig[Entity]) Validate(
	systemID string,
	emitterLogger event.EmitterLogger,
	conversionRules map[string]func(any) any,
	customRules map[string]func(any) error,
	connFn db.ConnFn,
	apiToDBFields inpututil.APIToDBFields,
) (*UpdateConfig[Entity], error)

Validate validates and sets defaults for the update config. It returns a new config with the defaults set.

type UpdateHandler

type UpdateHandler interface {
	Handle(
		w http.ResponseWriter, r *http.Request, i *services.UpdateInputer,
	) (any, error)
}

UpdateHandler is the handler interface for the update endpoint.

Jump to

Keyboard shortcuts

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