🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

vimagination.zapto.org/sessions

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/sessions

Go Modules
Version
v1.0.3
Version published
Created
Source

sessions

CI Go Reference Go Report Card

-- import "vimagination.zapto.org/sessions"

Package sessions is used to store session information for a web server.

Highlights

  • Set and get session data in client cookies.
  • Session data is signed and dated to prevent tampering.

Usage

package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"time"

	"vimagination.zapto.org/sessions"
)

func main() {
	store, err := sessions.NewCookieStore([]byte("!THIS IS MY KEY!"), sessions.Expiry(time.Second))
	if err != nil {
		fmt.Println(err)

		return
	}

	w := httptest.NewRecorder()

	store.Set(w, []byte("MY_DATA"))

	r := httptest.NewRequest(http.MethodGet, "http://example.com", nil)

	for _, cookie := range w.Result().Cookies() {
		r.AddCookie(cookie)
	}

	fmt.Printf("%q\n", store.Get(r))

	time.Sleep(2 * time.Second)

	fmt.Printf("%q\n", store.Get(r))

	// Output:
	// "MY_DATA"
	// ""
}

Documentation

Full API docs can be found at:

https://pkg.go.dev/vimagination.zapto.org/sessions

FAQs

Package last updated on 19 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts