亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Golang 服務器進行 Flutter Web

使用 Golang 服務器進行 Flutter Web

Go
慕田峪4524236 2023-08-14 15:04:24
是否可以使用 golang 服務器運行 flutter web build?Golang 具有提供 html 文件的功能,而 flutter web 則以 index.html 和 js 文件的形式提供輸出。如果可能的話 golang 代碼應該是什么樣子?
查看完整描述

2 回答

?
阿晨1998

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)


查看完整回答
反對 回復 2023-08-14
?
蕭十郎

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 應用程序即可。


查看完整回答
反對 回復 2023-08-14
  • 2 回答
  • 0 關注
  • 227 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號