如何将 magickWand 引用传递给函数

main_test.go


package main_test


import (

    "log"

    "os"

    "testing"

    "."

)


func TestMain(m *testing.M) {

    a = main.App{}

    a.Init(

        os.Getenv("TEST_DB_USERNAME"),

        os.Getenv("TEST_DB_PASSWORD"),

        os.Getenv("TEST_DB_NAME"))


    ensureTableExists()

    code := m.Run()

    clearTable()

    os.Exit(code)

}

app.go


package main


import (

    "database/sql"

    "fmt"

    "log"


    "github.com/gorilla/mux"

    _ "github.com/lib/pq"

)


type App struct {

    Router *mux.Router

    DB *sql.DB

}


func (a *App) Init(user, password, dbname string) {


    connection := fmt.Sprintf("user=%s password=%s dbname=%s", user, password, dbname)

    var err error

    a.DB, err = sql.Open("postgres", connection)

    if err != nil {

        log.Fatal(err)

    }

    a.Router = mux.NewRouter()


}

func (a *App) Run(addr string) { }

主程序


package main


import "os"


func main() {

    a := App{}

    a.Init(

        os.Getenv("APP_DB_USERNAME"),

        os.Getenv("APP_DB_PASSWORD"),

        os.Getenv("APP_DB_NAME"))

    a.Run(":8080")

}

大家好,我是 Golang 的新手,正在学习一些教程。在本教程中,他们使用导入语句“.”。这对我来说是一个错误。确切的错误是“非规范导入路径”。我尝试使用相对路径和完整路径来访问项目中的主文件,但是当我使用“.”以外的任何其他内容时。var a.main.App 抛出一个错误,指出 main 是一个未解析的类型。我的 $GOPATH 设置为 c:/users/me/go/src 我的项目位于 src 文件夹中。我不完全确定目前我的代码有什么问题。如果这是显而易见的事情,我深表歉意。


这是我要导入的内容。这存在于一个名为 app.go 的文件中,该文件通过 main.go 调用


type App struct {

    Router *mux.Router

    DB *sql.DB

}


眼眸繁星
浏览 51回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP