api

package
v0.0.0-...-849bbb1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package api provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.0 DO NOT EDIT.

Index

Constants

View Source
const (
	MaxRatio = 100_000
)

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(router gin.IRouter, si ServerInterface)

RegisterHandlers creates http.Handler with routing matching OpenAPI spec.

func RegisterHandlersWithOptions

func RegisterHandlersWithOptions(router gin.IRouter, si ServerInterface, options GinServerOptions)

RegisterHandlersWithOptions creates http.Handler with additional options

func ValidatePath

func ValidatePath(path string) error

Types

type APIResponse

type APIResponse struct {
	Body          string        `json:"body"`
	Calls         []CallOutcome `json:"calls"`
	LatencyMillis int           `json:"latency_millis" yaml:"latency_millis"`
	Status        int           `json:"status"`
}

APIResponse defines model for APIResponse.

type CallDef

type CallDef struct {
	// IgnoreStatus don't consider the status code when using `inherit`
	IgnoreStatus bool `json:"ignore_status" yaml:"ignore_status"`

	// TrimBody don't include the response body in the response of the parent API
	TrimBody bool   `json:"trim_body" yaml:"trim_body"`
	Url      string `json:"url"`
}

CallDef a list of urls that we'd call get on

func (CallDef) Validate

func (a CallDef) Validate() error

type CallOutcome

type CallOutcome struct {
	Body   *string `json:"body,omitempty"`
	Status int     `json:"status"`
	Url    string  `json:"url"`
}

CallOutcome defines model for CallOutcome.

type ConfigureAPI

type ConfigureAPI struct {
	// Body The content to return in the response
	Body string    `json:"body"`
	Call []CallDef `json:"call"`

	// Latency Extra latency to pick from a uniform distribution to add to this call
	Latency *LatencyDef `json:"latency,omitempty"`

	// Statuses The status codes to return, it will return with the probability passed in,
	// If the sum of the ratio of the entries doesn't add to 100000 it will complete with the status
	// of the children calls or 200 if there were no children calls
	Statuses []StatusDef `json:"statuses"`
}

ConfigureAPI defines model for ConfigureAPI.

func (*ConfigureAPI) Normalize

func (a *ConfigureAPI) Normalize()

func (*ConfigureAPI) Validate

func (a *ConfigureAPI) Validate() error

type ConfigureAPIItem

type ConfigureAPIItem struct {
	Conf ConfigureAPI `json:"conf"`
	Path string       `json:"path"`
}

ConfigureAPIItem defines model for ConfigureAPIItem.

func (*ConfigureAPIItem) Normalize

func (a *ConfigureAPIItem) Normalize()

func (*ConfigureAPIItem) Validate

func (a *ConfigureAPIItem) Validate() error

type ConfigureApiJSONRequestBody

type ConfigureApiJSONRequestBody = ConfigureAPI

ConfigureApiJSONRequestBody defines body for ConfigureApi for application/json ContentType.

type DegradeHealthJSONRequestBody

type DegradeHealthJSONRequestBody = Health

DegradeHealthJSONRequestBody defines body for DegradeHealth for application/json ContentType.

type DegradeReadyJSONRequestBody

type DegradeReadyJSONRequestBody = Health

DegradeReadyJSONRequestBody defines body for DegradeReady for application/json ContentType.

type ErrorResponse

type ErrorResponse struct {
	Details           string               `json:"details"`
	InvalidParameters *[]InvalidParameters `json:"invalid_parameters,omitempty" yaml:"invalid_parameters"`
	Status            float32              `json:"status"`
}

ErrorResponse defines model for ErrorResponse.

func BadRequestResponse

func BadRequestResponse(err error) ErrorResponse

type GinServerOptions

type GinServerOptions struct {
	BaseURL      string
	Middlewares  []MiddlewareFunc
	ErrorHandler func(*gin.Context, error, int)
}

GinServerOptions provides options for the Gin server.

type Health

type Health struct {
	Status int `json:"status"`
}

Health defines model for Health.

