cookies

package module
v0.0.0-...-90cceeb Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2017 License: MIT Imports: 3 Imported by: 0

README

Cookies

GoDoc Build Status Coverage Status

Cookies package

This is a small package the provides a layer of abstraction over gorilla secure cookie, in order to give a plug and play usage. Security is a paramount therefore cookies are encrypted only with secure randomly generate keys. The package provides only the following 3 methods:

  • New accept two value the cookie name and a configuration ( the Conf struct ).
  • Set method accept a map of string keys and string values and adds created and adds the cookie.
  • Get retrieves the cookie map for the request and return a map of string keys and string values.
How to use it

Pretty simple, there is only one method to create a new parser just call

  cookiemng := cookies.New("cookiename",&Conf{}) 
  // default conf uses default values not secure, max age 0 and not httponly.

To put, retrieve and delete cookies to like so:

  cookiemng.Set(w, r, map[string]string{"testkey":"testvalue"}) 
 // sets the cookie with the following map
  values := cookiemng.Get(w,r)
 // values containes all the value previously set into the cookie
 cookiemng.Del(w,r)
 // clears the cookie from the request

That's pretty much it.

Philosophy

This software is developed following the "mantra" keep it simple, stupid or better known as KISS. Something so simple like a cache with auto eviction should not required over engineered solutions. Though it provides most of the functionality needed by generic configuration files, and most important of all meaning full error messages.

Disclaimer

This software in alpha quality, don't use it in a production environment, it's not even completed.

Thank You Notes

None.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	HttpOnly bool
	Secure   bool
	MaxAge   int
}

Conf is the struct the manages the settings for the cookie creation, must be passed to the constructor.

type CookieIface

type CookieIface interface {
	Set(w http.ResponseWriter, r *http.Request, val map[string]interface{})
	Get(w http.ResponseWriter, r *http.Request) map[string]interface{}
	Del(w http.ResponseWriter, r *http.Request)
}

CookieIface is the interface to be implemented in case other backends implementation are added in future right one is only one.

type Cookies

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

func New

func New(name string, conf *Conf) *Cookies

New accept a cookie name and a configuration and returns a valid cookie manager.

func (*Cookies) Del

func (c *Cookies) Del(w http.ResponseWriter, r *http.Request)

Del clears the cookie from the client

func (*Cookies) Get

func (c *Cookies) Get(w http.ResponseWriter, r *http.Request) map[string]string

Get gets the map from the request

func (*Cookies) Set

func (c *Cookies) Set(w http.ResponseWriter, r *http.Request, val map[string]string)

Set set the cookie with map of values map[string]string

Jump to

Keyboard shortcuts

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