💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## 嵌入 go > 1.16 * 只支持嵌入为string, byte slice和embed.FS三种类型,这三种类型的别名(alias)和命名类型(如type S string)都不可以 ## 示例 ### 字符串 ``` import _ "embed" //go:embed hello.txt var s string print(s) ``` ### 字节 ``` import _ "embed" //go:embed hello.txt var b []byte print(string(b)) ``` ### fs.FS ``` import "embed" //go:embed hello.txt var f embed.FS data, _ := f.ReadFile("hello.txt") print(string(data)) // content holds our static web server content. //go:embed image/* template/* //go:embed html/index.html var content embed.FS ``` ## net/http ``` //go:embed public/* var fsys embed.FS func main() { http.Handle("/", http.FileServer(http.FS(fsys))) http.ListenAndServe(":8080", nil) } ```