param

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 4 Imported by: 0

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

View Source
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.

func Change

func Change(value string) Modifier

Change is a Modifier that replaces the primary value of the Value.

func Delete

func Delete(name string) Modifier

Delete is a Modifier that removes the parameter with the given name from the Value.

func Set

func Set(name, value string) Modifier

Set is a Modifier that sets a parameter with the given name on the Value.

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

func Modify(pv *Value, changes ...Modifier) *Value

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 New

func New(v string, ps ...map[string]string) *Value

New creates a new parameterized header field with or without parameters.

func Parse

func Parse(v string) (*Value, error)

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

func (pv *Value) Boundary() string

Boundary returns the value of the "boundary" parameter. It is intended for use with the Content-type header.

func (*Value) Bytes

func (pv *Value) Bytes() []byte

Bytes returns the serialized value of the Value including the primary value and all parameters.

func (*Value) Charset

func (pv *Value) Charset() string

Charset returns the value of the "charset" parameter. It is intended for use with the Content-type header.

func (*Value) Clone

func (pv *Value) Clone() *Value

Clone returns a deep copy of the Value.

func (*Value) Filename

func (pv *Value) Filename() string

Filename returns the value of the "filename" parameter. It is intended for use with the Content-disposition header.

func (*Value) MediaType

func (pv *Value) MediaType() string

MediaType is a synonym for Value() and returns the Content-type value, e.g., "text/html", "image/jpeg", "multipart/mixed", etc.

func (*Value) Parameter

func (pv *Value) Parameter(k string) string

Parameter returns the value of the parameter with the given name.

func (*Value) Parameters

func (pv *Value) Parameters() map[string]string

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

func (pv *Value) Presentation() string

Presentation is a synonym for Value() and returns the Content-disposition, either "inline" or "attachment".

func (*Value) String

func (pv *Value) String() string

String returns the serialized value of the Value including the primary value and all parameters.

func (*Value) Subtype

func (pv *Value) Subtype() string

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

func (pv *Value) Type() string

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".

func (*Value) Value

func (pv *Value) Value() string

Value returns the primary value of the Value. This is the value before the first semi-colon.

Jump to

Keyboard shortcuts

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