New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

goa.design/examples/cookies

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

goa.design/examples/cookies

  • v0.0.0-20240923021920-63cd2eb4e65f
  • Go
  • Socket score

Version published
Created
Source

Cookies Example

This example illustrates how to read and write HTTP cookies from a Goa service.

The session service exposes two methods: create_session and use_session. create_session writes a cookie to the HTTP response and use_session reads it back.

The available DSL functions used to manipulate HTTP cookies are:

  • Cookie
  • CookieMaxAge
  • CookiePath
  • CookieDomain
  • CookieSecure
  • CookieHTTPOnly

The following shows the DSL used to write the cookie:

HTTP(func() {
	POST("/")
	Response(StatusOK, func() {
		Cookie("session_id:SID") // Return session ID in "SID" cookie
		CookieMaxAge(3600)       // Sessions last one hour
	})
})

The value of the HTTP cookie SID is read from the session_id field of the method result object.

The extract below shows the DSL used to read the cookie:

HTTP(func() {
	GET("/")
	Cookie("session_id:SID") // Load session ID from "SID" cookie
	Response(StatusOK)
})

Building and Running the example

Build the server and the client:

go build ./cmd/session && go build ./cmd/session-cli

Run the server:

./session --http-port 8080

Run the client to create a session:

./session-cli -v -url http://localhost:8080 session create-session --body '{"name":"foo"}' 

Run the client to use a session:

./session-cli -url http://localhost:8080 session use-session -session-id abcd

FAQs

Package last updated on 23 Sep 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc