io/fs: package io/fs is not in GOROOT (D:\go\src\io\fs)

问题陈述:

loga/kafka imports
        github.com/Shopify/sarama imports
        github.com/klauspost/compress/zstd tested by
        github.com/klauspost/compress/zstd.test imports
        github.com/klauspost/compress/zip imports
        io/fs: package io/fs is not in GOROOT (D:\go\src\io\fs)

说明这个包中没有这个模块 到github去查询

在这里插入图片描述
点击右侧的Release

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用`embed.FS`中提供的`ReadFile`函数读取压缩文件,并使用`gzip`包对文件内容进行解压缩。以下是一个示例代码: ```go package main import ( "embed" "compress/gzip" "io/ioutil" "net/http" "github.com/gin-gonic/gin" ) //go:embed index.html.gz favicon.ico.gz assets static serverConfig.json.gz logo.svg.gz var Static embed.FS func main() { r := gin.Default() // Serve index.html htmlData, err := Static.ReadFile("index.html.gz") if err != nil { panic(err) } r.GET("/", func(c *gin.Context) { c.Header("Content-Encoding", "gzip") c.Data(http.StatusOK, "text/html", htmlData) }) // Serve favicon.ico icoData, err := Static.ReadFile("favicon.ico.gz") if err != nil { panic(err) } r.GET("/favicon.ico", func(c *gin.Context) { c.Header("Content-Encoding", "gzip") c.Data(http.StatusOK, "image/x-icon", icoData) }) // Serve assets r.StaticFS("/assets", http.FS(Static.Dir("assets"))) // Serve static r.StaticFS("/static", http.FS(Static.Dir("static"))) // Serve serverConfig.json configData, err := Static.ReadFile("serverConfig.json.gz") if err != nil { panic(err) } r.GET("/serverConfig.json", func(c *gin.Context) { c.Header("Content-Encoding", "gzip") c.Data(http.StatusOK, "application/json", configData) }) // Serve logo.svg logoData, err := Static.ReadFile("logo.svg.gz") if err != nil { panic(err) } r.GET("/logo.svg", func(c *gin.Context) { c.Header("Content-Encoding", "gzip") c.Data(http.StatusOK, "image/svg+xml", logoData) }) // Run server r.Run(":8080") } ``` 在上面的代码中,我们使用`embed.FS`嵌入了多个压缩文件,并在不同的路由中提供了这些文件的访问。对于每个压缩文件,我们使用`ReadFile`函数读取文件内容,然后使用`gzip`包对其进行解压缩,并将解压缩后的内容返回给客户端。注意要在响应头中设置`Content-Encoding`为`gzip`,以告诉浏览器这是一个经过gzip压缩的响应。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值