cookie

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDomainNotAllowed = errors.New("domain not allowed")

Functions

This section is empty.

Types

type Cookie struct {
	Name string
	// Path the path of the created cookie
	Path string
	// Secure the secure flag of the created cookie
	Secure bool
	// MaxAge the max age flag of the created cookie
	MaxAge int
	// Expires the expires flag of the created cookie
	Expires time.Duration
	// Secure the secure flag of the created cookie
	SameSite http.SameSite
	// HTTPOnly the http only of the created cookie
	HTTPOnly bool
	// TimeProvider function to retrieve the now time for the expires flag of the created cookie
	TimeProvider TimeProvider
	// DomainProvider function to retrieve the domain flag of the created cookie
	DomainProvider DomainProvider
}

func New

func New(name string, opts ...Option) Cookie

New return a new provider

func (Cookie) Delete

func (c Cookie) Delete(w http.ResponseWriter, r *http.Request) error

func (Cookie) Get

func (c Cookie) Get(r *http.Request) (*http.Cookie, error)

func (Cookie) Set

func (c Cookie) Set(w http.ResponseWriter, r *http.Request, value string, opts ...Option) (*http.Cookie, error)

type DomainProvider

type DomainProvider func(r *http.Request) (string, error)

func NewDomainProvider

func NewDomainProvider(opts ...DomainProviderOption) DomainProvider

type DomainProviderOption

type DomainProviderOption func(options *DomainProviderOptions)

func DomainProviderWithDomains

func DomainProviderWithDomains(v ...string) DomainProviderOption

func DomainProviderWithMappings

func DomainProviderWithMappings(v map[string]string) DomainProviderOption

type DomainProviderOptions

type DomainProviderOptions struct {
	Domains  []string
	Mappings map[string]string
}

func GetDefaultDomainProviderOptions

func GetDefaultDomainProviderOptions() DomainProviderOptions

type Option

type Option func(options *Cookie)

func WithDomainProvider

func WithDomainProvider(v DomainProvider) Option

WithDomainProvider middleware option

func WithExpires

func WithExpires(v time.Duration) Option

WithExpires middleware option

func WithHTTPOnly

func WithHTTPOnly(v bool) Option

WithHTTPOnly middleware option

func WithMaxAge

func WithMaxAge(v int) Option

WithMaxAge middleware option

func WithPath

func WithPath(v string) Option

WithPath middleware option

func WithSameSite

func WithSameSite(v http.SameSite) Option

WithSameSite middleware option

func WithSecure

func WithSecure(v bool) Option

WithSecure middleware option

func WithTimeProvider

func WithTimeProvider(v TimeProvider) Option

WithTimeProvider middleware option

type TimeProvider

type TimeProvider func() time.Time

func NewTimeProvider

func NewTimeProvider(opts ...TimeProviderOption) TimeProvider

type TimeProviderOption

type TimeProviderOption func(options *TimeProviderOptions)

func TimeProviderWithOffset

func TimeProviderWithOffset(v time.Duration) TimeProviderOption

type TimeProviderOptions

type TimeProviderOptions struct {
	Offset time.Duration
}

func GetDefaultTimeProviderOptions

func GetDefaultTimeProviderOptions() TimeProviderOptions

Jump to

Keyboard shortcuts

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