Documentation ¶
Index ¶
- Constants
- Variables
- func EndpointLoggingMiddleware(logger log.Logger) endpoint.Middleware
- func EndpointRequestValidationMiddleware() endpoint.Middleware
- func MakeHTTPHandler(endpoints Endpoints) (http.Handler, http.Handler)
- func MakeTLSClient(caFiles []string) (*http.Client, error)
- func ValidHTTPStatusCode(code string) string
- type Body
- type Endpoints
- type Errorify
- type Headers
- type HealthCheckRequest
- type HealthCheckResponse
- type Middleware
- type QueryString
- type ReceiveAndForwardRequest
- type ReceiveAndForwardResponse
- type Service
- type VersionRequest
- type VersionResponse
Constants ¶
const ( UpstreamSelfServiceEndpoint = "/task" UpstreamHealthEndpoint = "/health" DefaultUpstreamScheme = "https" DefaultTimeout = time.Second * 300 )
Constants used by service
Variables ¶
var ( //ErrInternalServerError will be returned in case of http 5xx errors ErrInternalServerError = errors.New("internal server error") //ErrInvalidContentType will be returned in case of content type is not application/json ErrInvalidContentType = errors.New("invalid content type") //ErrMissingTargetURL will be returned in case of target host is not empty ErrMissingTargetURL = errors.New("missing target URL in request body") //ErrJSONUnMarshall will be returned in case of failed json parsing. ErrJSONUnMarshall = errors.New("failed to parse json") //ErrEmptyRequestBody will be returned in case of request body is empty ErrEmptyRequestBody = errors.New("empty request body") //ErrReadingResponseBody will be returned in case of response body is empty ErrReadingResponseBody = errors.New("empty response body") //ErrMalformedRequest will be returned in case of request sent is invalid ErrMalformedRequest = errors.New("request not formed correctly") // ErrRequestTimeout will be returned in case of request timed out ErrRequestTimeout = errors.New("request timeout") // ErrFailedCreatingNewRequest ErrFailedCreatingNewRequest = errors.New("failed creating new request") )
Transport Errors
var ( // ErrUpstreamHealthCheckFailed will be returned in case of upstream server is un healthy ErrUpstreamHealthCheckFailed = errors.New("upstream health check failed") // ErrBadUpstreamURL ErrBadUpstreamURL = errors.New("upstream host not found") )
Service Errors
var ( // ErrCertLoadFailed will be returned in case of upstream server is un healthy ErrCertLoadFailed = errors.New("failed to load certificate") )
Certs Error
var ( // ErrTypeAssertion will be returned in case of unknown endpoint ErrTypeAssertion = errors.New("failed to type assert") )
Endpoint Errors
var (
ErrUnknown = 3999
)
Unknown Error
var ProxyVersion string
ProxyVersion Information
Functions ¶
func EndpointLoggingMiddleware ¶
func EndpointLoggingMiddleware(logger log.Logger) endpoint.Middleware
EndpointLoggingMiddleware is used for logging on endpoint layer.
func EndpointRequestValidationMiddleware ¶
func EndpointRequestValidationMiddleware() endpoint.Middleware
EndpointRequestValidationMiddleware is used for Request Validation on endpoint layer.
func MakeHTTPHandler ¶
MakeHTTPHandler returns an http handler for the endpoints
func MakeTLSClient ¶
MakeTLSClient to create a tls client
func ValidHTTPStatusCode ¶
ValidHTTPStatusCode takes in a string and return true if the string can be represented as valid http status code
Types ¶
type Body ¶
type Body struct { TargetURL string `json:"target"` Task *json.RawMessage `json:"task"` }
Body .
type Endpoints ¶
type Endpoints struct { ReceiveAndForward endpoint.Endpoint HealthCheck endpoint.Endpoint Version endpoint.Endpoint }
Endpoints for every service method
func MakeEndpointMiddlewares ¶
MakeEndpointMiddlewares orchastrate all required middlewares
func MakeProxyServiceEndpoints ¶
MakeProxyServiceEndpoints wrapper for creating endpoints
type Headers ¶
type Headers struct { Authorization string `json:"Authorization,omitempty"` RequestID string `json:"x-request-id,omitempty"` ContentType string `json:"Content-Type,omitempty"` XForwardedFor string `json:"X-Forwarded-For"` }
Headers .
type HealthCheckRequest ¶
type HealthCheckRequest struct{}
HealthCheckRequest is request structure for /healthcheck
type HealthCheckResponse ¶
type HealthCheckResponse struct {
Status string `json:"status"`
}
HealthCheckResponse is response for /healthcheck endpoint
type Middleware ¶
Middleware acts as wrapper
func ServiceLoggingMiddleware ¶
func ServiceLoggingMiddleware(logger log.Logger) Middleware
ServiceLoggingMiddleware is used for logging on service layer.
type ReceiveAndForwardRequest ¶
type ReceiveAndForwardRequest struct { Headers QueryString Body }
ReceiveAndForwardRequest is request structure for /task
type ReceiveAndForwardResponse ¶
type ReceiveAndForwardResponse struct { Status int `json:"status,omitempty"` Message *json.RawMessage `json:"message,omitempty"` Reason string `json:"reason,omitempty"` Error int `json:"error,omitempty"` ErrorDescription error }
ReceiveAndForwardResponse is response structure for /task
type Service ¶
type Service interface { ReceiveAndForward(ctx context.Context, request ReceiveAndForwardRequest) (ReceiveAndForwardResponse, error) HealthCheck(ctx context.Context) (HealthCheckResponse, error) Version(ctx context.Context) (VersionResponse, error) }
Service defines a nss proxy interface
type VersionRequest ¶
type VersionRequest struct{}
VersionRequest is request structure for /Version endpoint
type VersionResponse ¶
type VersionResponse struct {
GoproxyVersion string `json:"goproxy,omitempty"`
}
VersionResponse is response for /Version endpoint