web

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func API

API constructs a handler for the restQL query related endpoints

func CalculateStatusCode

func CalculateStatusCode(queryResult domain.Resources) int

CalculateStatusCode returns the greater status in all statement results to be used as the response status code. It applies the following normalization to statement result status codes:

0 => 500 204 => 200 201 => 200

func Debug

Debug constructs a handler for profiling endpoints

func Health

func Health(log restql.Logger, cfg *conf.Config) fasthttp.RequestHandler

Health constructs a handler for system checks endpoints

func Respond

func Respond(ctx *fasthttp.RequestCtx, data interface{}, statusCode int, headers map[string]string) error

Respond write the information back to the client.

func RespondError

func RespondError(ctx *fasthttp.RequestCtx, err error, toStatusCode map[error]int) error

RespondError translate the error and write it back to the client.

Types

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse is the form used for API responses from failures in the API.

type QueryResponse

type QueryResponse struct {
	StatusCode int
	Body       map[string]StatementResult
	Headers    map[string]string
}

QueryResponse represents the client format of the query result

func MakeQueryResponse

func MakeQueryResponse(queryResult domain.Resources, debug bool) (QueryResponse, error)

MakeQueryResponse create a query execution response for the client.

type StatementDebugging

type StatementDebugging struct {
	Method          string                 `json:"method,omitempty"`
	URL             string                 `json:"url,omitempty"`
	RequestHeaders  map[string]string      `json:"request-headers,omitempty"`
	ResponseHeaders map[string]string      `json:"response-headers,omitempty"`
	Params          map[string]interface{} `json:"params,omitempty"`
	RequestBody     interface{}            `json:"request-body,omitempty"`
	ResponseTime    int64                  `json:"response-time,omitempty"`
}

StatementDebugging represents the client format of debugging information

type StatementDetails

type StatementDetails struct {
	Status   int                 `json:"status"`
	Success  bool                `json:"success"`
	Metadata StatementMetadata   `json:"metadata"`
	Debug    *StatementDebugging `json:"debug,omitempty"`
}

StatementDetails represents the client format of the statement details

type StatementMetadata

type StatementMetadata struct {
	IgnoreErrors string `json:"ignore-errors,omitempty"`
}

StatementMetadata represents the client format of metadata

type StatementResult

type StatementResult struct {
	Details interface{} `json:"details"`
	Result  interface{} `json:"result,omitempty"`
}

StatementResult represents the client format of the statement result

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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