2017-09-19 3 views
0

내 코드에 어떤 문제가 있는지 이해하는 데 문제가 있습니다. Visual Studio 코드 컴파일러는 "util"패키지가 정의되지 않았기 때문에 다음과 같은 오류를 표시합니다.왜 Go 패키지가 정의되지 않은 것으로 표시됩니까?

'Error' message: 'undefined: util.GetPortAndURL 

나는

package util 

내가 또한 하나가 내 handlers.go 파일의 util을/패키지의 Myproj을 수입하고있어 내 util.go 파일의 맨 위에 다음을 배치하고 있습니다 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 (정의)가 동일한 패키지에있는 경우 패키지 접두어.

관련 문제