mux

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAccept              = "Accept"
	HeaderAcceptEncoding      = "Accept-Encoding"
	HeaderAllow               = "Allow"
	HeaderAuthorization       = "Authorization"
	HeaderContentDisposition  = "Content-Disposition"
	HeaderContentEncoding     = "Content-Encoding"
	HeaderContentLength       = "Content-Length"
	HeaderContentType         = "Content-Type"
	HeaderCookie              = "Cookie"
	HeaderSetCookie           = "Set-Cookie"
	HeaderIfModifiedSince     = "If-Modified-Since"
	HeaderLastModified        = "Last-Modified"
	HeaderLocation            = "Location"
	HeaderUpgrade             = "Upgrade"
	HeaderVary                = "Vary"
	HeaderWWWAuthenticate     = "WWW-Authenticate"
	HeaderXForwardedFor       = "X-Forwarded-For"
	HeaderXForwardedProto     = "X-Forwarded-Proto"
	HeaderXForwardedProtocol  = "X-Forwarded-Protocol"
	HeaderXForwardedSsl       = "X-Forwarded-Ssl"
	HeaderXUrlScheme          = "X-Url-Scheme"
	HeaderXHTTPMethodOverride = "X-HTTP-Method-Override"
	HeaderXRealIP             = "X-Real-IP"
	HeaderXRequestID          = "X-Request-ID"
	HeaderXRequestedWith      = "X-Requested-With"
	HeaderServer              = "Server"
	HeaderOrigin              = "Origin"
	HeaderSimulatorUserID     = "Simulator-Actor-ID"

	// Access control
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"

	// Security
	HeaderStrictTransportSecurity         = "Strict-Transport-Security"
	HeaderXContentTypeOptions             = "X-Content-Type-Options"
	HeaderXXSSProtection                  = "X-XSS-Protection"
	HeaderXFrameOptions                   = "X-Frame-Options"
	HeaderContentSecurityPolicy           = "Content-Security-Policy"
	HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
	HeaderXCSRFToken                      = "X-CSRF-Token" // #nosec
	HeaderReferrerPolicy                  = "Referrer-Policy"
	HeaderReferer                         = "Referer"
)

Headers

View Source
const (
	MIMEApplicationJSON                  = "application/json"
	MIMEApplicationJSONCharsetUTF8       = MIMEApplicationJSON + "; " + charsetUTF8
	MIMEApplicationJavaScript            = "application/javascript"
	MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
	MIMEApplicationXML                   = "application/xml"
	MIMEApplicationXMLCharsetUTF8        = MIMEApplicationXML + "; " + charsetUTF8
	MIMETextXML                          = "text/xml"
	MIMETextXMLCharsetUTF8               = MIMETextXML + "; " + charsetUTF8
	MIMEApplicationForm                  = "application/x-www-form-urlencoded"
	MIMEApplicationProtobuf              = "application/protobuf"
	MIMEApplicationMsgpack               = "application/msgpack"
	MIMETextHTML                         = "text/html"
	MIMETextHTMLCharsetUTF8              = MIMETextHTML + "; " + charsetUTF8
	MIMETextPlain                        = "text/plain"
	MIMETextPlainCharsetUTF8             = MIMETextPlain + "; " + charsetUTF8
	MIMEMultipartForm                    = "multipart/form-data"
	MIMEOctetStream                      = "application/octet-stream"
)

MIME types

View Source
const (

	// PROPFIND Method can be used on collection and property resources.
	PROPFIND = "PROPFIND"
	// REPORT Method can be used to get information about a resource, see rfc 3253
	REPORT = "REPORT"
)

Variables

View Source
var ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType)

Functions

func Bind

func Bind(r *http.Request, i interface{}) (err error)

Bind binds the request to the destination struct. nolint:gocyclo

func CopyBody

func CopyBody(r *http.Request) (interface{}, error)

CopyBody returns query param for get method, and body for others.

func FormParams

func FormParams(r *http.Request) (url.Values, error)

Types

type BindUnmarshaler

type BindUnmarshaler interface {
	// UnmarshalParam decodes and assigns a value from an form or query param.
	UnmarshalParam(param string) error
}

BindUnmarshaler is the interface used to wrap the UnmarshalParam method. Types that don't implement this, but do implement encoding.TextUnmarshaler will use that interface instead.

type GetResultData

type GetResultData struct {
	// Contains query param passed by client.
	// To cross check if server accept the correct param from client.
	Param interface{} `json:"http_param"`

	// Defines the current API response generated.
	GeneratedDate string `json:"generated_date"`

	// Describes total number of data generated by current request.
	TotalData string `json:"total_data"`

	// Request result data.
	Data interface{} `json:"data"`
}

GetResultData is the default response result data format. For method GET.

type HTTPError

type HTTPError struct {
	Code     int         `json:"-"`
	Message  interface{} `json:"message"`
	Internal error       `json:"-"` // Stores the error returned by an external dependency
}

HTTPError represents an error that occurred while handling a request.

func NewHTTPError

func NewHTTPError(code int, message ...interface{}) *HTTPError

NewHTTPError creates a new HTTPError instance.

func (*HTTPError) Error

func (he *HTTPError) Error() string

Error makes it compatible with `error` interface.

func (*HTTPError) SetInternal

func (he *HTTPError) SetInternal(err error) *HTTPError

SetInternal sets error to HTTPError.Internal

func (*HTTPError) Unwrap

func (he *HTTPError) Unwrap() error

Unwrap satisfies the Go 1.13 error wrapper interface.

type PostResultData

type PostResultData struct {
	// Contains json body passed by client.
	// To cross check if server accept the correct param from client.
	Param interface{} `json:"http_param"`

	// Defines the current API request execution time.
	ExecutedDate string `json:"executed_date"`

	// Describes total number of data is affected by current request.
	RowsAffected int `json:"rows_affected"`
}

PostResultData is the default response result data format. For method PUT, PATCH, POST, DELETE.

type Response

type Response struct {
	// Describes api status or response code.
	Code string `json:"api_code"`

	// Describes status message that should be shown to user.
	DisplayMsg string `json:"api_display_message"`

	// Describes server real error message that should not be shown to user.
	RawMsg string `json:"api_raw_message"`

	// Used for debugging.
	// It uses client request `X-Request-ID` header.
	// If empty, generated by server instead.
	RequestID string `json:"trace_id"`

	// Describes current api generated result data.
	ResultData interface{} `json:"api_result_data"`
}

Response is the default response format.

func GetDefaultResponse

func GetDefaultResponse(r *http.Request) Response

GetDefaultResponse is the default response for http get request

func GetSuccessResponse

func GetSuccessResponse(r *http.Request, totalData int, data interface{}) Response

GetSuccessResponse is the success response for http get request

func PostDefaultResponse

func PostDefaultResponse(r *http.Request) Response

PostDefaultResponse is the default response for http post request

func PostSuccessResponse

func PostSuccessResponse(r *http.Request, param interface{}, rowsAffected int) Response

PostSuccessResponse is the success response for http post request

type Writer

type Writer struct {
	http.ResponseWriter
	StatusCode int
	// Response contains the whole operation response data.
	// Since certain operation has a big response data,
	// response will only be filled on [development, staging] environment.
	Response map[string]interface{}
}

func NewWriter

func NewWriter(w http.ResponseWriter) *Writer

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(code int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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