HOST
Go
Sem framework. net/http mais o módulo é o host.
Go
Sem framework. net/http mais o módulo é o host.
github.com/neresson/sveda-go-sdk, sveda.StartHostSession, POST /sveda/session em net/http.
AGENT PROMPT
Paste into Cursor
Copy this into Cursor, Claude Code, or any coding agent. It installs Sveda against this stack using public packages.
Install Sveda into this Go project.
Read:
- https://sveda.dev/docs/hosts/go
- https://sveda.dev/docs/client
- https://sveda.dev/docs/deploy
- https://sveda.dev/llms.txt
Follow the numbered steps on the Go page. If unsure which frontend this repo uses, ask the user. 1. Run sveda-server
# ghcr.io/neresson/sveda-server:latest
# curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.yaml -o compose.yaml && curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.env -o .env && # Edit .env: a model key, SVEDA_EMBED_HOST_API_KEY, SVEDA_CORS_ORIGINS && && docker compose up -d && curl -s http://127.0.0.1:8787/sveda/ready
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: sveda
POSTGRES_PASSWORD: sveda
POSTGRES_DB: sveda
healthcheck:
test: ["CMD-SHELL", "pg_isready -U sveda -d sveda"]
interval: 5s
timeout: 3s
retries: 10
volumes:
- sveda-postgres:/var/lib/postgresql/data
redis:
image: redis:7-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
sveda-server:
image: ghcr.io/neresson/sveda-server:latest
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8787:8787"
environment:
SVEDA_BIND: 0.0.0.0:8787
SVEDA_EMBED_ENABLED: "true"
SVEDA_DATABASE_URL: postgres://sveda:sveda@postgres:5432/sveda
SVEDA_REDIS_URL: redis://redis:6379
SVEDA_APP_KEY: ${SVEDA_APP_KEY:-dev-app-key-change-me}
SVEDA_ADMIN_API_KEY: ${SVEDA_ADMIN_API_KEY:-dev-admin-key-change-me}
SVEDA_EMBED_HOST_API_KEY: ${SVEDA_EMBED_HOST_API_KEY:-dev-host-key-change-me}
SVEDA_CORS_ORIGINS: ${SVEDA_CORS_ORIGINS:-*}
DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY:-}
volumes:
sveda-postgres:# ghcr.io/neresson/sveda-server:latest
# curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.yaml -o compose.yaml && curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.env -o .env && # Edit .env: a model key, SVEDA_EMBED_HOST_API_KEY, SVEDA_CORS_ORIGINS && && docker compose up -d && curl -s http://127.0.0.1:8787/sveda/ready
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: sveda
POSTGRES_PASSWORD: sveda
POSTGRES_DB: sveda
healthcheck:
test: ["CMD-SHELL", "pg_isready -U sveda -d sveda"]
interval: 5s
timeout: 3s
retries: 10
volumes:
- sveda-postgres:/var/lib/postgresql/data
redis:
image: redis:7-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
sveda-server:
image: ghcr.io/neresson/sveda-server:latest
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8787:8787"
environment:
SVEDA_BIND: 0.0.0.0:8787
SVEDA_EMBED_ENABLED: "true"
SVEDA_DATABASE_URL: postgres://sveda:sveda@postgres:5432/sveda
SVEDA_REDIS_URL: redis://redis:6379
SVEDA_APP_KEY: ${SVEDA_APP_KEY:-dev-app-key-change-me}
SVEDA_ADMIN_API_KEY: ${SVEDA_ADMIN_API_KEY:-dev-admin-key-change-me}
SVEDA_EMBED_HOST_API_KEY: ${SVEDA_EMBED_HOST_API_KEY:-dev-host-key-change-me}
SVEDA_CORS_ORIGINS: ${SVEDA_CORS_ORIGINS:-*}
DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY:-}
volumes:
sveda-postgres: 2. Add the module
Module
github.com/neresson/sveda-go-sdk.
No Gin or Echo required.
go get github.com/neresson/sveda-go-sdkgo get github.com/neresson/sveda-go-sdk
3. Env
SVEDA_CLIENT_BASE_URL=http://127.0.0.1:8787
SVEDA_CLIENT_HOST_API_KEY=replace-meSVEDA_CLIENT_BASE_URL=http://127.0.0.1:8787 SVEDA_CLIENT_HOST_API_KEY=replace-me
4. POST /sveda/session
sveda.StartHostSession
returns a struct tagged
origin,
token,
expires_in,
appearance.
Empty env returns an error — map that to 503.
Optional
policy
on the mint maps your app role to a named capability set —
embed policies.
mux.HandleFunc("POST /sveda/session", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
session, err := sveda.StartHostSession(r.Context(), sveda.Config{
BaseURL: os.Getenv("SVEDA_CLIENT_BASE_URL"),
HostAPIKey: os.Getenv("SVEDA_CLIENT_HOST_API_KEY"),
}, "go-playground")
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(map[string]string{"message": err.Error()})
return
}
json.NewEncoder(w).Encode(session)
})mux.HandleFunc("POST /sveda/session", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
session, err := sveda.StartHostSession(r.Context(), sveda.Config{
BaseURL: os.Getenv("SVEDA_CLIENT_BASE_URL"),
HostAPIKey: os.Getenv("SVEDA_CLIENT_HOST_API_KEY"),
}, "go-playground")
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(map[string]string{"message": err.Error()})
return
}
json.NewEncoder(w).Encode(session)
}) 5. Templates
Only emit
data-sveda-*,
chat buttons, and
sveda-host.js
when
SvedaOrigin
is non-empty.
<html
lang="en"
data-sveda-origin="http://127.0.0.1:8787"
data-sveda-session="/sveda/session"
>
<body>
<button type="button" data-sveda-open="js">Open JS chat</button>
<button type="button" data-sveda-open="iframe">Open iframe chat</button>
<script type="module" src="/sveda-host.js"></script>
</body>
</html><html
lang="en"
data-sveda-origin="http://127.0.0.1:8787"
data-sveda-session="/sveda/session"
>
<body>
<button type="button" data-sveda-open="js">Open JS chat</button>
<button type="button" data-sveda-open="iframe">Open iframe chat</button>
<script type="module" src="/sveda-host.js"></script>
</body>
</html>