bootstrap

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RemapperReferenceName = "remapper"
	RemapperKazaam        = "kazaam" // https://github.com/qntfy/kazaam
	RemapperNoOp          = "noOp"
)
View Source
const (
	TablifierReferenceName = "tablifier"
	TablifierJSON          = "json"
)
View Source
const (
	TransformerReferenceName = "transformer"
	TransformerCSV           = "csv"
	TransformerPDF           = "pdf"
)
View Source
const (
	ErrRequiredConfigurationMissed = Error("required configuration missed")
)

Variables

Functions

func CreateRemapperKazaam

func CreateRemapperKazaam(name string, config Config) (manipulation.Remapper, error)

func CreateRemapperNoOp

func CreateRemapperNoOp(name string, _ Config) (manipulation.Remapper, error)

func DefaultBackendErrorHandler

func DefaultBackendErrorHandler(log func(v ...any)) func(err error) (proceed bool)

func DefaultErrorHandler

func DefaultErrorHandler(log func(v ...any)) func(err error, w http.ResponseWriter, r *http.Request)

func GetLogger

func GetLogger() app.Logger

func SetLogger

func SetLogger(log app.Logger)

Types

type BackendConfig

type BackendConfig struct {
	TargetURL              string `hcl:"target_url"`
	SuccessHTTPStatusCodes []int  `hcl:"success_http_status_codes,optional"`
}

type Config

type Config map[string]any

func (Config) GetString

func (c Config) GetString(name string, defaultVal ...string) string

type ConfigParser

type ConfigParser interface {
	Parse(filename string) (*RootConfig, error)
}

type DynamicConfig

type DynamicConfig struct {
	Name       string               `hcl:"name,label"`
	Attributes map[string]cty.Value `hcl:",remain"`
}

func (*DynamicConfig) ToConfig

func (c *DynamicConfig) ToConfig() (Config, error)

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type Factory

type Factory[T any] interface {
	Create(name string, config Config) (instance T, err error)
}

Factory base factory interface

func CSVTransformer

func CSVTransformer(tablifierFactory Factory[manipulation.Tablifier]) Factory[manipulation.DataTransformer]

func JSONTablifierFactory

func JSONTablifierFactory(
	remapperFactory Factory[manipulation.Remapper],
	defaultRemapper manipulation.Remapper,
) Factory[manipulation.Tablifier]

func PDFTransformer

func PDFTransformer(remapperFactory Factory[manipulation.Remapper]) Factory[manipulation.DataTransformer]

type FactoryFunc

type FactoryFunc[T any] func(name string, config Config) (T, error)

FactoryFunc allows using functions as factories

func (FactoryFunc[T]) Create

func (f FactoryFunc[T]) Create(name string, config Config) (T, error)

type FactoryMap

type FactoryMap[T any] map[string]Factory[T]

FactoryMap allows using multiple factory by name

func (FactoryMap[T]) Create

func (f FactoryMap[T]) Create(name string, config Config) (instance T, err error)

type HCLConfigParser

type HCLConfigParser struct {
}

func (HCLConfigParser) Parse

func (p HCLConfigParser) Parse(filename string) (*RootConfig, error)

type HTTPRoutesInitializer

type HTTPRoutesInitializer interface {
	InitRoutes(router route.Router, config *ServerConfig) error
}

type HTTPRoutesInitializers

type HTTPRoutesInitializers []HTTPRoutesInitializer

func (HTTPRoutesInitializers) InitRoutes

func (h HTTPRoutesInitializers) InitRoutes(router route.Router, config *ServerConfig) error

type ProxyRoutesInitializer

type ProxyRoutesInitializer struct {
	// contains filtered or unexported fields
}

func NewProxyRoutesInitializer

func NewProxyRoutesInitializer(
	backendErrorHandler func(err error) (proceed bool),
	errorHandler func(err error, w http.ResponseWriter, r *http.Request),
) *ProxyRoutesInitializer

func (*ProxyRoutesInitializer) InitRoutes

func (p *ProxyRoutesInitializer) InitRoutes(router route.Router, config *ServerConfig) error

type ProxyServiceConfig

type ProxyServiceConfig struct {
	Method        string            `hcl:"method,optional"`
	PathTemplate  string            `hcl:"path_template,label"`
	Backend       BackendConfig     `hcl:"backend,block"`
	FlushInterval time.Duration     `hcl:"flush_interval,optional"`
	SetHeader     map[string]string `hcl:"set_header,optional"`
	Transformer   DynamicConfig     `hcl:"transformer,block"`
}

type RootConfig

type RootConfig struct {
	LogLevel string          `hcl:"log_level,optional"`
	Servers  []*ServerConfig `hcl:"server,block"`
}

func ParseConfig

func ParseConfig(filename string) (*RootConfig, error)

type ServerConfig

type ServerConfig struct {
	Name           string                 `hcl:"name,label"`
	ListenAddress  string                 `hcl:"listen"`
	ReadTimeout    time.Duration          `hcl:"read_timeout,optional"`
	WriteTimeout   time.Duration          `hcl:"write_timeout,optional"`
	IdleTimeout    time.Duration          `hcl:"idle_timeout,optional"`
	ProxyServices  []*ProxyServiceConfig  `hcl:"proxy_service,block"`
	StaticServices []*StaticServiceConfig `hcl:"static_service,block"`
}

type StaticContentRoutesInitializer

type StaticContentRoutesInitializer struct {
}

func NewStaticContentRoutesInitializer

func NewStaticContentRoutesInitializer() *StaticContentRoutesInitializer

func (*StaticContentRoutesInitializer) InitRoutes

func (s *StaticContentRoutesInitializer) InitRoutes(router route.Router, config *ServerConfig) error

type StaticServiceConfig

type StaticServiceConfig struct {
	Method       string            `hcl:"method,optional"`
	PathTemplate string            `hcl:"path_template,label"`
	SetHeader    map[string]string `hcl:"set_header,optional"`
	ResponseCode int               `hcl:"response_code"`
	Content      string            `hcl:"content,optional"`
}

Jump to

Keyboard shortcuts

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