2 回答

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

TA貢獻1815條經驗 獲得超13個贊
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 文件夾復制到您的 go 應用程序即可。
- 2 回答
- 0 關注
- 227 瀏覽
添加回答
舉報