Gothic ships with three storage helpers for your WASM components: LocalStorage, SessionStorage, and Cookies.
Important: You must dot-import pkg/wasm (import . "github.com/felipegenef/gothicframework/v2/pkg/wasm") for use these helpers, otherwise you will get a tinygo compile error.
Each one has the same shape: Set, Get, and Remove (Delete for cookies). Pick the storage that matches the lifetime you need.
LocalStorage persists across sessions and tabs. Great for theme, language, or any preference that should outlive the browser tab.
// LocalStorage: persists across tabs and restarts
LocalStorageSet("theme", "dark")
theme := LocalStorageGet("theme") // returns "" if missing
LocalStorageRemove("theme") SessionStorage is wiped when the tab closes. Use it for draft form data, wizard steps, or anything that should not leak to the next session.
// SessionStorage: cleared when the tab closes
SessionStorageSet("draft", content)
draft := SessionStorageGet("draft")
SessionStorageRemove("draft") Cookies ride along with every HTTP request, so they are perfect when the server needs to read the value too. Auth tokens, locale, feature flags.
Note: use CookieOptions to control MaxAge, Path, SameSite, and Secure.
// Cookies: sent with every HTTP request, readable server-side
CookieSet("theme", "dark", CookieOptions{
MaxAge: 60 * 60 * 24 * 365, // 1 year
SameSite: "Lax",
Secure: true,
})
theme := CookieGet("theme")
CookieDelete("theme") With your state safely persisted, let's see how WASM talks to the network and reads user files next with HTTP & Files!