Validate a licence key
One POST to /apps/{appId}/licenses/authenticate. Go 1.21+. Standard library only.
package licence
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"time"
)
type Result struct {
Authenticated bool `json:"authenticated"`
Subscription *struct {
Level int `json:"level"`
Name string `json:"name"`
Active bool `json:"active"`
} `json:"subscription"`
}
func Verify(key string) (*Result, error) {
body, _ := json.Marshal(map[string]string{"licenseKey": key})
url := fmt.Sprintf("https://api.evora.lol/api/developer-api/apps/%s/licenses/authenticate", os.Getenv("EVORA_APP_ID"))
req, _ := http.NewRequest("POST", url, bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("EVORA_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := (&http.Client{Timeout: 10 * time.Second}).Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var out Result
return &out, json.NewDecoder(res.Body).Decode(&out)
}