Go
Go examples using the standard library net/http.
Prerequisites
- Go 1.18+
OTTR_API_KEYenvironment variable
Create Approval
main.go
// Create approval
body := map[string]any{
"key_path": "deploy/prod",
"value": "approved",
"ttl_seconds": 600,
"info": "Deploy to production?",
}
jsonBody, _ := json.Marshal(body)
req, _ := http.NewRequest("POST", "https://api.ottr.run/v1/approvals", bytes.NewBuffer(jsonBody))
req.Header.Set("Authorization", "Bearer "+os.Getenv("OTTR_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var result struct{ URL string `json:"url"` }
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println("Approval URL:", result.URL)Poll for Result
main.go
// Poll for approval
for {
req, _ := http.NewRequest("GET", "https://api.ottr.run/v1/key/deploy/prod", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("OTTR_API_KEY"))
resp, _ := http.DefaultClient.Do(req)
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if string(body) == "approved" {
fmt.Println("Approved!")
// ... proceed with deployment
break
}
time.Sleep(5 * time.Second)
}