transport

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const GlobalUse = "*"

Variables

View Source
var (
	ErrBadPayload       = errors.New("unable to decode payload")
	ErrUnmarshalPayload = errors.New("unable to unmarshal payload")
	ErrPathNotFound     = errors.New("path not found")
	ErrAddrInUse        = errors.New("address:port already in use")
)

Functions

func Decode

func Decode(r io.ReadCloser, data any) error

Decode incoming http request body

func Encode

func Encode(w http.ResponseWriter, r *http.Request, status int, data any) error

Encode outgoing http response

func Intercept

func Intercept(target http.HandlerFunc, interceptors ...Interceptor) http.HandlerFunc

Types

type Certs added in v0.19.2

type Certs struct {
}

type Code added in v0.19.2

type Code uint32
const (
	OK              Code = 0
	Canceled        Code = 1
	Unknown         Code = 2
	NotFound        Code = 3
	Unimplemented   Code = 4
	Unauthenticated Code = 5
	Internal        Code = 6
	Unavailable     Code = 7
	InvalidRequest  Code = 8
)

type Config added in v0.19.2

type Config struct {
	BasePath string `mapstructure:"basePath" envVar:"ATMK_TRANSPORT_BASEPATH"`
	Name     string `mapstructure:"name" envVar:"ATMK_TRANSPORT_NAME"`
	Port     string `mapstructure:"port" envVar:"ATMK_TRANSPORT_PORT"`
	WWW      string `mapstructure:"www" envVar:"ATMK_TRANSPORT_WWW"`

	// CORS
	AllowedOrigins   []string `mapstructure:"allowedOrigins" envVar:"ATMK_CORS_ORIGINS"`
	AllowedMethods   []string `mapstructure:"allowedMethods" envVar:"ATMK_CORS_METHODS"`
	AllowedHeaders   []string `mapstructure:"allowedHeaders" envVar:"ATMK_CORS_HEADERS"`
	AllowCredentials bool     `mapstructure:"allowCredentials" envVar:"ATMK_CORS_CREDS"`

	// TLS
	TlsCa   string `mapstructure:"tlsCa" envVar:"ATMK_TLS_CA"`
	TlsCert string `mapstructure:"tlsCert" envVar:"ATMK_TLS_CERT"`
	TlsKey  string `mapstructure:"tlsKey" envVar:"ATMK_TLS_KEY"`
}

func Configure added in v0.19.2

func Configure(key ...string) (*Config, error)

func Defaults added in v0.19.2

func Defaults() *Config

type Error

type Error struct {
	Code Code        `json:"code"`
	Msg  interface{} `json:"msg"`
}

func (*Error) Error added in v0.19.2

func (e *Error) Error() string

type Interceptor

type Interceptor interface {
	Intercept(http.HandlerFunc) http.HandlerFunc
}

Interceptor definition

type Route

type Route struct {
	ServiceName string
	ActionName  string
	Handler     http.HandlerFunc
	Method      string
}

type Transport

type Transport interface {
	atomika.Service
	OnError(w http.ResponseWriter, r *http.Request, err error)
	Register(route Route)
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	Use(route string, interceptorsList []Interceptor)
	UI(ui *UI)
}

func New

func New(cfg *Config) (Transport, error)

type UI added in v0.19.2

type UI struct {
	Dir string
	FS  http.FileSystem
}

UI allows adding ui support to the project. this will mount the handler on "/" (root) path and will overwrite anything else if present This UI mounting style is designed to work with SPA/WASM app style To activate UI - Pass a relative/abs path in DIR or - Pass an FS files system http.FS(fs.Sub())

func NewWithEmptyHandler added in v0.19.2

func NewWithEmptyHandler() *UI

func (*UI) Handler added in v0.19.2

func (ui *UI) Handler() http.Handler

Jump to

Keyboard shortcuts

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