fish 2 months ago
parent
commit
be2e3b2bab
7 changed files with 306 additions and 1 deletions
  1. 1 0
      .gitignore
  2. 32 1
      README.md
  3. 11 0
      assets/index.html
  4. 235 0
      bindata.go
  5. 5 0
      go.mod
  6. 2 0
      go.sum
  7. 20 0
      main.go

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+my-go-project

+ 32 - 1
README.md

@@ -1,3 +1,34 @@
 # go-bindata
 
-web项目资源文件打包进二进制中
+web项目资源文件打包进二进制中
+
+
+## Develop
+
+```
+go mod init my-go-project
+go get github.com/gin-gonic/gin
+
+export PATH=$PATH:$(go env GOPATH)/bin
+
+
+GOPROXY=https://mirrors.aliyun.com/goproxy/,direct;GO111MODULE=auto
+GOPROXY=https://goproxy.cn,direct;GO111MODULE=auto
+
+go get -u github.com/go-bindata/go-bindata/...
+
+
+静态打包
+go-bindata-assetfs -o=vue/vue.go -pkg=vue vue/dist/...
+
+go-bindata -o bindata.go -pkg main assets/...
+
+go build
+go run main.go bindata.go
+
+```
+
+## License
+
+## Reference
+

+ 11 - 0
assets/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>index</title>
+</head>
+<body>
+    你好。html
+</body>
+</html>

+ 235 - 0
bindata.go

