binctr/generate.go
Jess Frazelle 0186c7808b cleanup
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
2018-03-19 22:21:14 -04:00

40 lines
886 B
Go

// +build ignore
package main
import (
"encoding/base64"
"io/ioutil"
"os"
"path/filepath"
)
// Reads image.tar and saves as a constant in rootfs.go
func main() {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
out, err := os.Create(filepath.Join(wd, "image", "data.go"))
if err != nil {
panic(err)
}
tarPath := filepath.Join(wd, "image.tar")
out.Write([]byte("// Package image is autogenerated; DO NOT EDIT DIRECTLY\n"))
out.Write([]byte("// See generate.go for more info\n"))
out.Write([]byte("package image\n\n"))
out.Write([]byte("const (\n"))
out.Write([]byte("\t// DATA is the image data that is embessed at compile time.\n"))
out.Write([]byte("\tDATA = `"))
f, err := ioutil.ReadFile(tarPath)
if err != nil {
panic(err)
}
tar := base64.StdEncoding.EncodeToString(f)
out.Write([]byte(tar))
out.Write([]byte("`\n"))
out.Write([]byte(")\n"))
}