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

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

在 golang 中將無服務器功能部署到 digitalocean

在 golang 中將無服務器功能部署到 digitalocean

Go
搖曳的薔薇 2023-03-07 11:14:26
我正在嘗試在數字海洋無服務器功能中構建一個 CRUD。我正在使用 sqlite3 進行測試并插入到表中。當我嘗試將其部署到產品中時,出現錯誤。這是我的代碼:package mainimport (    "database/sql"    "fmt"    _ "github.com/mattn/go-sqlite3")func Main(args map[string]interface{}) map[string]interface{} {db, err := sql.Open("sqlite3", "./data.db")checkErr(err)// insertstmt, err := db.Prepare("INSERT INTO userinfo(username, departname, created) values(?,?,?)")checkErr(err)res, err := stmt.Exec("rumi", "CSE", "2012-12-09")checkErr(err)id, err := res.LastInsertId()checkErr(err)fmt.Println(id)db.Close()msg := make(map[string]interface{})msg["body"] = idreturn msg}我得到的錯誤:?  functions git:(master) ? doctl serverless deploy . --remote-buildDeploying '/home/rumi/go/src/github.com/manjurulhoque/digitalocean-cloud-functions/functions'  to namespace 'fn-b799454253a-a40440-4639-937f-05102a48c06e'  on host 'https://fa45as-sgp1-18b45c02afgc.doserverless.co'Submitted action 'blog/createBlog' for remote building and deployment in runtime go:default (id: b3d5421ee5656bb44c4295421eebb44c642cf)Submitted action 'sample/hello' for remote building and deployment in runtime go:default (id: b3d5421ee5656bb44c4295421eebb44c642cf)Submitted action 'blog/db' for remote building and deployment in runtime go:default (id: edcc9eefce9f4aa58c9eefce9f2aa5e6)Transcript of remote build session for action 'blog/db':Output of failed build in /tmp/slices/builds/fn-b79956253a-a4080-465639-95637f-05102a48c06e/blog_db/2022-10-22T04-23-08.642Z/packages/blog/dbinitializing modulesgo: creating new go.mod: module execgo: to add module requirements and sums:        go mod tidybuildingdb.go:6:2: no required module provides package github.com/mattn/go-sqlite3; to add it:        go get github.com/mattn/go-sqlite3Deployed functions ('doctl sbx fn get <funcName> --url' for URL):  - blog/createBlog  - sample/helloFailures:Error: While deploying action 'blog/db': './build.sh' exited with code 1雖然我沒有找到任何好的資源來連接到數據庫。任何幫助,將不勝感激。
查看完整描述

1 回答

?
天涯盡頭無女友

TA貢獻1831條經驗 獲得超9個贊

在 DO 中,每個函數本身都是一個應用程序。所以你需要在每個函數目錄中創建go.mod和。go.sum

下面是我的項目結構之一

http://img1.sycdn.imooc.com//6406ac5600011d6602620798.jpg

注意:我寫了一篇關于如何為 DO 設置 golang 應用程序的文章 https://medium.com/@manzurulhoque/use-package-in-digital-ocean-do-serverless-functions-using-golang-cb5200ab22ee


查看完整回答
反對 回復 2023-03-07
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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