zoukankan      html  css  js  c++  java
  • 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 前会将所有变量初始化

      

  • 相关阅读:
    【巷子】:关于Apply、call、bind的详解
    关于this的指向问题
    SOA和微服务之间的区别
    业务系统如何微服务化
    微服务架构的理论基础
    每个架构师都应该研究下康威定律
    Rabbit MQ
    Scalability, Availability & Stability Patterns
    应用层协议
    SSO
  • 原文地址:https://www.cnblogs.com/leleyao/p/10917183.html
Copyright © 2011-2022 走看看