func (*Health) Validate

func (a *Health) Validate() error

type HomeResponse

type HomeResponse struct {
	Commit   string `json:"commit"`
	Hostname string `json:"hostname"`
	Target   string `json:"target"`
	Version  string `json:"version"`
}

HomeResponse defines model for HomeResponse.

type InvalidParameters

type InvalidParameters struct {
	Field  string `json:"field"`
	Reason string `json:"reason"`
}

InvalidParameters defines model for InvalidParameters.

type LatencyDef

type LatencyDef struct {
	MaxMillis int `json:"max_millis" yaml:"max_millis"`
	MinMillis int `json:"min_millis" yaml:"min_millis"`
}

LatencyDef Extra latency to pick from a uniform distribution to add to this call

func (*LatencyDef) Validate

func (a *LatencyDef) Validate() error

type MiddlewareFunc

type MiddlewareFunc func(c *gin.Context)

type Normalizer

type Normalizer interface {
	Normalize()
}

type ParamsAPI

type ParamsAPI struct {
	Apis []ConfigureAPIItem `json:"apis"`
}

ParamsAPI defines model for ParamsAPI.

func (*ParamsAPI) Normalize

func (a *ParamsAPI) Normalize()

func (*ParamsAPI) Validate

func (a *ParamsAPI) Validate() error

type Reloader

type Reloader interface {
	Reload(ctx context.Context, apis ParamsAPI) error
}

type ServerInterface

type ServerInterface interface {
	// home
	// (GET /)
	Home(c *gin.Context)
	// list all apis registered
	// (GET /api/dynamic)
	ParamsApi(c *gin.Context)
	// hello
	// (GET /api/dynamic/{path})
	GetApi(c *gin.Context, path string)
	// set api params
	// (POST /api/dynamic/{path})
	ConfigureApi(c *gin.Context, path string)
	// healthcheck
	// (GET /health)
	Health(c *gin.Context)
	// change healthcheck response
	// (POST /health)
	DegradeHealth(c *gin.Context)
	// healthcheck
	// (GET /ready)
	Ready(c *gin.Context)
	// change healthcheck response
	// (POST /ready)
	DegradeReady(c *gin.Context)
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler            ServerInterface
	HandlerMiddlewares []MiddlewareFunc
	ErrorHandler       func(*gin.Context, error, int)
}

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) ConfigureApi

func (siw *ServerInterfaceWrapper) ConfigureApi(c *gin.Context)

ConfigureApi operation middleware

func (*ServerInterfaceWrapper) DegradeHealth

func (siw *ServerInterfaceWrapper) DegradeHealth(c *gin.Context)

DegradeHealth operation middleware

func (*ServerInterfaceWrapper) DegradeReady

func (siw *ServerInterfaceWrapper) DegradeReady(c *gin.Context)

DegradeReady operation middleware

func (*ServerInterfaceWrapper) GetApi

func (siw *ServerInterfaceWrapper) GetApi(c *gin.Context)

GetApi operation middleware

func (*ServerInterfaceWrapper) Health

func (siw *ServerInterfaceWrapper) Health(c *gin.Context)

Health operation middleware

func (*ServerInterfaceWrapper) Home

func (siw *ServerInterfaceWrapper) Home(c *gin.Context)

Home operation middleware

func (*ServerInterfaceWrapper) ParamsApi

func (siw *ServerInterfaceWrapper) ParamsApi(c *gin.Context)

ParamsApi operation middleware

func (*ServerInterfaceWrapper) Ready

func (siw *ServerInterfaceWrapper) Ready(c *gin.Context)

Ready operation middleware

type StatusDef

type StatusDef struct {
	// Code The status code to return. `inherit` is a special key that will return whatever `call` leads to
	Code string `json:"code"`

	// Ratio The proportion of the requests out of 100k that should return this status
	Ratio int `json:"ratio"`
}

StatusDef defines model for StatusDef.

func (StatusDef) Validate

func (a StatusDef) Validate() error

Jump to

Keyboard shortcuts

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