[Go] embed指令嵌入静态文件到二进制包
go 1.16开始提供了embed指令 , 可以将静态资源嵌入到编译包里面
这样就可以把网页模板等文件直接打包了,就不需要每次还要拷贝静态文件
常规用法:
import _ "embed"
//go:embed hello.txt
var s string
func main() {
print(s)
}
go 1.16开始提供了embed指令 , 可以将静态资源嵌入到编译包里面
这样就可以把网页模板等文件直接打包了,就不需要每次还要拷贝静态文件
常规用法:
import _ "embed"
//go:embed hello.txt
var s string
func main() {
print(s)
}

![[Go] embed指令嵌入静态文件到二进制包](https://www.zixueka.com/wp-content/uploads/2024/01/1706706813-5e25cfbb9877301.jpg)
