config

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RootServiceName is the name and location in the service directory of the service without a name.
	RootServiceName = ".root"

	// RootOpenAPIName is the name and location of the OpenAPI service without a name.
	RootOpenAPIName = ".openapi"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Port                int            `json:"port" yaml:"port" koanf:"port"`
	HomeURL             string         `json:"homeUrl" yaml:"homeURL" koanf:"homeUrl"`
	ServiceURL          string         `json:"serviceUrl" yaml:"serviceURL" koanf:"serviceUrl"`
	SettingsURL         string         `json:"settingsUrl" yaml:"settingsURL" koanf:"settingsUrl"`
	ContextURL          string         `json:"contextUrl" yaml:"contextUrl" koanf:"contextUrl"`
	ContextAreaPrefix   string         `json:"contextAreaPrefix" yaml:"contextAreaPrefix" koanf:"contextAreaPrefix"`
	DisableUI           bool           `json:"disableUI" yaml:"disableUI" koanf:"disableUI"`
	DisableSwaggerUI    bool           `json:"disableSwaggerUI" yaml:"disableSwaggerUI" koanf:"disableSwaggerUI"`
	SchemaProvider      SchemaProvider `json:"schemaProvider" yaml:"schemaProvider" koanf:"schemaProvider"`
	Paths               *Paths         `json:"-" koanf:"-"`
	CreateFileStructure bool           `koanf:"createFileStructure" json:"createFileStructure" yaml:"createFileStructure"`
	Editor              *EditorConfig  `koanf:"editor" json:"editor" yaml:"editor"`
}

AppConfig is the app configuration. Port is the port number to listen on. HomeURL is the URL for the UI home page. ServiceURL is the URL for the service and resources endpoints in the UI. SettingsURL is the URL for the settings endpoint in the UI. ContextURL is the URL for the context endpoint in the UI. ContextAreaPrefix sets sub-contexts for replacements in path, header or any other supported place.

for example: in-path:

user_id: "fake:ids.int8"

DisableUI is a flag whether to disable the UI. DisableSpec is a flag whether to disable the Swagger UI. SchemaProvider is the schema provider to use: kin-openapi or libopenapi. Paths is the paths to various resource directories. CreateFileStructure is a flag whether to create the initial resources file structure: contexts, services, etc. It will also copy sample files from the samples directory into services. Default: true

func NewDefaultAppConfig

func NewDefaultAppConfig(baseDir string) *AppConfig

NewDefaultAppConfig creates a new default app config in case the config file is missing, not found or any other error.

func (*AppConfig) IsValidPrefix

func (a *AppConfig) IsValidPrefix(prefix string) bool

IsValidPrefix returns true if the prefix is not a reserved URL.

type Config

type Config struct {
	App      *AppConfig                `koanf:"app" json:"app" yaml:"app"`
	Services map[string]*ServiceConfig `koanf:"services" json:"services" yaml:"services"`
	BaseDir  string                    `koanf:"-"`
	// contains filtered or unexported fields
}

Config is the main configuration struct. App is the app config. Services is a map of service name and the corresponding config. ServiceName is the first part of the path. e.g. /petstore/v1/pets -> petstore in case, there's no service name, the name ".root" will be used.

func MustConfig

func MustConfig(baseDir string) *Config

MustConfig creates a new config from a YAML file path. In case it file does not exist or has incorrect YAML: - it creates a new default config

Koanf has a file watcher, but its easier to control the changes with a manual reload.

func NewConfigFromContent

func NewConfigFromContent(content []byte) (*Config, error)

NewConfigFromContent creates a new config from a YAML file content.

func NewDefaultConfig

func NewDefaultConfig(baseDir string) *Config

NewDefaultConfig creates a new default config in case the config file is missing, not found or any other error.

func (*Config) EnsureConfigValues

func (c *Config) EnsureConfigValues()

EnsureConfigValues ensures that all config values are set.

func (*Config) GetApp

func (c *Config) GetApp() *AppConfig

func (*Config) GetServiceConfig

func (c *Config) GetServiceConfig(service string) *ServiceConfig

GetServiceConfig returns the config for a service. If the service is not found, it returns a default config.

func (*Config) Reload

func (c *Config) Reload()

type EditorConfig

type EditorConfig struct {
	Theme    string `koanf:"theme" json:"theme" yaml:"theme"`
	FontSize int    `koanf:"fontSize" json:"fontSize" yaml:"fontSize"`
}

type HTTPStatusConfig added in v0.1.23

type HTTPStatusConfig struct {
	Exact int    `koanf:"exact" json:"exact" yaml:"exact"`
	Range string `koanf:"range" json:"range" yaml:"range"`
}

func (*HTTPStatusConfig) Is added in v0.1.23

func (s *HTTPStatusConfig) Is(status int) bool

type HttpStatusFailOnConfig added in v0.1.23

type HttpStatusFailOnConfig []HTTPStatusConfig

func (HttpStatusFailOnConfig) Is added in v0.1.23

func (ss HttpStatusFailOnConfig) Is(status int) bool

type ParseConfig

