rest

package
v0.0.0-...-8b94866 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Unlicense Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Base64         string = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
	PrintableASCII string = "^[\x20-\x7E]+$"
	DataURI        string = "^data:.+\\/(.+);base64$"
	Email          string = "" /* 1212-byte string literal not displayed */
	CreditCard     string = "" /* 151-byte string literal not displayed */
	PhoneNumber    string = "" /* 182-byte string literal not displayed */
)

Variables

View Source
var LoggerDefaultFormat = "{{.Status}} | ({{.IPAddr}}) {{.Hostname}} | {{.Method}} {{.Path}} {{if .Message}}:: {{.Message}}{{end}}"

LoggerDefaultFormat is the format logged used by the default Logger instance.

View Source
var SafeFields = []string{"authorization", "api-key", "api", "apikey", "merchant-key", "enterprise-token", "token", "user-token"}

Functions

func SetupCORSFilterByEnv

func SetupCORSFilterByEnv(restContainer *restful.Container, envPrefix string) error

Types

type CORSFilterConfig

type CORSFilterConfig struct {
	AllowedHeaders *string `env:"ALLOWED_HEADERS"`
	AllowedMethods string  `env:"ALLOWED_METHODS"`
	AllowedDomains string  `env:"ALLOWED_DOMAINS"`
}

CORSFilterConfig get cors filter from env AllowedHeaders define which headers is allowed AllowedMethods define which http methods is allowed AllowedDomains define which domain is allowd or set to (*)

type EmptyRequest

type EmptyRequest struct{}

type EmptyResponse

type EmptyResponse struct{}

type ErrorResponse

type ErrorResponse struct {
	// Code this will be used as error code
	Code string `json:"code,omitempty"`

	// We use the term description because it describes the error
	// to the developer rather than a message for the end user.
	Description string `json:"description,omitempty"`

	Fields []ErrorResponseField `json:"fields,omitempty"`
	DocURL string               `json:"doc_url,omitempty"`
}

type ErrorResponseField

type ErrorResponseField struct {
	Field       string `json:"field"`
	Code        string `json:"code,omitempty"`
	Description string `json:"desciption,omitempty"`
	DocURL      string `json:"doc_url,omitempty"`
}

type HTTPReqInfo

type HTTPReqInfo struct {
	Method    string
	Uri       string
	Referer   string
	IPAddr    string
	UserAgent string
	Duration  time.Duration
	Request   *http.Request
}

type LogFilter

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

func NewRequestLoggingFilter

func NewRequestLoggingFilter(logSrv LogServiceServer) *LogFilter

func (*LogFilter) Filter

func (lf *LogFilter) Filter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

type LogServiceServer

type LogServiceServer interface {
	LogRequest(statusCode int, message string, endPoint string, method string, ipAddr string, referer string, userAgent string, latency int64, data json.RawMessage) error
}

type LoggerBody

type LoggerBody struct {
	Header   propertyMap `json:"header,omitempty"`
	Request  propertyMap `json:"request,omitempty"`
	Response propertyMap `json:"response,omitempty"`
}

type Recover

type Recover struct {
	StackAll   bool
	StackSize  int
	PrintStack bool
	// contains filtered or unexported fields
}

func NewRecoveryFilter

func NewRecoveryFilter(svc RecoveryService) *Recover

func (*Recover) RecoverOnPanic

func (rec *Recover) RecoverOnPanic(panicReason any, httpWriter http.ResponseWriter)

type RecoveryService

type RecoveryService interface {
	Notify(msg any) (string, error)
}

type RequestContext

type RequestContext interface {
	api.CallContext
	HTTPRequest() *http.Request
}

type Responder

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

func RespondTo

func RespondTo(w http.ResponseWriter) Responder

func (Responder) EmptyError

func (r Responder) EmptyError(httpStatusCode int)

func (Responder) Error

func (r Responder) Error(errorData any, httpStatusCode int)

func (Responder) Success

func (r Responder) Success(successData any)

func (Responder) SuccessWithHTTPStatusCode

func (r Responder) SuccessWithHTTPStatusCode(successData any, httpStatusCode int)

type ResponseCapture

type ResponseCapture struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseCapture

func NewResponseCapture(w http.ResponseWriter) *ResponseCapture

func (ResponseCapture) Bytes

func (c ResponseCapture) Bytes() []byte

func (ResponseCapture) Header

func (c ResponseCapture) Header() http.Header

func (ResponseCapture) StatusCode

func (c ResponseCapture) StatusCode() int

func (ResponseCapture) Write

func (c ResponseCapture) Write(data []byte) (int, error)

func (*ResponseCapture) WriteHeader

func (c *ResponseCapture) WriteHeader(statusCode int)

type StatsFilter

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

func NewStatsFilter

func NewStatsFilter() *StatsFilter

func (*StatsFilter) Filter

func (sf *StatsFilter) Filter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

func (*StatsFilter) StatsHandler

func (sf *StatsFilter) StatsHandler(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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