package
0.0.0-20160323153452-958a0a0266f1
Repository: https://github.com/archs/js.git
Documentation: pkg.go.dev
# README
Gopherjs Cookie Library
This Library implements convenience functions for manipulating cookies in a Gopherjs application.
Installation
Install with go get:
go get github.com/fabioberger/cookie
Then include the package in your imports:
import "github.com/fabioberger/cookie"
Example Usage
Set Cookie:
expires := time.Now().Add(time.Hour) // Set expiry time to in one hour
cookie.Set("username", "John Doe", &expires, "/")
// Or
// set cookie with correctly formatted string
cookie.SetString("username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/")
Get Cookie:
username, ok := cookie.Get("username")
if !ok {
// Cookie was not found
}
Delete Cookie:
cookie.Delete("username")
# Functions
Delete removes a cookie specified by name.
Get returns a given cookie by name.
Set adds a cookie to a user's browser with a name, value, expiry and path value, path and expires can be omitted.
SetString sets a cookie given a correctly formatted cookie string i.e "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/".