5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 05:50:08 +08:00
wails/v2/pkg/menu/colours/colours.go
Eng Zer Jun ef8d7d2fd7
refactor: move from io/ioutil to io and os packages
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-11-25 12:15:43 +08:00

67 lines
1.1 KiB
Go

package main
import (
"bytes"
_ "embed"
"encoding/json"
"io"
"log"
"net/http"
"os"
"path/filepath"
"text/template"
)
type Rgb struct {
R uint8 `json:"r"`
G uint8 `json:"g"`
B uint8 `json:"b"`
}
type Hsl struct {
H float64 `json:"h"`
S float64 `json:"s"`
L float64 `json:"l"`
}
type InputCol struct {
Colorid uint8 `json:"colorId"`
Hexstring string `json:"hexString"`
Rgb Rgb `json:"rgb"`
Hsl Hsl `json:"hsl"`
Name string `json:"name"`
}
//go:embed gen.tmpl
var Template string
func main() {
var Cols []InputCol
resp, err := http.Get("https://jonasjacek.github.io/colors/data.json")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(data, &Cols)
if err != nil {
log.Fatal(err)
}
t, err := template.New("cols").Parse(Template)
if err != nil {
log.Fatal(err)
}
var buffer bytes.Buffer
err = t.Execute(&buffer, Cols)
if err != nil {
log.Fatal(err)
}
os.WriteFile(filepath.Join("..", "cols.go"), buffer.Bytes(), 0755)
}