goproxy

package
v0.0.0-...-b01aa8d Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpstreamSelfServiceEndpoint = "/task"
	UpstreamHealthEndpoint      = "/health"
	DefaultUpstreamScheme       = "https"
	DefaultTimeout              = time.Second * 300
)

Constants used by service

Variables

View Source
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

View Source
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

View Source
var (
	// ErrCertLoadFailed will be returned in case of upstream server is un healthy
	ErrCertLoadFailed = errors.New("failed to load certificate")
)

Certs Error

View Source
var (
	// ErrTypeAssertion will be returned in case of unknown endpoint
	ErrTypeAssertion = errors.New("failed to type assert")
)

Endpoint Errors

View Source
var (
	ErrUnknown = 3999
)

Unknown Error

View Source
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

func MakeHTTPHandler(endpoints Endpoints) (http.Handler, http.Handler)

MakeHTTPHandler returns an http handler for the endpoints

func MakeTLSClient

func MakeTLSClient(caFiles []string) (*http.Client, error)

MakeTLSClient to create a tls client

func ValidHTTPStatusCode

func ValidHTTPStatusCode(code string) string

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

func MakeEndpointMiddlewares(endpoints Endpoints, logger log.Logger) Endpoints

MakeEndpointMiddlewares orchastrate all required middlewares

func MakeProxyServiceEndpoints

func MakeProxyServiceEndpoints(psvc Service) Endpoints

MakeProxyServiceEndpoints wrapper for creating endpoints

type Errorify

type Errorify struct {
	Status  int
	Err     error
	Message string
}

Errorify used to represent http status and error

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

type Middleware func(service Service) Service

Middleware acts as wrapper

func ServiceLoggingMiddleware

func ServiceLoggingMiddleware(logger log.Logger) Middleware

ServiceLoggingMiddleware is used for logging on service layer.

type QueryString

type QueryString struct {
	IsBeta bool
}

QueryString .

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

func NewService

func NewService(_ context.Context, upstreamPort string, upstreamClient *http.Client) (Service, error)

NewService creates new service

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

Jump to

Keyboard shortcuts

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