Golang go mod 入門
Golang: go mod 起手式. Golang 套件到底要怎麼用?!
Last updated
Golang: go mod 起手式. Golang 套件到底要怎麼用?!
Last updated
-hello_GOPATH/
- main.go
- src/
- hello/
- hello.gogo env -w GOPATH=$(pwd)package hello
import "fmt"
func PrintHello() { // fun大寫代表public(才能夠被存取)
fmt.Println("hello world")
}ln -s `pwd`/hello $(go env GOPATH)/srcpackage main
import "hello" // src/hello 資料夾下
func main() {
hello.PrintHello()
}-hello/
- main.go
- go.mod
- hello/
- hello.gomodule hello //產生出來的模組名
go 1.15 // golang 現在的版本package hello
import "fmt"
func PrintHello() { // fun大寫代表public(才能夠被存取)
fmt.Println("hello world")
}package main
import "hello/hello" //module/package name
func main() {
hello.PrintHello()
}