2017-09-19 12 views
0

下記のコードで何が問題なのか理解できません。 Visual Studioのコードコンパイラは、パッケージ "util"が定義されていないため、以下のようなエラーが出ます。Goパッケージが定義されていないと表示されるのはなぜですか?

私は、一つである私のhandlers.goファイル、内UTIL /パッケージにmyprojをインポートしています私のutil.goファイルの先頭

package util 

で次のように配置することだ

'Error' message: 'undefined: util.GetPortAndURL 

そのinitメソッドで以下のコードを呼び出します。

file, err := ioutil.ReadFile("./creds.json") 
if err != nil { 
    fmt.Printf("File error: %v\n", err) 
    // use a better error pattern here 
} 
json.Unmarshal(file, &oathCred) 
port, url := util.GetPortAndURL() <-------- Here 
if (port != nil) && (url != nil) { 
    oathConf = &oauth2.Config{ 
     ClientID:  oathCred.ClientID, 
     ClientSecret: oathCred.ClientSecret, 
     RedirectURL: url + ":" + string(port) + "/auth", 
     Scopes: []string{ 
      "https://www.googleapis.com/auth/userinfo.email", // You have to select your own scope from here -> https://developers.google.com/identity/protocols/googlescopes#google_sign-in 
     }, 
     Endpoint: google.Endpoint, 
    } 
} 

getPortAndURL()関数はutil.goにあり、

// GetPortandURL returns the URL and Port currently used 
/* 
' 
This function should be used to set the port and url for the program until a 
set function is created. 
' 
*/ 
func GetPortandURL() (int, string) { 
    port := 8080 
    url := "http://127.0.0.1" 
    return port, url 
} 

マイGOPATHを次のようにあるCです:\ユーザーは\コードは\

ファイル構造行くミー\ドキュメント\します

go/src/ 
└── myproj 
    ├── handlers 
    ├── main 
    └── util 
+0

完全なエラーを質問に貼り付けます。また、GOPATH内のmyprojフォルダの場所 – Topo

+0

GetPortAndURLが定義されていないということです。あなたはそれを定義しましたか? – khrm

+0

はい、これをutil.goの関数として定義しました。私は方法を反映するために私の質問を編集しました。 –

答えて

0

port, url := GetPortAndURL()と呼びます。私はそれが "util"を必要としているとは思わない。 util.go(定義)が同じパッケージ内にある場合、パッケージ接頭辞。

関連する問題