Documentation ¶
Index ¶
- func CORSMiddleware(c *CORS, next http.Handler) http.Handler
- func CORSMiddlewareAllInclusive(next http.Handler) http.Handler
- func EnvOrAlternates(envVar string, alternates ...string) string
- func FirstNonEmptyString(args ...string) string
- func NonEmptyStrings(args ...string) (nonEmpties []string)
- func RedirectAllTrafficTo(host string) http.Handler
- func StatusOK(code int) bool
- func ToURLValues(v interface{}) (url.Values, error)
- func UniqStrings(strs ...string) []string
- type CORS
- type CodedError
- type NullableFloat64
- type NullableString
- type NullableTime
- type NumericBool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORSMiddlewareAllInclusive ¶
CORSMiddlewareAllInclusive is a convenience helper that uses the all inclusive CORS: Access-Control-Allow-Origin: * Access-Control-Allow-Methods: * Access-Control-Allow-Headers: * Access-Control-Allow-Credentials: * thus enabling all origins, all methods and all headers.
func EnvOrAlternates ¶
func FirstNonEmptyString ¶
FirstNonEmptyString iterates through its arguments trying to find the first string that is not blank or consists entirely of spaces.
func NonEmptyStrings ¶
func RedirectAllTrafficTo ¶
RedirectAllTrafficTo creates a handler that can be attached to an HTTP traffic multiplexer to perform a 301 Permanent Redirect to the specified host for any path, anytime that the handler receives a request. Sample usage is:
httpsRedirectHandler := RedirectAllTrafficTo("https://orijtech.com") if err := http.ListenAndServe(":80", httpsRedirectHandler); err != nil { log.Fatal(err) }
which is used in production at orijtech.com to redirect any non-https traffic from http://orijtech.com/* to https://orijtech.com/*
func ToURLValues ¶
ToURLValues transforms any type with fields into a url.Values map so that it can be used to make the QUERY string in HTTP GET requests for example:
Transforming a struct whose JSON representation is:
{ "url": "https://orijtech.com", "logo": { "url": "https://orijtech.com/favicon.ico", "dimens": { "width": 100, "height": 120, "extra": { "overlap": true, "shade": "48%" } } } }
Into: "logo.dimension.extra.shade=48%25&logo.dimension.extra.zoom=false&logo.dimension.height=120&logo.dimension.width=100&logo.url=https%3A%2F%2Forijtech.com%2Ffavicon.ico"
func UniqStrings ¶
Types ¶
type CORS ¶
type CORS struct { Origins []string Methods []string Headers []string // AllowCredentials when set signifies that the header // "Access-Control-Allow-Credentials" which will allow // the possibility of the frontend XHR's withCredentials=true // to be set. AllowCredentials bool // contains filtered or unexported fields }
type CodedError ¶
type CodedError struct {
// contains filtered or unexported fields
}
func MakeCodedError ¶
func MakeCodedError(msg string, code int) *CodedError
func (*CodedError) Code ¶
func (cerr *CodedError) Code() int
func (*CodedError) Error ¶
func (cerr *CodedError) Error() string
type NullableFloat64 ¶
type NullableFloat64 float64
func (*NullableFloat64) UnmarshalJSON ¶
func (nf64 *NullableFloat64) UnmarshalJSON(b []byte) error
type NullableString ¶
type NullableString string
NullableString represents a string that is sent back by some APIs as null, in JSON unquoted which makes them un-unmarshalable in Go. NullableString interprets null as "".
func (*NullableString) UnmarshalJSON ¶
func (ns *NullableString) UnmarshalJSON(b []byte) error
type NullableTime ¶
func (*NullableTime) UnmarshalJSON ¶
func (nt *NullableTime) UnmarshalJSON(b []byte) error
type NumericBool ¶
type NumericBool bool
func (*NumericBool) UnmarshalJSON ¶
func (nb *NumericBool) UnmarshalJSON(blob []byte) error