transport

package
v0.0.0-...-020f94a Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const GlobalUse = "*"
View Source
const (
	TraceKey = "traceKey"
)

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 CORS

type CORS struct {
	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"`
}

type Certs

type Certs struct {
	CA   string `mapstructure:"ca" envVar:"ATMK_CERTS_CA"`
	Cert string `mapstructure:"cert" envVar:"ATMK_CERTS_CERT"`
	Key  string `mapstructure:"key" envVar:"ATMK_CERTS_KEY"`
}

type Code

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

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"`
	Certs    *Certs `mapstructure:"certs"`
	CORS     *CORS  `mapstructure:"cors"`
}

func (*Config) Configure

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

func (*Config) Defaults

func (c *Config) Defaults()

type Error

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

func (*Error) Error

func (e *Error) Error() string

type Interceptor

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

Interceptor definition

type Route

type Route struct {
	Handler http.Handler
	Method  string
}

type Transport

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

func New

func New(cfgKey ...string) Transport

Jump to

Keyboard shortcuts

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