如何使用 Go 在 Cloud Function 中提供swagger-ui-dist ?
在 Cloud Functions 环境之外,我会这样做:
package main
import (
"fmt"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("./swagger-ui-dist"))
http.Handle("/swaggerui/", http.StripPrefix("/swaggerui/", fs))
http.ListenAndServe(":8080", nil)
}
但由于云函数使用标准 http.HanlderFunc 接口使用普通函数作为处理程序,我不知道如何使其工作。
我试图模拟这种情况以使用 http.ServeFile 进行测试,但没有奏效。似乎没有下载文件夹的所有内容。
package main
import (
"fmt"
"net/http"
)
func cloudFunctionHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./swagger-ui-dist")
}
func main() {
http.HanldeFunc("/swaggerui/", handler)
http.ListenAndServe(":8080", nil)
}
MMTTMM
ITMISS
相关分类