http

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package http has helpers for HTTP servers, such as signed cookies.

Index

Constants

View Source
const MinCookieKeyLength = 32

MinCookieKeyLength is the shortest key NewCookieSigner accepts.

Variables

This section is empty.

Functions

This section is empty.

Types

type CookieSigner

type CookieSigner struct {
	// contains filtered or unexported fields
}

CookieSigner keeps small values in cookies signed with HMAC-SHA256, so a server can trust what comes back without keeping a store. Values are signed but not encrypted: the client can read them, but not change them.

The signature covers the cookie's name as well as its value, so a value sealed for one cookie is not accepted for another.

func NewCookieSigner

func NewCookieSigner(key []byte) (*CookieSigner, error)

NewCookieSigner returns a CookieSigner using key, which must be at least MinCookieKeyLength bytes. Changing the key invalidates every value sealed with the old one.

func (*CookieSigner) Open

func (s *CookieSigner) Open(name, value string, v any) bool

Open checks that value was sealed for the cookie called name and decodes it into v. It reports false if the signature or encoding is wrong, in which case v may have been partly written.

func (*CookieSigner) Read

func (s *CookieSigner) Read(r *http.Request, name string, v any) bool

Read opens the cookie called name from r into v, reporting false if it is missing or not validly sealed.

func (*CookieSigner) Seal

func (s *CookieSigner) Seal(name string, v any) (string, error)

Seal encodes v as JSON and signs it for the cookie called name. The result is safe to use as a cookie value.

Jump to

Keyboard shortcuts

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