Last active
July 24, 2020 08:48
-
-
Save yanue/f62b101474464042602738a701146ae5 to your computer and use it in GitHub Desktop.
go使用go-bindata打包静态资源并还原文件 - embed static files into Go binaries and restore files when launch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"path" | |
"bindata" | |
) | |
// step1. go get -u github.com/go-bindata/go-bindata | |
// step2. go:generate | |
// link: https://jaycechant.info/2020/go-bindata-golang-static-resources-embedding/ | |
// Before buildling, run go generate. | |
//go:generate go-bindata -o=bindata/bindata.go -ignore="\\.DS_Store|desktop.ini" -pkg=bindata assets/... | |
func main() { | |
RestoreAllAssets() | |
} | |
func RestoreAllAssets() { | |
assets := bindata.AssetNames() | |
for _, s := range assets { | |
err := bindata.RestoreAsset("", s) | |
if err != nil { | |
log.Println("RestoreAsset err:", err.Error()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment