What the endpoint gives you
The releases endpoint returns the most recently published release, which is not always the highest version number. With a valid license key for the product, the answer includes release notes and a signed download url on each file. Without one it holds only version and published_at, so the app can still say an update exists. Nothing published is a 404 with not_found; that means no update. The endpoint has its own budget of 120 requests per minute per IP address, separate from validation.
All of this lives in the Go backend, next to the validation client. The webview gets a small struct with the version and the notes, and calls a bound method when the user clicks.
Check for an update
Use the platform query to get only your files for this OS, plus files with no label. Clavem does not fix the labels; use what you typed when uploading. Labels may contain lowercase letters, digits, dots, dashes and underscores, so macos-arm64 works and runtime.GOARCH gives you the second half.
type File struct {
ID int64 `json:"id"`
Filename string `json:"filename"`
Size int64 `json:"size"`
Platform string `json:"platform"`
URL string `json:"url"` // signed, valid for one hour, present only with a valid key
}
type Release struct {
Version string `json:"version"`
Notes string `json:"notes"`
PublishedAt string `json:"published_at"`
Files []File `json:"files"`
}
func Platform() string {
name := map[string]string{"darwin": "macos", "windows": "windows", "linux": "linux"}[runtime.GOOS]
return name + "-" + runtime.GOARCH
}
// Latest returns nil, nil when nothing is published.
func (c *Client) Latest(ctx context.Context, key string) (*Release, error) {
ctx, cancel := context.WithTimeout(ctx, 8*time.Second)
defer cancel()
u := fmt.Sprintf("%s/v1/releases/%d/latest?platform=%s", c.Base, c.ProductID, url.QueryEscape(Platform()))
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
if err != nil {
return nil, err
}
req.Header.Set("X-License-Key", key) // the header keeps the key out of URLs and logs
res, err := c.HTTP.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
switch res.StatusCode {
case http.StatusOK:
var rel Release
if err := json.NewDecoder(io.LimitReader(res.Body, 1<<20)).Decode(&rel); err != nil {
return nil, err
}
return &rel, nil
case http.StatusNotFound:
return nil, nil
case http.StatusTooManyRequests:
return nil, errors.New("rate limited, retry after " + res.Header.Get("Retry-After") + " seconds")
}
return nil, fmt.Errorf("update check failed: HTTP %d", res.StatusCode)
}
Compare versions
golang.org/x/mod/semver compares semantic version strings, pre-release tags included, and requires a leading v:
import "golang.org/x/mod/semver"
func Newer(latest, current string) bool {
l, c := "v"+latest, "v"+current
return semver.IsValid(l) && semver.IsValid(c) && semver.Compare(l, c) > 0
}
Plain string comparison puts 3.10.0 before 3.9.2. In the run, Newer("3.10.0", "3.9.2") was true, Newer("3.2.0", "3.10.0") false, Newer("4.0.0", "4.0.0-beta.2") true, Newer("3.2", "3.1") true, and Newer("banana", "1.0.0") false, so an invalid string never prompts an update.
Download with resume and progress
Ask Latest again when the user clicks and use the fresh files[].url, because links last one hour. Then stream it to a .part file. If the file exists, ask for the rest with a Range header.
// Use a client with no overall Timeout: it would also cut off a long body read.
func Download(ctx context.Context, hc *http.Client, fileURL, dest string, progress func(done, total int64)) error {
part := dest + ".part"
var have int64
if st, err := os.Stat(part); err == nil {
have = st.Size()
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fileURL, nil)
if err != nil {
return err
}
if have > 0 {
req.Header.Set("Range", "bytes="+strconv.FormatInt(have, 10)+"-")
}
res, err := hc.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
flags := os.O_CREATE | os.O_WRONLY
switch res.StatusCode {
case http.StatusPartialContent:
flags |= os.O_APPEND // resuming
case http.StatusOK:
have = 0 // no Range support, or a fresh start
flags |= os.O_TRUNC
case http.StatusForbidden:
return errors.New("the download link expired: ask for a new one")
case http.StatusRequestedRangeNotSatisfiable:
_ = os.Remove(part) // stale part file: start again
return errors.New("partial download discarded, try again")
default:
return fmt.Errorf("download failed: HTTP %d", res.StatusCode)
}
f, err := os.OpenFile(part, flags, 0o644)
if err != nil {
return err
}
total := have + res.ContentLength
buf := make([]byte, 64<<10)
for {
n, rerr := res.Body.Read(buf)
if n > 0 {
if _, werr := f.Write(buf[:n]); werr != nil {
f.Close()
return werr
}
have += int64(n)
if progress != nil {
progress(have, total)
}
}
if rerr == io.EOF {
break
}
if rerr != nil {
f.Close()
return rerr // the .part file stays, so the next call resumes
}
}
if err := f.Close(); err != nil {
return err
}
return os.Rename(part, dest)
}
Pass a progress that emits to the webview: runtime.EventsEmit(ctx, "update:progress", ...) in Wails v2, app.Event.Emit("update:progress", ...) in v3. Throttle it to a few times a second.
What I ran
On the Go Playground, against an in-process mock of the documented shapes with no outbound network, so not the live API. A valid key returned version 3.10.0 with a file URL; a wrong key returned the version only, with no notes and no files. The request carried the key in X-License-Key and not in the URL, and platform=linux-amd64 on the playground’s platform. A 100,000-byte test file with a 40,000-byte part file resumed through a 206 and ended intact at 100,000 bytes, with progress reaching 100,000. The mock never exercised the 403 and 416 branches.
Applying the update
Clavem delivers files; replacing the app is yours. Run the installer and quit, because a running executable cannot reliably replace itself on Windows:
func Install(path string) error {
switch runtime.GOOS {
case "darwin":
return exec.Command("open", path).Start() // mounts a .dmg
case "windows":
return exec.Command(path).Start() // an installer .exe
default:
return exec.Command("xdg-open", path).Start()
}
}
After Install returns, call runtime.Quit(ctx) in v2 or app.Quit() in v3. Each uploaded file can be up to 5 GiB. Clavem has no delta updates and no auto-updater, and I found no checksum field in the release response, so publish a SHA-256 yourself if you want to verify downloads.
Doing this with Clavem
Upload each build in the dashboard with a version and a platform label, then publish it. Limits, storage per plan and the one-hour link rule are in the files docs.
Questions
Does Wails have a built-in updater?
I found none in the Wails documentation I read. Clavem does not patch apps either: it stores the files you upload, reports the latest release and hands out signed download links. Replacing the installed app is up to you.
Why does my download stop after 8 seconds?
You gave the HTTP client a Timeout. In net/http it covers reading the whole response body. Use a client without Timeout for downloads and a context deadline for the small API calls.