Documentation ¶
Index ¶
Constants ¶
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 is the port number to listen on. Port int `json:"port" yaml:"port" koanf:"port"` // HomeURL is the URL for the UI home page. HomeURL string `json:"homeUrl" yaml:"homeURL" koanf:"homeUrl"` // ServiceURL is the URL for the service and resources endpoints in the UI. ServiceURL string `json:"serviceUrl" yaml:"serviceURL" koanf:"serviceUrl"` // SettingsURL is the URL for the settings endpoint in the UI. SettingsURL string `json:"settingsUrl" yaml:"settingsURL" koanf:"settingsUrl"` // ContextURL is the URL for the context endpoint in the UI. ContextURL string `json:"contextUrl" yaml:"contextUrl" koanf:"contextUrl"` // ContextAreaPrefix sets sub-contexts for replacements in path, header or any other supported place. // // for example: // in-path: // user_id: "fake.ids.int8" ContextAreaPrefix string `json:"contextAreaPrefix" yaml:"contextAreaPrefix" koanf:"contextAreaPrefix"` // DisableUI is a flag whether to disable the UI. DisableUI bool `json:"disableUI" yaml:"disableUI" koanf:"disableUI"` // DisableSpec is a flag whether to disable the Swagger UI. DisableSwaggerUI bool `json:"disableSwaggerUI" yaml:"disableSwaggerUI" koanf:"disableSwaggerUI"` // SchemaProvider is the schema provider to use: kin-openapi or libopenapi. SchemaProvider SchemaProvider `json:"schemaProvider" yaml:"schemaProvider" koanf:"schemaProvider"` // Paths is the paths to various resource directories. Paths *Paths `json:"-" koanf:"-"` // 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 CreateFileStructure bool `koanf:"createFileStructure" json:"createFileStructure" yaml:"createFileStructure"` Editor *EditorConfig `koanf:"editor" json:"editor" yaml:"editor"` }
AppConfig is the app configuration.
func NewDefaultAppConfig ¶
NewDefaultAppConfig creates a new default app config in case the config file is missing, not found or any other error.
func (*AppConfig) IsValidPrefix ¶
IsValidPrefix returns true if the prefix is not a reserved URL.
type Config ¶
type Config struct { // App is the app config. App *AppConfig `koanf:"app" json:"app" yaml:"app"` // 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. Services map[string]*ServiceConfig `koanf:"services" json:"services" yaml:"services"` BaseDir string `koanf:"-"` // contains filtered or unexported fields }
func MustConfig ¶
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 ¶
NewConfigFromContent creates a new config from a YAML file content.
func NewDefaultConfig ¶
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) 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.
type EditorConfig ¶
type ParseConfig ¶
type ParseConfig struct { // MaxLevels is the maximum level to parse. MaxLevels int `koanf:"maxLevels" json:"maxLevels" yaml:"maxLevels"` // MaxRecursionLevels is the maximum level to parse recursively. // 0 means no recursion: property will get nil value. MaxRecursionLevels int `koanf:"maxRecursionLevels" json:"maxRecursionLevels" yaml:"maxRecursionLevels"` // OnlyRequired is a flag whether to include only required fields. // If the spec contains deep references, this might significantly speed up parsing. OnlyRequired bool `koanf:"onlyRequired" json:"onlyRequired" yaml:"onlyRequired"` }
func NewParseConfig ¶
func NewParseConfig() *ParseConfig
type Paths ¶
type Paths struct { Base string Resources string Data 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.
type SchemaProvider ¶
type SchemaProvider string
const ( KinOpenAPIProvider SchemaProvider = "kin-openapi" LibOpenAPIProvider SchemaProvider = "libopenapi" DefaultSchemaProvider SchemaProvider = LibOpenAPIProvider )
type ServiceCacheConfig ¶
type ServiceCacheConfig struct { // Avoid multiple schema parsing by caching the parsed schema. // Default: true Schema bool `koanf:"schema" json:"schema" yaml:"schema"` }
func NewServiceCacheConfig ¶
func NewServiceCacheConfig() *ServiceCacheConfig
type ServiceConfig ¶
type ServiceConfig struct { // Latency is the latency to add to the response. // Latency not used in the services API, only when endpoint queried directly. Latency time.Duration `koanf:"latency" json:"latency" yaml:"latency"` // Errors is the error config. Errors *ServiceError `koanf:"errors" json:"errors" yaml:"errors"` // 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. Contexts []map[string]string `koanf:"contexts" json:"contexts" yaml:"contexts"` // ParseConfig is the config for parsing the OpenAPI spec. ParseConfig *ParseConfig `json:"parseConfig" yaml:"parseConfig" koanf:"parseConfig"` // Validate is the validation config. // It is used to validate the request and/or response outside of the Services API. Validate *ServiceValidateConfig `koanf:"validate" json:"validate" yaml:"validate"` // Cache is the cache config. Cache *ServiceCacheConfig `koanf:"cache" json:"cache" yaml:"cache"` }
func NewServiceConfig ¶
func NewServiceConfig() *ServiceConfig
type ServiceError ¶
type ServiceError struct { // Chance is the chance to return an error. // In the config, it can be set with %-suffix. Chance int `koanf:"chance" json:"chance" yaml:"chance"` // 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. Codes map[int]int `koanf:"codes" json:"codes" yaml:"codes"` // contains filtered or unexported fields }
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 is a flag whether to validate the request. // Default: true Request bool `koanf:"request" json:"request" yaml:"request"` // Response is a flag whether to validate the response. // Default: false Response bool `koanf:"response" json:"response" yaml:"response"` }
func NewServiceValidateConfig ¶
func NewServiceValidateConfig() *ServiceValidateConfig