오늘도 한 뼘 더
[Golang] package ... is not in GOROOT 에러 해결하기 본문
728x90
반응형
# 문제
Golang 프로젝트를 새로 만들고 다음 코드에 대해 main.go를 실행하는 중에 다음과 같은 에러가 발생했다.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello")
}
- 에러 메시지
# 해결방법
go에서 제공하는 문서를 참고하여 진행하였다.
https://go.dev/blog/using-go-modules
Using Go Modules - The Go Programming Language
Using Go Modules Tyler Bui-Palsulich and Eno Compton 19 March 2019 Introduction This post is part 1 in a series. Note: For documentation on managing dependencies with modules, see Managing dependencies. Go 1.11 and 1.12 include preliminary support for modu
go.dev
go module 추가
실행하고자 하는 프로젝트에 모듈을 추가하는 명령어를 실행한다.
go mod init
실행을 하면 다음과 같이 go.mod가 만들어진다는 메시지가 뜬다.
프로젝트에 go.mod가 뜬 걸 확인할 수 있다.
다시 main.go를 실행하면 정상적으로 작동이 된다.
728x90
반응형
'Study > Go' 카테고리의 다른 글
[Golang] DB 연결할 때, timeout 설정하기 (context) (0) | 2022.09.02 |
---|---|
[Golang] Go 환경변수 쓰기/ 읽기 (0) | 2022.08.31 |
[Golang] .env 사용하여 환경변수 설정 (0) | 2022.08.30 |
[Golang] sql: unknown driver "mysql" (forgotten import?) 에러 해결하기 (0) | 2022.08.27 |
[Go] GoLand 설치(Go 설치) (0) | 2020.12.17 |
Comments