Documentation ¶
Index ¶
- Constants
- Variables
- func ComposeFileSavePath(descr *ServiceDescription, paths *config.Paths) string
- func ComposeOpenAPISavePath(descr *ServiceDescription, baseDir string) string
- func ConditionalLoggingMiddleware(cfg *config.Config) func(http.Handler) http.Handler
- func CreateResponseMiddleware(params *MiddlewareParams) func(http.Handler) http.Handler
- func CreateUpstreamRequestMiddleware(params *MiddlewareParams) func(http.Handler) http.Handler
- func GetJSONPayload[T any](req *http.Request) (*T, error)
- func HandleErrorAndLatency(svcConfig *config.ServiceConfig, w http.ResponseWriter) bool
- func MustFileStructure(paths *config.Paths) error
- type APIResponse
- type App
- type BaseHandler
- type BaseResponse
- type BufferedWriter
- type ContextHandler
- type ContextListResponse
- type GenerateResponse
- type HomeHandler
- type JSONResponse
- type MiddlewareParams
- type OpenAPIHandler
- type ResourceGeneratePayload
- type ResourceResponse
- type RouteDescription
- type RouteDescriptions
- type RouteRegister
- type Router
- func (r *Router) AddService(item *ServiceItem)
- func (r *Router) GetContexts() map[string]map[string]any
- func (r *Router) GetDefaultContexts() []map[string]string
- func (r *Router) GetServices() map[string]*ServiceItem
- func (r *Router) RemoveContext(name string)
- func (r *Router) RemoveService(name string)
- func (r *Router) SetContexts(contexts map[string]map[string]any, defaultContexts []map[string]string) *Router
- func (r *Router) SetServices(services map[string]*ServiceItem) *Router
- type SavedResourceResponse
- type ServiceDescription
- type ServiceEmbedded
- type ServiceHandler
- type ServiceItem
- type ServiceItemResponse
- type ServiceListResponse
- type ServicePayload
- type ServiceResourcesResponse
- type SettingsHandler
- type SimpleResponse
Constants ¶
const ( OpenAPIRouteType = "openapi" FixedRouteType = "fixed" )
Variables ¶
var ( ErrServiceNotFound = errors.New("service not found") ErrResourceNotFound = errors.New("resource not found") ErrResourceMethodNotFound = errors.New("resource method not found") ErrOpenAPISpecIsEmpty = errors.New("OpenAPI spec is empty") ErrInvalidHTTPVerb = errors.New("invalid HTTP verb") ErrInvalidURLResource = errors.New("invalid URL resource") ErrReservedPrefix = errors.New("reserved prefix") ErrOnlyFixedResourcesAllowedEditing = errors.New("only fixed resources are allowed editing") ErrGettingFileFromURL = errors.New("error getting file from url") )
Functions ¶
func ComposeFileSavePath ¶
func ComposeFileSavePath(descr *ServiceDescription, paths *config.Paths) string
ComposeFileSavePath composes a save path for a file.
func ComposeOpenAPISavePath ¶
func ComposeOpenAPISavePath(descr *ServiceDescription, baseDir string) string
ComposeOpenAPISavePath composes a save path for an OpenAPI specification. The resulting filename is always index.<spec extension>.
func ConditionalLoggingMiddleware ¶
ConditionalLoggingMiddleware is a middleware that conditionally can disable logger. For example, in tests or when fetching static files.
func CreateResponseMiddleware ¶ added in v0.1.23
func CreateResponseMiddleware(params *MiddlewareParams) func(http.Handler) http.Handler
CreateResponseMiddleware is a method on the Router to create a middleware
func CreateUpstreamRequestMiddleware ¶ added in v0.1.23
func CreateUpstreamRequestMiddleware(params *MiddlewareParams) func(http.Handler) http.Handler
func GetJSONPayload ¶
GetJSONPayload parses JSON payload from the request body into the given type.
func HandleErrorAndLatency ¶
func HandleErrorAndLatency(svcConfig *config.ServiceConfig, w http.ResponseWriter) bool
HandleErrorAndLatency handles error and latency defined in the service configuration. Returns true if error was handled.
func MustFileStructure ¶
MustFileStructure creates the necessary directories and files
Types ¶
type APIResponse ¶
type APIResponse struct {
*BaseResponse
}
APIResponse is a response type for API responses.
func NewAPIResponse ¶
func NewAPIResponse(w http.ResponseWriter) *APIResponse
NewAPIResponse creates a new APIResponse instance.
func (*APIResponse) Send ¶
func (r *APIResponse) Send(data []byte)
Send sends the data to the client.
func (*APIResponse) WithHeader ¶
func (r *APIResponse) WithHeader(key string, value string) *APIResponse
WithHeader adds a header to the response.
func (*APIResponse) WithStatusCode ¶
func (r *APIResponse) WithStatusCode(code int) *APIResponse
WithStatusCode sets the status code of the response.
type App ¶
App is the main application struct
func (*App) AddBluePrint ¶
func (a *App) AddBluePrint(bluePrint RouteRegister) error
AddBluePrint adds a new blueprint to the application.
type BaseHandler ¶
type BaseHandler struct { }
BaseHandler is a base handler type to be embedded in other handlers.
func NewBaseHandler ¶
func NewBaseHandler() *BaseHandler
func (*BaseHandler) Error ¶
func (h *BaseHandler) Error(code int, message string, w http.ResponseWriter)
Error sends an error response.
func (*BaseHandler) JSONResponse ¶
func (h *BaseHandler) JSONResponse(w http.ResponseWriter) *JSONResponse
JSONResponse is a response type for JSON responses.
func (*BaseHandler) Response ¶
func (h *BaseHandler) Response(w http.ResponseWriter) *APIResponse
Response is a response type for API responses.
func (*BaseHandler) Success ¶
func (h *BaseHandler) Success(message string, w http.ResponseWriter)
Success sends a Success response.
type BaseResponse ¶
type BaseResponse struct {
// contains filtered or unexported fields
}
BaseResponse is a base response type.
type BufferedWriter ¶
type BufferedWriter struct {
// contains filtered or unexported fields
}
BufferedWriter is a writer that captures the response. Used to capture the template execution result.
func NewBufferedResponseWriter ¶
func NewBufferedResponseWriter() *BufferedWriter
NewBufferedResponseWriter creates a new buffered writer.
func (*BufferedWriter) Header ¶
func (bw *BufferedWriter) Header() http.Header
Header returns the header.
func (*BufferedWriter) Write ¶
func (bw *BufferedWriter) Write(p []byte) (int, error)
Write writes the data to the buffer.
func (*BufferedWriter) WriteHeader ¶
func (bw *BufferedWriter) WriteHeader(statusCode int)
WriteHeader writes the status code.
type ContextHandler ¶
type ContextHandler struct { *BaseHandler // contains filtered or unexported fields }
ContextHandler handles context routes.
type ContextListResponse ¶
type ContextListResponse struct {
Items []string `json:"items"`
}
ContextListResponse is a response for context list.
type GenerateResponse ¶
type GenerateResponse struct { Request *openapi.GeneratedRequest `json:"request"` Response *openapi.GeneratedResponse `json:"response"` }
type HomeHandler ¶
type HomeHandler struct { *BaseHandler // contains filtered or unexported fields }
HomeHandler handles home routes.
type JSONResponse ¶
type JSONResponse struct {
*BaseResponse
}
JSONResponse is a response type for JSON responses.
func NewJSONResponse ¶
func NewJSONResponse(w http.ResponseWriter) *JSONResponse
NewJSONResponse creates a new JSONResponse instance.
func (*JSONResponse) Send ¶
func (r *JSONResponse) Send(data any)
Send sends the data as JSON to the client. WriteHeader must be called before any writing happens and just once.
func (*JSONResponse) WithHeader ¶
func (r *JSONResponse) WithHeader(key string, value string) *JSONResponse
WithHeader adds a header to the response.
func (*JSONResponse) WithStatusCode ¶
func (r *JSONResponse) WithStatusCode(code int) *JSONResponse
WithStatusCode sets the status code of the response.
type MiddlewareParams ¶ added in v0.1.23
type OpenAPIHandler ¶
type OpenAPIHandler struct { *BaseHandler // contains filtered or unexported fields }
OpenAPIHandler handles OpenAPI routes serve.
type ResourceGeneratePayload ¶
ResourceGeneratePayload is a payload for generating resources. It contains a map of replacements. It is used only with generating resources endpoint. It's merged together with contexts but has higher priority.
type ResourceResponse ¶
type RouteDescription ¶
type RouteDescription struct { Method string `json:"method"` Path string `json:"path"` Type string `json:"type"` ContentType string `json:"contentType"` Overwrites bool `json:"overwrites"` File *connexions.FileProperties `json:"-"` }
RouteDescription describes a route for the UI Application. Path is relative to the service prefix.
type RouteDescriptions ¶
type RouteDescriptions []*RouteDescription
RouteDescriptions is a slice of RouteDescription. Allows to add custom methods.
func (RouteDescriptions) Sort ¶
func (rs RouteDescriptions) Sort()
Sort sorts the routes by path and method. The order is: GET, POST, other methods (alphabetically)
type RouteRegister ¶
type Router ¶
type Router struct { *chi.Mux // Config is a pointer to the global Config instance. Config *config.Config // contains filtered or unexported fields }
Router is a wrapper around chi.Mux that adds some extra functionality.
func (*Router) AddService ¶
func (r *Router) AddService(item *ServiceItem)
func (*Router) GetDefaultContexts ¶
func (*Router) GetServices ¶
func (r *Router) GetServices() map[string]*ServiceItem
func (*Router) RemoveContext ¶
RemoveContext removes registered context namespace from the router. Removing it from the service configurations seems not needed at the moment as it won't affect any resolving.
func (*Router) RemoveService ¶
func (*Router) SetContexts ¶
func (*Router) SetServices ¶
func (r *Router) SetServices(services map[string]*ServiceItem) *Router
type SavedResourceResponse ¶
type ServiceDescription ¶
ServiceDescription is a struct created from the service payload to facilitate file path composition.
type ServiceEmbedded ¶
type ServiceEmbedded struct {
Name string `json:"name"`
}
type ServiceHandler ¶
type ServiceHandler struct { *BaseHandler // contains filtered or unexported fields }
ServiceHandler handles service routes.
type ServiceItem ¶
type ServiceItem struct { Name string `json:"name"` Routes RouteDescriptions `json:"routes"` OpenAPIFiles []*connexions.FileProperties `json:"-"` // contains filtered or unexported fields }
ServiceItem represents a service with the route collection. Service can hold multiple OpenAPI specs.
func (*ServiceItem) AddOpenAPIFile ¶
func (i *ServiceItem) AddOpenAPIFile(file *connexions.FileProperties)
AddOpenAPIFile adds OpenAPI file to the service.
func (*ServiceItem) AddRoutes ¶
func (i *ServiceItem) AddRoutes(routes RouteDescriptions)
AddRoutes adds routes to the service. There's no check for duplicates.
type ServiceItemResponse ¶
type ServiceListResponse ¶
type ServiceListResponse struct {
Items []*ServiceItemResponse `json:"items"`
}
type ServicePayload ¶
type ServicePayload struct { IsOpenAPI bool `json:"isOpenApi"` Method string `json:"method"` Path string `json:"path"` Response []byte `json:"response"` ContentType string `json:"contentType"` File *connexions.UploadedFile `json:"file"` URL string `json:"url"` }
ServicePayload is a struct that represents a new service payload.
type ServiceResourcesResponse ¶
type ServiceResourcesResponse struct { Service *ServiceEmbedded `json:"service"` Endpoints RouteDescriptions `json:"endpoints"` OpenAPISpecNames []string `json:"openapiSpecNames"` }
type SettingsHandler ¶
type SettingsHandler struct { *BaseHandler // contains filtered or unexported fields }
SettingsHandler handles settings routes.
type SimpleResponse ¶
SimpleResponse is a simple response type to indicate the success of an operation.