web

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package web provides abstraction to http web functionalies

Index

Constants

View Source
const (
	// HTTPKeyRequestID contains key to HTTP Header requestID.
	HTTPKeyRequestID = "X-Request-ID"

	// HTTPKeyTraceID contains key to HTTP Header traceID.
	HTTPKeyTraceID = "X-Trace-ID"
)

Variables

View Source
var (
	// ContextKeyRequestID to store/obtains requestID from context.
	ContextKeyRequestID = ContextKey("reqID")

	// ContextKeyHeader to store/obtains original http header from downstream.
	ContextKeyHeader = ContextKey("header")

	// ContextKeyTraceID to store/obtains traceID from downstream context.
	ContextKeyTraceID = ContextKey("traceID")

	// ContextKeyTranslator to store/obtains translator to/from request's context.
	ContextKeyTranslator = ContextKey("translator")
)

Functions

func GetIP

func GetIP(r *http.Request) string

GetIP returns the IP from given request. It will try to extract the real client IP from headers if possible.

func HeaderFromContext

func HeaderFromContext(ctx context.Context) http.Header

HeaderFromContext - get header value from context we set "header" key on context to set forwarded request context.

func ValueFromContext

func ValueFromContext(ctx context.Context, key *ContextID) string

ValueFromContext returns string value for certain ContextID.

Types

type ContextID

type ContextID struct {
	// contains filtered or unexported fields
}

ContextID is a struct which will be used as context key.

func ContextKey

func ContextKey(name string) *ContextID

ContextKey constructs context key using name supplied.

func (*ContextID) String

func (k *ContextID) String() string

String returns formatted context key identifier.

type ErrorDetails

type ErrorDetails struct {
	Exception string       `json:"exception"`
	Errors    []ErrorField `json:"errors"`
}

ErrorDetails ...

type ErrorField

type ErrorField struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ErrorField -.

type HTTPError

type HTTPError struct {
	Code     int         `json:"code"`
	Message  string      `json:"message"`
	Response interface{} `json:"response"`
}

HTTPError -.

func NewHTTPValidationError

func NewHTTPValidationError(ctx context.Context, err error) (result *HTTPError)

NewHTTPValidationError - return new HTTPError caused by validation error.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator - go-playground/validator wrapper.

func NewValidator

func NewValidator(v *validator.Validate) *Validator

NewValidator -.

func (*Validator) Validate

func (v *Validator) Validate(i interface{}) error

Validate - go-playground/validator impl.

Directories

Path Synopsis
Package httpclient is *http.Client helpers
Package httpclient is *http.Client helpers

Jump to

Keyboard shortcuts

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