Genresource
This is a utility used for converting ../gokserver
to a resource.go file.
It allows go binaries to contain resource. Extract resource with the following function.
func UnpackResource() {
orignal, err := hex.DecodeString(Resource)
if err != nil {
errExit(err, "")
}
unzip, err := gzip.NewReader(bytes.NewBuffer([]byte(orignal)))
if err != nil {
errExit(err, "")
}
untar := tar.NewReader(unzip)
var fileContent bytes.Buffer
for h, err := untar.Next(); err == nil; h, err = untar.Next() {
fileContent.Reset()
io.Copy(&fileContent, untar)
var name string
if h.Name[0] == '/' {
name = h.Name[1:]
} else {
name = h.Name
}
if strings.Contains(name, "/") {
lstIndx := strings.LastIndex(name, "/")
if err := os.MkdirAll(name[0:lstIndx], 0744); err != nil {
errExit(err, "")
}
}
ioutil.WriteFile(name, fileContent.Bytes(), os.FileMode(h.Mode))
}
}