crud

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRUDEntitiesToOutput

func CRUDEntitiesToOutput[Entity any, Output any](
	entities []Entity, apiFields input.APIFields, tableName string,
) *Output

CRUDEntitiesToOutput converts a slice of entities to a single output.

Parameters:

  • entities: The entities to convert.
  • apiFields: The API fields to use for mapping.
  • tableName: The name of the table to use for mapping.

Returns:

  • Output: The output.

func CRUDEntitiesToOutputs

func CRUDEntitiesToOutputs[Entity any, Output any](
	entities []Entity, apiFields input.APIFields, tableName string,
) []Output

CRUDEntitiesToOutputs converts a slice of entities to a slice of outputs.

Parameters:

  • entities: The entities to convert.
  • apiFields: The API fields to use for mapping.
  • tableName: The name of the table to use for mapping.

Returns:

  • []Output: The outputs.

Types

type CRUDClient

type CRUDClient struct {
	// contains filtered or unexported fields
}

CRUDClient is a base client with common configuration.

func NewDefaultClient

func NewDefaultClient(url string) *CRUDClient

NewDefaultClient creates a new base client.

type CreateClient

type CreateClient[Input, Output any] struct {
	*CRUDClient
}

CreateClient is a generic wrapper for the create endpoint.

func NewCreateClient

func NewCreateClient[Input, Output any](
	base *CRUDClient,
) *CreateClient[Input, Output]

NewCreateClient creates a new CreateClient given a base client.

func (*CreateClient[Input, Output]) Send

func (c *CreateClient[Input, Output]) Send(
	ctx context.Context, host string, input *Input,
) (*json.Response[Output], error)

Send sends a create request using the strongly typed input and output.

type DefaultClients

type DefaultClients[CreateInput any, CreateOutput any, GetOutput any] struct {
	Create *CreateClient[CreateInput, json.APIOutput[CreateOutput]]
	Get    *GetClient[setup.DefaultGetInput, json.APIOutput[GetOutput]]
	Update *UpdateClient[setup.DefaultUpdateInput, json.APIOutput[setup.DefaultUpdateOutput]]
	Delete *DeleteClient[setup.DefaultDeleteInput, json.APIOutput[setup.DefaultDeleteOutput]]
}

DefaultClients groups the CRUD clients into a single struct.

func NewDefaultClients

func NewDefaultClients[CreateInput any, CreateOutput any, GetOutput any](
	url string,
) *DefaultClients[CreateInput, CreateOutput, GetOutput]

NewDefaultClients creates a new set of CRUD clients for the given URL.

type DeleteClient

type DeleteClient[Input any, Output any] struct {
	*CRUDClient
}

DeleteClient is a generic wrapper for the delete endpoint.

func NewDeleteClient

func NewDeleteClient[Input any, Output any](
	base *CRUDClient,
) *DeleteClient[Input, Output]

NewDeleteClient creates a new DeleteClient given a base client.

func (*DeleteClient[Input, Output]) Send

func (c *DeleteClient[Input, Output]) Send(
	ctx context.Context, host string, input *Input,
) (*json.Response[Output], error)

Send sends a delete request using the strongly typed input and output.

type GetClient

type GetClient[Input any, Output any] struct {
	*CRUDClient
}

GetClient is a generic wrapper for the get endpoint.

func NewGetClient

func NewGetClient[Input any, Output any](
	base *CRUDClient,
) *GetClient[Input, Output]

NewGetClient creates a new GetClient given a base client.

func (*GetClient[Input, Output]) Send

func (c *GetClient[Input, Output]) Send(
	ctx context.Context, host string, input *Input,
) (*json.Response[Output], error)

Send sends a get request using the strongly typed input and output.

type UpdateClient

type UpdateClient[Input any, Output any] struct {
	*CRUDClient
}

UpdateClient is a generic wrapper for the update endpoint.

func NewUpdateClient

func NewUpdateClient[Input any, Output any](
	base *CRUDClient,
) *UpdateClient[Input, Output]

NewUpdateClient creates a new UpdateClient given a base client.

func (*UpdateClient[Input, Output]) Send

func (c *UpdateClient[Input, Output]) Send(
	ctx context.Context, host string, input *Input,
) (*json.Response[Output], error)

Send sends an update request using the strongly typed input and output.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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