@@ -0,0 +1,235 @@
+// Code generated by go-bindata. DO NOT EDIT.
+// sources:
+// assets/index.html
+package main
+
+import (
+	"bytes"
+	"compress/gzip"
+	"fmt"
+	"io"
+	"io/ioutil"
+	"os"
+	"path/filepath"
+	"strings"
+	"time"
+)
+
+func bindataRead(data []byte, name string) ([]byte, error) {
+	gz, err := gzip.NewReader(bytes.NewBuffer(data))
+	if err != nil {
+		return nil, fmt.Errorf("Read %q: %v", name, err)
+	}
+
+	var buf bytes.Buffer
+	_, err = io.Copy(&buf, gz)
+	clErr := gz.Close()
+
+	if err != nil {
+		return nil, fmt.Errorf("Read %q: %v", name, err)
+	}
+	if clErr != nil {
+		return nil, err
+	}
+
+	return buf.Bytes(), nil
+}
+
+type asset struct {
+	bytes []byte
+	info  os.FileInfo
+}
+
+type bindataFileInfo struct {
+	name    string
+	size    int64
+	mode    os.FileMode
+	modTime time.Time
+}
+
+func (fi bindataFileInfo) Name() string {
+	return fi.name
+}
+func (fi bindataFileInfo) Size() int64 {
+	return fi.size
+}
+func (fi bindataFileInfo) Mode() os.FileMode {
+	return fi.mode
+}
+func (fi bindataFileInfo) ModTime() time.Time {
+	return fi.modTime
+}
+func (fi bindataFileInfo) IsDir() bool {
+	return false
+}
+func (fi bindataFileInfo) Sys() interface{} {
+	return nil
+}
+
+var _assetsIndexHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4c\x8f\x3d\x6e\xc3\x30\x0c\x85\x77\x9d\x82\xd5\x5c\x57\xed\xd6\x81\xf2\xd2\x9f\xb5\x1d\xdc\xa1\xa3\x22\x11\x31\x01\x59\x0e\x6c\xc2\x4e\xb6\x20\x27\xc9\x92\x63\xf8\x34\x49\xee\x11\xd8\x42\x80\x4c\xc4\xe3\x47\x10\xdf\xc3\xa7\xcf\x9f\x8f\xea\xff\xf7\x0b\x6a\x69\x62\xa9\x70\x1e\x10\x5d\x5a\x5b\x4d\x49\xcf\x0b\x72\xa1\x54\x00\x00\xd8\x90\x38\xf0\xb5\xeb\x7a\x12\xab\xff\xaa\xef\xe2\x5d\x3f\xa2\xe4\x1a\xb2\x7a\x60\x1a\x37\x6d\x27\x1a\x7c\x9b\x84\x92\x58\x3d\x72\x90\xda\x06\x1a\xd8\x53\xb1\x84\x67\xe0\xc4\xc2\x2e\x16\xbd\x77\x91\xec\xdb\xcb\xeb\xfd\x95\xb0\x44\x2a\x39\x05\xda\xa2\xc9\x41\xa1\xc9\x1a\xb8\x6a\xc3\x2e\xdf\x5d\xa6\xe3\xf5\x34\x9d\xf7\x87\xd9\x58\xa1\xc9\x04\xcd\xd2\xe3\x16\x00\x00\xff\xff\x6d\xa3\xa0\x01\xd7\x00\x00\x00")
+
+func assetsIndexHtmlBytes() ([]byte, error) {
+	return bindataRead(
+		_assetsIndexHtml,
+		"assets/index.html",
+	)
+}
+
+func assetsIndexHtml() (*asset, error) {
+	bytes, err := assetsIndexHtmlBytes()
+	if err != nil {
+		return nil, err
+	}
+
+	info := bindataFileInfo{name: "assets/index.html", size: 215, mode: os.FileMode(420), modTime: time.Unix(1728264874, 0)}
+	a := &asset{bytes: bytes, info: info}
+	return a, nil
+}
+
+// Asset loads and returns the asset for the given name.
+// It returns an error if the asset could not be found or
+// could not be loaded.
+func Asset(name string) ([]byte, error) {
+	cannonicalName := strings.Replace(name, "\\", "/", -1)
+	if f, ok := _bindata[cannonicalName]; ok {
+		a, err := f()
+		if err != nil {
+			return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
+		}
+		return a.bytes, nil
+	}
+	return nil, fmt.Errorf("Asset %s not found", name)
+}
+
+// MustAsset is like Asset but panics when Asset would return an error.
+// It simplifies safe initialization of global variables.
+func MustAsset(name string) []byte {
+	a, err := Asset(name)
+	if err != nil {
+		panic("asset: Asset(" + name + "): " + err.Error())
+	}
+
+	return a
+}
+
+// AssetInfo loads and returns the asset info for the given name.
+// It returns an error if the asset could not be found or
+// could not be loaded.
+func AssetInfo(name string) (os.FileInfo, error) {
+	cannonicalName := strings.Replace(name, "\\", "/", -1)
+	if f, ok := _bindata[cannonicalName]; ok {
+		a, err := f()
+		if err != nil {
+			return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
+		}
+		return a.info, nil
+	}
+	return nil, fmt.Errorf("AssetInfo %s not found", name)
+}
+
+// AssetNames returns the names of the assets.
+func AssetNames() []string {
+	names := make([]string, 0, len(_bindata))
+	for name := range _bindata {
+		names = append(names, name)
+	}
+	return names
+}
+
+// _bindata is a table, holding each asset generator, mapped to its name.
+var _bindata = map[string]func() (*asset, error){
+	"assets/index.html": assetsIndexHtml,
+}
+
+// AssetDir returns the file names below a certain
+// directory embedded in the file by go-bindata.
+// For example if you run go-bindata on data/... and data contains the
+// following hierarchy:
+//     data/
+//       foo.txt
+//       img/
+//         a.png
+//         b.png
+// then AssetDir("data") would return []string{"foo.txt", "img"}
+// AssetDir("data/img") would return []string{"a.png", "b.png"}
+// AssetDir("foo.txt") and AssetDir("notexist") would return an error
+// AssetDir("") will return []string{"data"}.
+func AssetDir(name string) ([]string, error) {
+	node := _bintree
+	if len(name) != 0 {
+		cannonicalName := strings.Replace(name, "\\", "/", -1)
+		pathList := strings.Split(cannonicalName, "/")
+		for _, p := range pathList {
+			node = node.Children[p]
+			if node == nil {
+				return nil, fmt.Errorf("Asset %s not found", name)
+			}
+		}
+	}
+	if node.Func != nil {
+		return nil, fmt.Errorf("Asset %s not found", name)
+	}
+	rv := make([]string, 0, len(node.Children))
+	for childName := range node.Children {
+		rv = append(rv, childName)
+	}
+	return rv, nil
+}
+
+type bintree struct {
+	Func     func() (*asset, error)
+	Children map[string]*bintree
+}
+var _bintree = &bintree{nil, map[string]*bintree{
+	"assets": &bintree{nil, map[string]*bintree{
+		"index.html": &bintree{assetsIndexHtml, map[string]*bintree{}},
+	}},
+}}
+
+// RestoreAsset restores an asset under the given directory
+func RestoreAsset(dir, name string) error {
+	data, err := Asset(name)
+	if err != nil {
+		return err
+	}
+	info, err := AssetInfo(name)
+	if err != nil {
+		return err
+	}
+	err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
+	if err != nil {
+		return err
+	}
+	err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
+	if err != nil {
+		return err
+	}
+	err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// RestoreAssets restores an asset under the given directory recursively
+func RestoreAssets(dir, name string) error {
+	children, err := AssetDir(name)
+	// File
+	if err != nil {
+		return RestoreAsset(dir, name)
+	}
+	// Dir
+	for _, child := range children {
+		err = RestoreAssets(dir, filepath.Join(name, child))
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func _filePath(dir, name string) string {
+	cannonicalName := strings.Replace(name, "\\", "/", -1)
+	return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
+}
+

+ 5 - 0
go.mod

@@ -0,0 +1,5 @@
+module my-go-project
+
+go 1.21.4
+
+require github.com/go-bindata/go-bindata v1.0.0 // indirect

+ 2 - 0
go.sum

@@ -0,0 +1,2 @@
+github.com/go-bindata/go-bindata v1.0.0 h1:DZ34txDXWn1DyWa+vQf7V9ANc2ILTtrEjtlsdJRF26M=
+github.com/go-bindata/go-bindata v1.0.0/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=

+ 20 - 0
main.go

@@ -0,0 +1,20 @@
+package main
+
+import (
+    "net/http"
+    "log"
+)
+
+func main() {
+    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+        data, err := Asset("assets/index.html") // 访问打包的文件
+        if err != nil {
+            http.Error(w, "File not found", http.StatusNotFound)
+            return
+        }
+        w.Write(data)
+    })
+
+    log.Println("Listening on :8080")
+    log.Fatal(http.ListenAndServe(":8080", nil))
+}