Gorta

Getting Started

Install Gorta and wire up auth in a Go HTTP server.

Gorta is a minimal, adapter-based authentication library for Go. You bring the database; Gorta handles sessions, cookies, and plugin HTTP routes.

Install

go get github.com/etornam45/gorta

Prerequisites

  • Go 1.22+ (stdlib http.ServeMux route patterns)
  • A SQL database (or your own core.Storage implementation)
  • A signing secret of at least 32 characters

Quick start

storage := sqladapter.New(db)

emailPlugin, err := emailpassword.New(storage, storage, mailer, emailpassword.Config{
    VerifyEmail: true,
})

auth, err := gorta.New(storage, gorta.Config{
    Secret:  os.Getenv("SECRET"),
    BaseURL: os.Getenv("BASE_URL"),
}, gorta.WithPlugin(emailPlugin))

mux := http.NewServeMux()
mux.Handle("/auth/", http.StripPrefix("/auth", auth.Handler()))
mux.Handle("/dashboard", auth.RequireAuth()(http.HandlerFunc(dashboard)))

http.ListenAndServe(":8080", auth.Middleware()(mux))

Auth routes live under /auth (for example POST /auth/sign-in). Session middleware loads the cookie on every request; RequireAuth guards private handlers.

Environment variables

VariableDescription
SECRETSession signing secret (32+ characters)
BASE_URLPublic URL of your API (OAuth redirects, email links)
SESSION_DURATIONOptional session lifetime (e.g. 168h)
COOKIE_SECURESet true in production (HTTPS only)
COOKIE_DOMAINOptional cookie domain
COOKIE_NAMEOptional cookie name (default gorta_session)

Example project

A full working server with email/password, magic links, and OAuth is in the repository:

Next steps

Plugin guides, storage adapters, and HTTP API reference are coming soon. For now, explore the repository README and plugin packages under plugins/.

On this page