-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild_ui.go
More file actions
58 lines (51 loc) · 1.15 KB
/
build_ui.go
File metadata and controls
58 lines (51 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:build ignore
// +build ignore
package main
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
)
const (
defaultUIReleaseURL = "https://github.com/gigapi/gigapi-ui/releases/latest/download/release.zip"
uiZipFile = "ui.zip"
targetDir = "querier"
)
func main() {
uiReleaseURL := getenv("UI_RELEASE_URL", defaultUIReleaseURL)
zipFilePath := filepath.Join(targetDir, uiZipFile)
// Download the UI zip file
fmt.Println("Downloading UI release from:", uiReleaseURL)
if err := downloadFile(uiReleaseURL, zipFilePath); err != nil {
exitf("Error downloading UI: %v", err)
}
}
func getenv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}
func exitf(format string, a ...interface{}) {
fmt.Printf(format+"\n", a...)
os.Exit(1)
}
func downloadFile(url, filepath string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("bad status: %s", resp.Status)
}
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
return err
}