Documentation ¶
Overview ¶
Package param provides a tool for dealing with parameterized headers. These headers include the Content-type and Content-disposition header. In addition, it provides some helper methods for breaking down the MIME types that get set in the Content-type header.
Index ¶
- Constants
- type Modifier
- type Value
- func (pv *Value) Boundary() string
- func (pv *Value) Bytes() []byte
- func (pv *Value) Charset() string
- func (pv *Value) Clone() *Value
- func (pv *Value) Filename() string
- func (pv *Value) MediaType() string
- func (pv *Value) Parameter(k string) string
- func (pv *Value) Parameters() map[string]string
- func (pv *Value) Presentation() string
- func (pv *Value) String() string
- func (pv *Value) Subtype() string
- func (pv *Value) Type() string
- func (pv *Value) Value() string
Constants ¶
const ( // Charset is the name of the charset parameter that may be present in the // Content-type header. Charset = "charset" // Boundary is the name of the boundary parameter that may be present in the // Content-type header. Boundary = "boundary" // Filename is the name of the filename parameter that may be present in the // Content-disposition header. Filename = "filename" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Modifier ¶
type Modifier func(*Value)
Modifier is a modification to apply to a Value when calling the Modify() function.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents a parsed parameterized header field, such as is used in the Content-type and Content-disposition headers. A Value object is immutable: You cannot change it in place. However, a Modify() function is provided to perform transformation of a Value into a new Value.
func Modify ¶
Modify clones a Value, applies the given modifications (if any) and returns the new Value. You can pass multiple changes to this function:
v, _ := value.Parse("multipart/mixed; boundary=abc123; charset=latin1") nv := value.Modify(v, Change("multipart/alternate"), Set("charset", "utf-8"))
func Parse ¶
Parse takes a header field body, parses it as a Value and returns it. If an error occurs in the process, it returns an error.
func (*Value) Boundary ¶
Boundary returns the value of the "boundary" parameter. It is intended for use with the Content-type header.
func (*Value) Bytes ¶
Bytes returns the serialized value of the Value including the primary value and all parameters.
func (*Value) Charset ¶
Charset returns the value of the "charset" parameter. It is intended for use with the Content-type header.
func (*Value) Filename ¶
Filename returns the value of the "filename" parameter. It is intended for use with the Content-disposition header.
func (*Value) MediaType ¶
MediaType is a synonym for Value() and returns the Content-type value, e.g., "text/html", "image/jpeg", "multipart/mixed", etc.
func (*Value) Parameters ¶
Parameters returns the parameters encoded on this Value as a map. Do not modify this map. The behavior if you do is not defined and may change in the future. If you need to modify it, make a copy first.
func (*Value) Presentation ¶
Presentation is a synonym for Value() and returns the Content-disposition, either "inline" or "attachment".
func (*Value) String ¶
String returns the serialized value of the Value including the primary value and all parameters.
func (*Value) Subtype ¶
Subtype is only intended for use with the Content-type header. It searches the MediaType() for a slash. If found, it will return the string after that slash. If no slash is found, it returns an empty string.
For example, if MediaType() returns "text/html", this method will return "html".
func (*Value) Type ¶
Type is only intended for use with the Content-type header. It searches the MediaType() for a slash. If found, it will return the string before that slash. If no slash is found, it returns an empty string.
For example, if MediaType() returns "image/jpeg", this method will return "image".