headers

package
v0.0.0-...-ad7249d Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: AGPL-3.0 Imports: 4 Imported by: 0

README

headers

Package headers provides utility code for operating on header values that come from different sources. A default HTTP middleware handler is provided and will ensure that the headers are appropriately translated and passed along.

import github.com/mjpitz/myago/headers

Usage

func HTTP
func HTTP(delegate http.Handler) http.HandlerFunc

HTTP returns an http middleware function that translates HTTP headers into a context Header.

func ToContext
func ToContext(ctx context.Context, header Header) context.Context

ToContext attaches the provided headers to the context.

type Header
type Header map[string][]string

Header defines an abstract definition of a header.

func Extract
func Extract(ctx context.Context) Header

Extract attempts to obtain the headers from the provided context.

func New
func New() Header

New constructs a Header for use.

func (Header) Get
func (h Header) Get(key string) string

Get returns the first possible header value for a key (if present).

func (Header) GetAll
func (h Header) GetAll(key string) []string

GetAll returns all possible values for a key.

func (Header) Set
func (h Header) Set(key, value string)

Set sets a single value for the provided key.

func (Header) SetAll
func (h Header) SetAll(key string, values []string)

SetAll sets the values for the provides key.

Documentation

Overview

Package headers provides utility code for operating on header values that come from different sources. A default HTTP middleware handler is provided and will ensure that the headers are appropriately translated and passed along.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTP

func HTTP(delegate http.Handler) http.HandlerFunc

HTTP returns an http middleware function that translates HTTP headers into a context Header.

func ToContext

func ToContext(ctx context.Context, header Header) context.Context

ToContext attaches the provided headers to the context.

Types

type Header map[string][]string

Header defines an abstract definition of a header.

func Extract

func Extract(ctx context.Context) Header

Extract attempts to obtain the headers from the provided context.

func New

func New() Header

New constructs a Header for use.

func (Header) Get

func (h Header) Get(key string) string

Get returns the first possible header value for a key (if present).

func (Header) GetAll

func (h Header) GetAll(key string) []string

GetAll returns all possible values for a key.

func (Header) Set

func (h Header) Set(key, value string)

Set sets a single value for the provided key.

func (Header) SetAll

func (h Header) SetAll(key string, values []string)

SetAll sets the values for the provides key.

Jump to

Keyboard shortcuts

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