api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 8 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[T any] struct {
	Handler[T]
}

func NewClient

func NewClient[T any](c ctx.C, init T) (Client[T], error)

helper for NewHandler().Client()

func (Client[T]) Recv

func (this Client[T]) Recv(c ctx.C, res ClientResponse, into T) (err error)

func (Client[T]) Send

func (this Client[T]) Send(c ctx.C, obj T, data ClientRequest) error

type ClientRequest

type ClientRequest interface {
	Marshal(c ctx.C, name string, into reflect.Value) error
}

the client request object used to Marshal a request to a server

type ClientResponse

type ClientResponse interface {
	Unmarshal(c ctx.C, name string, from reflect.Value) error
}

the client response object used to unmarshal the response from the server

type Handler

type Handler[T any] struct {
	// contains filtered or unexported fields
}

each type of object T has its own handler

func NewHandler

func NewHandler[T any](c ctx.C, init T) (Handler[T], error)

we accept either Type or *Type

func (*Handler[T]) Client

func (this *Handler[T]) Client() Client[T]

func (*Handler[T]) Path

func (this *Handler[T]) Path() string

return the path of the first url, or the object name if no url is given

func (*Handler[T]) Paths

func (this *Handler[T]) Paths() []string

func (*Handler[T]) Server

func (this *Handler[T]) Server() Server[T]

func (*Handler[T]) Type

func (this *Handler[T]) Type() reflect.Type

func (*Handler[T]) URL

func (this *Handler[T]) URL() *url.URL

func (*Handler[T]) URLs

func (this *Handler[T]) URLs() []*url.URL

type JSON

type JSON struct {
	Data enc.Map
	UID  enc.Node
	// contains filtered or unexported fields
}

implementation for all the client/server request/responses using json Note(oha): the object is not goroutine safe, but it's not expected to be

func (*JSON) Auth

func (this *JSON) Auth(c ctx.C, into reflect.Value, required bool) error

func (*JSON) Marshal

func (this *JSON) Marshal(c ctx.C, name string, from reflect.Value) error

func (*JSON) ReadFrom

func (this *JSON) ReadFrom(c ctx.C, r io.Reader) error

func (JSON) String

func (this JSON) String() string

func (*JSON) Unmarshal

func (this *JSON) Unmarshal(c ctx.C, name string, into reflect.Value) error

type Request

type Request struct {
	Headers map[string]string
}

type Server

type Server[T any] struct {
	Handler[T]
}

func NewServer

func NewServer[T any](c ctx.C, init T) (Server[T], error)

helper for NewHandler().Server()

func (Server[T]) Recv

func (this Server[T]) Recv(c ctx.C, req ServerRequest) (T, error)

func (Server[T]) Send

func (this Server[T]) Send(c ctx.C, obj T, res ServerResponse) (err error)

type ServerRequest

type ServerRequest interface {
	Unmarshal(c ctx.C, name string, into reflect.Value) error
	Auth(c ctx.C, into reflect.Value, required bool) error
}

the server request object used to Unmarshal the request from the client

type ServerResponse

type ServerResponse interface {
	Marshal(c ctx.C, name string, into reflect.Value) error
}

the server response object used to marshal the response to the client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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