util

package
v0.0.0-...-58bf0a8 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InitDirnameErr error
)

Functions

func AddHeader

func AddHeader(w http.ResponseWriter, k string, v interface{})

AddHeader adds the specified value to the HTTP response header field. If the header is not already set, it creates the header with the specified value. The value parameter can be a string or a string slice.

func AddPrefixSlash

func AddPrefixSlash(p string) string

AddPrefixSlash adds a slash to the start of given string

func AppendToVaryHeader

func AppendToVaryHeader(vary string, fields []string) string

AppendToVaryHeader appends fields to the vary field of header.

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func Dirname

func Dirname() (string, error)

Dirname returns the directory name of executable file that started the current process.

func EncodeURI

func EncodeURI(str string) string

EncodeURI encodes a text string as a valid Uniform Resource Identifier (URI)

func EncodeURIComponent

func EncodeURIComponent(str string) string

EncodeURIComponent encodes a text string as a valid component of a Uniform Resource Identifier (URI).

func FileExists

func FileExists(absPath string) bool

FileExists returns true if specified absolute file path exists.

func FormatMediaType

func FormatMediaType(m MediaType) (string, error)

Format object to media type

func Fresh

func Fresh(reqHeader, resHeader http.Header) bool

Fresh checks freshness of the response using request and response headers.

func GetHeaderValues

func GetHeaderValues(h http.Header, key string) []string

GetHeaderValues returns the header values of specified key. This is a patch function of http.Header.Values for go version lower than 1.4

func H

func H(k string) string

H is an alias function for `textproto.CanonicalMIMEHeaderKey`

func HasBody

func HasBody(req *http.Request) bool

HasBody checks if a request has a request body. A request with a body __must__ either have `transfer-encoding` or `content-length` headers set.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3

func IsFileExist

func IsFileExist(path string) bool

IsFileExist checks if a file is exist

func LookupCharset

func LookupCharset(mimeType string) string

LookupCharset lookups the charset of MIME Type.

func LookupMimeType

func LookupMimeType(s string) string

LookupMimeType lookups the MIME Type of a suffix string.

func Max

func Max(x, y int) int

func Min

func Min(x, y int) int

func ParseHeader

func ParseHeader(header string) []string

ParseHeader parses header with type string into a slice.

func RequestTypeIs

func RequestTypeIs(req *http.Request, types ...string) string

func RouteJoin

func RouteJoin(routes ...string) string

RouteJoin joins all given routes

func SetContentType

func SetContentType(w http.ResponseWriter, s string)

SetContentType sets the Content-Type HTTP header to the MIME type as determined by LookupMimeType() for the specified type. If type contains the “/” character, then it sets the Content-Type to type.

func SetHeader

func SetHeader(w http.ResponseWriter, value ...interface{})

SetHeader sets the response’s HTTP header field to value. To set multiple fields at once, pass a string map as the parameter.

func StringToBytes

func StringToBytes(s string) (b []byte)

StringToBytes converts string to byte slice without a memory allocation.

func TestMediaType

func TestMediaType(s string) bool

Test media type

func TypeIs

func TypeIs(contentType string, types ...string) string

func Vary

func Vary(w http.ResponseWriter, fields []string)

Vary marks that a request is varied on a header field.

Types

type AcceptParams

type AcceptParams struct {
	Value   string
	Quality float64
	Params  map[string]string
}

AcceptParams is an object with `.value`, `.quality` and `.params`.

func NormalizeType

func NormalizeType(t string) AcceptParams

NormalizeType normalizes the given `type`, for example "html" becomes "text/html".

type MediaType

type MediaType struct {
	MainType string
	Subtype  string
	Suffix   string
}

func ParseMediaType

func ParseMediaType(s string) (MediaType, error)

Parse media type to object

type Range

type Range struct {
	Start int64
	End   int64
	// contains filtered or unexported fields
}

type Ranges

type Ranges struct {
	Type   string
	Ranges []*Range
}

func RangeParser

func RangeParser(size int64, str string, combine bool) (Ranges, error)

RangeParser parses "Range" header `str` relative to the given file `size`.

The "combine" argument can be set to `true` and overlapping & adjacent ranges * will be combined into a single range.

type StringSlice

type StringSlice []string

StringSlice attaches the methods of Interface to []string.

func (StringSlice) Contains

func (s StringSlice) Contains(str string) bool

Contains reports whether str is within the string slice.

func (StringSlice) Filter

func (s StringSlice) Filter(f func(string) bool) []string

Filter returns a new string slice with matched values.

func (StringSlice) Index

func (s StringSlice) Index(str string) int

Index returns the index of str in the string slice.

func (StringSlice) Map

func (s StringSlice) Map(f func(string) string) []string

Map returns a new string slice with modified values.

Jump to

Keyboard shortcuts

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