rest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client for issuing REST-JSON requests for a specific type of objects.

func NewClient

func NewClient(config *Config) *Client

NewClient returns a new REST-JSON client.

func (*Client) Create

func (c *Client) Create(object any) error

Create an object.

func (*Client) Delete

func (c *Client) Delete(object any) error

Delete an object, either by name or the object itself.

func (*Client) Get

func (c *Client) Get(name string) (any, error)

Get an object.

func (*Client) List

func (c *Client) List() (any, error)

List all objects.

func (*Client) Update

func (c *Client) Update(object any) error

Update an object.

type Config

type Config struct {
	// Client is the underlying HTTP client.
	Client *jsonapi.Client
	// BasePath is the server HTTP path for manipulating a specific type of objects.
	BasePath string
	// SampleObject is an instance representing the type returned when getting an object.
	SampleObject any
	// SampleList is an instance representing the type returned when listing objects.
	SampleList any
}

Config specifies a client configuration.

type Handler

type Handler interface {
	// Decode and validate an object.
	Decode(data []byte) (any, error)
	// Create an object.
	Create(object any) error
	// Update an object.
	Update(object any) error
	// Get an object.
	Get(name string) (any, error)
	// Delete an object.
	Delete(object any) (any, error)
	// List all objects.
	List() (any, error)
}

Handler for object operations.

type Server

type Server struct {
	utilhttp.Server
	// contains filtered or unexported fields
}

Server for handling REST-JSON requests.

func NewServer

func NewServer(name string, tlsConfig *tls.Config) *Server

NewServer returns a new empty REST-JSON server.

func (*Server) AddObjectHandlers

func (s *Server) AddObjectHandlers(spec *ServerObjectSpec)

AddObjectHandlers adds the server a handlers for managing a specific object type.

type ServerObjectSpec

type ServerObjectSpec struct {
	// BasePath is the server HTTP path for manipulating a specific type of objects.
	BasePath string
	// Handler interface for object operations.
	Handler Handler
	// DeleteByValue is true for object types which are deletable by sending their value, instead of their name.
	DeleteByValue bool
}

ServerObjectSpec specifies a set of server handlers for a specific object type.

Jump to

Keyboard shortcuts

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