fit

package
v0.0.0-...-47b83b8 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fiber

func Fiber[I, O any](fn Handler[I, O]) fiber.Handler

Fiber builds a POST/JSON fiber.handler

func ListExportedMethodNames

func ListExportedMethodNames(v reflect.Type) []string

Types

type Handler

type Handler[I, O any] func(ctx context.Context, in I) (O, status.Status)

type Method

type Method struct {
	In string

	Out string
	// contains filtered or unexported fields
}

func (*Method) Invoke

func (m *Method) Invoke(ctx context.Context, in any) (any, status.Status)

func (*Method) NewIn

func (m *Method) NewIn() reflect.Value

NewIn mints a new inType.

in := m.NewIn()
json.Unmarshal(data, in.Interface())

type Property

type Property struct {
	Type       string              `json:"type,omitempty"`
	Format     string              `json:"format,omitempty"`
	Validate   string              `json:"validate,omitempty"`
	Example    string              `json:"example,omitempty"`
	Properties map[string]Property `json:"properties,omitempty"`
}

type RPC

type RPC struct {
	*validator.Validate
	// contains filtered or unexported fields
}

func NewRPC

func NewRPC(ptr any) *RPC

NewRPC builds an RPC with from an instance of a type and its methods.

The exported methods must have the following signature. Where INPUT is a pointer to your input type, and OUTPUT is value your method sends back to the client.

fn(ctx context.Context, in *INPUT) (*OUTPUT, status.Status)

INPUT is validated before being passed to it method. see https://pkg.go.dev/github.com/go-playground/validator/v10

type Foo struct {
	Email string `validate:"email"`
}

Docs endpoints are created for each method.

GET /<type>/help // gets list of methods
GET /<type>/<method>/help // gets INPUT/OUTPUT

func (*RPC) MountFiberApp

func (s *RPC) MountFiberApp(app *fiber.App) fiber.Router

func (*RPC) Name

func (r *RPC) Name() string

func (*RPC) NewNetHttpHandler

func (s *RPC) NewNetHttpHandler() http.HandlerFunc

Directories

Path Synopsis
Run this file and try out the example.
Run this file and try out the example.

Jump to

Keyboard shortcuts

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