3.Golang的包导入
Posted leleyao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3.Golang的包导入相关的知识,希望对你有一定的参考价值。
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 前会将所有变量初始化
以上是关于3.Golang的包导入的主要内容,如果未能解决你的问题,请参考以下文章
尽管覆盖了 onSaveInstanceState,但片段的包在 onCreate 中为空