2 回答

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
正如友好的文檔提到的那樣,我相信您必須構(gòu)建您的應(yīng)用程序。
https://flutter.dev/docs/get-started/web#build
運(yùn)行以下命令生成發(fā)布版本:
flutter build web
這會(huì)使用構(gòu)建的文件填充 build/web 目錄,包括需要一起提供的資產(chǎn)目錄。
golang 代碼應(yīng)該是什么樣子?
就像任何其他常規(guī) HTTP golang 服務(wù)器一樣。
http.Handle("/build/web/", http.StripPrefix("/build/web/", http.FileServer(http.Dir("build/web")))) http.ListenAndServe(":8080", nil)

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
package main
import (
"flag"
"log"
"net/http"
)
func main() {
port := flag.String("p", "8181", "port to serve on")
directory := flag.String("d", "web", "the directory of static file to host")
flag.Parse()
http.Handle("/", http.FileServer(http.Dir(*directory)))
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
}
只需將 web 文件夾復(fù)制到您的 go 應(yīng)用程序即可。
- 2 回答
- 0 關(guān)注
- 219 瀏覽
添加回答
舉報(bào)