安装
go get -u github.com/gobuffalo/packr/packr
go get -u github.com/gobuffalo/packr
当前目录:
[root@localhost d0116]# tree
.
├── go.mod
├── go.sum
├── static
│ ├── index2.html
│ ├── index.html
│ └── js
│ └── example.js
└── x.go
执行packr
[root@localhost d0116]# packr
[root@localhost d0116]# tree
.
├── a_main-packr.go
├── go.mod
├── go.sum
├── static
│ ├── index2.html
│ ├── index.html
│ └── js
│ └── example.js
└── x.go
2 directories, 7 files
build构建
[root@localhost d0116]# go build x.go a_main-packr.go
[root@localhost d0116]# tree
.
├── a_main-packr.go
├── go.mod
├── go.sum
├── static
│ ├── index2.html
│ ├── index.html
│ └── js
│ └── example.js
├── x
└── x.go
2 directories, 8 files
之后可执行文件x在任何位置都可以执行,不依赖于静态资源。
测试如下:
[root@localhost ~]# curl http://192.168.150.53:8080/js/example.js
var word = "Hello, itbsl";
alert(word);[root@localhost ~]#
[ro