The Go Blog

Package

bantana
22 June 2015

Golag的package组织管理

程序路径

$GOPATH/src/github.com/go-martini/martini

包头声明

package martini

编译后存储路径

$GOAPTH/pkg/darwin_amd64/github.com/go-martini/martini.a

包名的导入路径和包名最好一致

包名的导入路径和包名最好一致,虽然它们可以不一致。

例如:

src path

$GOPATH/src/github.com/bantana/newmathabc
$GOPATH/src/github.com/bantana/newmathabc/newmath.go

pkackage name for newmath.go

package newmath

main.go

package main
import (
  "fmt"

  "github.com/bantana/newmathabc"
)

func main () {
  x := 20.0
  z := newmath.Sqrt(x)
  fmt.Println(z)
}

Related articles