December 28, 2023
Call your code from another module - The Go Programming Language
아래의 명령어를 통해 모듈 생성
go mod init example.com/hello
main 함수 작성
package main
import (
"fmt"
"example.com/greetings"
)
func main() {
// Get a greeting message and print it.
message := greetings.Hello("Gladys")
fmt.Println(message)
}
example.com/greetings 모듈을 로컬의 것을 사용하도록 수정새롭게 생성한 hello 모듈 내에서 아래의 명령어를 실행
go mod edit -replace example.com/greetings=../greetings
위 명령어를 실행한 후에는 go.mod 파일 내용이 아래와 같이 수정됨
module example.com/hello
go 1.16
replace example.com/greetings => ../greetings
go run .