Skip to main content

sdk-go/owly (Go)

The Go SDK keeps you net/http-native — register routes with http.HandleFunc / http.ServeMux as usual — and layers response helpers, env access, and static file reads on top. Importing it sets up HTTP serving for you; there's nothing else to wire by hand.

package main

import (
"net/http"

"github.com/owly/owly-testing/sdk-go/owly"
)

func init() {
http.HandleFunc("/api/status", func(w http.ResponseWriter, r *http.Request) {
owly.JSON(w, http.StatusOK, map[string]string{
"version": owly.Env("APP_VERSION", "1.0.0"),
})
})
}

func main() {}

Import only the owly package:

import "github.com/owly/owly-testing/sdk-go/owly"

API

// JSON writes status + Content-Type: application/json + json-encoded data.
func JSON(w http.ResponseWriter, status int, data any) error

// Text writes status + Content-Type: text/plain + body.
func Text(w http.ResponseWriter, status int, body string) error

// Env returns an environment variable (from owly.yaml) or def if unset.
func Env(key, def string) string

// Files reads static files from the project's public directory via the
// owly:project/files host interface.
var Files = filesAPI{}
func (filesAPI) Get(path string) ([]byte, error)

Reading static files

func init() {
http.HandleFunc("/page", func(w http.ResponseWriter, r *http.Request) {
html, err := owly.Files.Get("template.html")
if err != nil {
owly.Text(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(html)
})
}

Build

Go functions build with TinyGo. owly build runs it for you — no flags to remember. See Build & deploy.