api

package
v4.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(e *Endpoint) map[string]string

Encode encodes an endpoint to endpoint metadata

func RequestPayload

func RequestPayload(r *http.Request) ([]byte, error)

RequestPayload takes a *http.Request and returns the payload If the request is a GET the query string parameters are extracted and marshaled to JSON and the raw bytes are returned. If the request method is a POST the request body is read and returned

func Validate

func Validate(e *Endpoint) error

Validate validates an endpoint to guarantee it won't blow up when being served

func WithEndpoint

func WithEndpoint(e *Endpoint) server.HandlerOption

Types

type API

type API interface {
	// Initialise options
	Init(...Option) error
	// Get the options
	Options() Options
	// Register a http handler
	Register(*Endpoint) error
	// Register a route
	Deregister(*Endpoint) error
	// Implementation of api
	String() string
}

type Endpoint

type Endpoint struct {
	// RPC Method e.g. Greeter.Hello
	Name string
	// Domain
	Domain string
	// Description e.g what's this endpoint for
	Description string
	// API Handler e.g rpc, proxy
	Handler string
	// HTTP Host e.g example.com
	Host []string
	// HTTP Methods e.g GET, POST
	Method []string
	// HTTP Path e.g /greeter. Expect POSIX regex
	Path string
	// Body destination
	// "*" or "" - top level message value
	// "string" - inner message value
	Body string
	// Stream flag
	Stream bool
}

Endpoint is a mapping between an RPC method and HTTP endpoint

func Decode

func Decode(e map[string]string) *Endpoint

Decode decodes endpoint metadata into an endpoint

type Option

type Option func(*Options)

func EnableCORS

func EnableCORS(b bool) Option

func EnableTLS

func EnableTLS(b bool) Option

func TLSConfig

func TLSConfig(t *tls.Config) Option

func WrapHandler

func WrapHandler(w ...Wrapper) Option

type Options

type Options struct {
	EnableACME bool
	EnableCORS bool
	EnableTLS  bool
	ACMEHosts  []string
	TLSConfig  *tls.Config
	Wrappers   []Wrapper
}

type Server

type Server interface {
	Address() string
	Init(opts ...Option) error
	Handle(path string, handler http.Handler)
	Start() error
	Stop() error
}

Server serves api requests

type Service

type Service struct {
	// Name of service
	Name string
	// Domain of the service
	Domain string
	// The endpoint for this service
	Endpoint *Endpoint
	// Versions of this service
	Services []*registry.Service
}

Service represents an API service

type Wrapper

type Wrapper func(h http.Handler) http.Handler

Directories

Path Synopsis
Package handler provides http handlers
Package handler provides http handlers
rpc
Package rpc is a go-micro rpc handler.
Package rpc is a go-micro rpc handler.
Package router provides api service routing
Package router provides api service routing
registry
Package registry provides a dynamic api service router
Package registry provides a dynamic api service router
http
Package http provides a http server with features; acme, cors, etc
Package http provides a http server with features; acme, cors, etc

Jump to

Keyboard shortcuts

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