1.golang的源码文件可以随意命名,但是属于同一个包的源文件必须声明 package base
2.golang的包引入规则
import ( "fmt" #系统包直接写名字 "github.com/user/stringutil" #其余包 写 src 下的绝对路径 )
go help importpath
A few common code hosting sites have special syntax:
Bitbucket (Git, Mercurial)
import "bitbucket.org/user/project"
import "bitbucket.org/user/project/sub/directory"
GitHub (Git)
import "github.com/user/project"
import "github.com/user/project/sub/directory"
Launchpad (Bazaar)
import "launchpad.net/project"
import "launchpad.net/project/series"
import "launchpad.net/project/series/sub/directory"
import "launchpad.net/~user/project/branch"
import "launchpad.net/~user/project/branch/sub/directory"
IBM DevOps Services (Git)
import "hub.jazz.net/git/user/project"
import "hub.jazz.net/git/user/project/sub/directory"
#### 导入的包还可以有以下几种方式
import (
. "launchpad.net/project/series/sub/directory" 不用包名直接引用func
lele "launchpad.net/project/series/sub/directory" 使用自建别名
_ "launchpad.net/project/series/sub/directory" 不再使用该包 相当于注释
)
3.包初始化函数
func init()
执行init 前会将所有变量初始化