杜松子酒上的 router.Static() 和 router.Use(static.Serve()) 有什么区别?

What is difference between router.Static() and router.Use(static.Serve()) on the gin?

我刚刚阅读了 gin 的文档,发现有两种不同的方法可以将资产文件夹设置到服务器,一种是使用路由器的 Static() 方法,如下所示:

package main

import "github.com/gin-gonic/gin"

func main() {
        r := gin.Default()
        r.Static("/assets", "./assets")

然后另一个是使用静态中间件如下:

package main

import (
       "github.com/gin-gonic/gin"
       "github.com/gin-contrib/static"
)

func main() {
        r := gin.Default()
        r.Use(static.Serve("/", static.LocalFile("./assets", false)))

这两种方式在速度、副作用等方面有什么区别吗?

第一个选项from

Static serves files from the given file system root. Internally a http.FileServer is used, therefore http.NotFound is used instead of the Router's NotFound handler.

第二个选项link

Static returns a middleware handler that serves static files in the given directory.

两者都在后台使用 http.FileServer