type ParseConfig struct {
	MaxLevels          int  `koanf:"maxLevels" json:"maxLevels" yaml:"maxLevels"`
	MaxRecursionLevels int  `koanf:"maxRecursionLevels" json:"maxRecursionLevels" yaml:"maxRecursionLevels"`
	OnlyRequired       bool `koanf:"onlyRequired" json:"onlyRequired" yaml:"onlyRequired"`
}

ParseConfig defines the parsing configuration for a service. MaxLevels is the maximum level to parse. MaxRecursionLevels is the maximum level to parse recursively. 0 means no recursion: property will get nil value. OnlyRequired is a flag whether to include only required fields. If the spec contains deep references, this might significantly speed up parsing.

func NewParseConfig

func NewParseConfig() *ParseConfig

type Paths

type Paths struct {
	Base              string
	Resources         string
	Data              string
	Callbacks         string
	Contexts          string
	Docs              string
	Samples           string
	Services          string
	ServicesOpenAPI   string
	ServicesFixedRoot string
	UI                string
	ConfigFile        string
}

Paths is a struct that holds all the paths used by the application.

func NewPaths

func NewPaths(baseDir string) *Paths

type SchemaProvider

type SchemaProvider string
const (
	KinOpenAPIProvider    SchemaProvider = "kin-openapi"
	LibOpenAPIProvider    SchemaProvider = "libopenapi"
	DefaultSchemaProvider SchemaProvider = LibOpenAPIProvider
)

type ServiceCacheConfig

type ServiceCacheConfig struct {
	Schema bool `koanf:"schema" json:"schema" yaml:"schema"`
}

ServiceCacheConfig defines the cache configuration for a service. Avoid multiple schema parsing by caching the parsed schema. Default: true

func NewServiceCacheConfig

func NewServiceCacheConfig() *ServiceCacheConfig

type ServiceConfig

type ServiceConfig struct {
	Upstream            *UpstreamConfig        `koanf:"upstream" json:"upstream" yaml:"upstream"`
	Latency             time.Duration          `koanf:"latency" json:"latency" yaml:"latency"`
	Errors              *ServiceError          `koanf:"errors" json:"errors" yaml:"errors"`
	Contexts            []map[string]string    `koanf:"contexts" json:"contexts" yaml:"contexts"`
	ParseConfig         *ParseConfig           `json:"parseConfig" yaml:"parseConfig" koanf:"parseConfig"`
	Validate            *ServiceValidateConfig `koanf:"validate" json:"validate" yaml:"validate"`
	RequestTransformer  string                 `koanf:"requestTransformer" json:"requestTransformer" yaml:"requestTransformer"`
	ResponseTransformer string                 `koanf:"responseTransformer" json:"responseTransformer" yaml:"responseTransformer"`
	Cache               *ServiceCacheConfig    `koanf:"cache" json:"cache" yaml:"cache"`
}

ServiceConfig defines the configuration for a particular service. Latency is the latency to add to the response. Latency not used in the services API, only when endpoint queried directly. Errors is the error config. Contexts is the list of contexts to use for replacements. It is a map of context name defined either in the UI or filename without extension. You can refer to the name when building aliases. ParseConfig is the config for parsing the OpenAPI spec. Validate is the validation config. It is used to validate the request and/or response outside the Services API. ResponseTransformer is a callback function name which should exist inside callbacks directory and be visible to the plugin. Cache is the cache config.

func NewServiceConfig

func NewServiceConfig() *ServiceConfig

type ServiceError

type ServiceError struct {
	Chance int         `koanf:"chance" json:"chance" yaml:"chance"`
	Codes  map[int]int `koanf:"codes" json:"codes" yaml:"codes"`
	// contains filtered or unexported fields
}

ServiceError defines the error configuration for a service. Chance is the chance to return an error. In the config, it can be set with %-suffix. Codes is a map of error codes and their weights if Chance > 0. If no error codes are specified, it returns a 500 error code.

func NewServiceErrorConfig

func NewServiceErrorConfig() *ServiceError

func (*ServiceError) GetError

func (s *ServiceError) GetError() int

GetError returns an error code based on the chance and error weights. If no error weights are specified, it returns a 500 error code. If the chance is 0, it returns 0.

type ServiceValidateConfig

type ServiceValidateConfig struct {
	Request  bool `koanf:"request" json:"request" yaml:"request"`
	Response bool `koanf:"response" json:"response" yaml:"response"`
}

ServiceValidateConfig defines the validation configuration for a service. Request is a flag whether to validate the request. Default: true Response is a flag whether to validate the response. Default: false

func NewServiceValidateConfig

func NewServiceValidateConfig() *ServiceValidateConfig

type UpstreamConfig added in v0.1.23

type UpstreamConfig struct {
	URL     string                `koanf:"url" json:"url" yaml:"url"`
	Headers map[string]string     `koanf:"headers" json:"headers" yaml:"headers"`
	FailOn  *UpstreamFailOnConfig `koanf:"failOn" json:"failOn" yaml:"failOn"`
}

type UpstreamFailOnConfig added in v0.1.23

type UpstreamFailOnConfig struct {
	TimeOut    time.Duration          `koanf:"timeout" json:"timeout" yaml:"timeout"`
	HTTPStatus HttpStatusFailOnConfig `koanf:"httpStatus" json:"httpStatus" yaml:"httpStatus"`
}

Jump to

Keyboard shortcuts

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