httplink

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package httplink defines a representation of Web Linkings.

Index

Constants

View Source
const (
	ParamRel         = "rel"
	ParamAs          = "as"
	ParamCrossOrigin = "crossorigin"
	ParamMedia       = "media"
	ParamType        = "type"
)

A few common parameter names for use with LinkParams.

View Source
const (
	// Value(s) for the "rel" parameter.
	RelPreload = "preload"

	// Value(s) for the "crossorigin" parameter.
	CrossOriginAnonymous = "anonymous"
)

Special parameter values recognized by LinkParams.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	URL    *url.URL
	Params LinkParams
}

Link represents a Web Linking [RFC 8288], aka. the Link HTTP header.

func NewLink(u *url.URL, rel string) *Link

NewLink creates and initializes a new Link with the provided URL u and the provided rel parameter.

func Parse

func Parse(header string) ([]*Link, error)

Parse parses the Link HTTP header value. It returns a slice since the value may contain multiple links, separated by comma.

func (*Link) Equal

func (l *Link) Equal(m *Link) bool

Equal reports whether l and m have the same URL and parameters. The URLs are compared by strings.

func (*Link) GoString

func (l *Link) GoString() string

GoString implements the GoStringer interface.

func (*Link) IsPreload

func (l *Link) IsPreload() bool

IsPreload reports whether the Link involves preloading of the resource.

func (*Link) String

func (l *Link) String() string

String serializes the Link as it appears in the HTTP header.

type LinkParams

type LinkParams map[string]string

LinkParams represents the parameters of a Web Linking.

func (LinkParams) Clone

func (p LinkParams) Clone() LinkParams

Clone returns a deep copy of the LinkParams p.

func (LinkParams) Equal

func (p LinkParams) Equal(q LinkParams) bool

Equal reports whether p and q contain the same set of key-value pairs.

func (LinkParams) Get

func (p LinkParams) Get(key string) string

Get returns the value of the parameter specified by key. key gets lowered, thus is case-insensitive.

func (LinkParams) Set

func (p LinkParams) Set(key, val string)

Set changes the value of the parameter specified by key. key gets lowered, thus is case-insensitive. Set also normalizes the provided value for some parameters, e.g. removes extra spaces for the rel parameter. To get around the normalization, access the map entry directly.

Jump to

Keyboard shortcuts

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