• 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 前会将所有变量初始化

      

  • 相关阅读:
    扩展运算符(Spread operator)
    增强的对象字面量,解构赋值
    ES6 模板字符串(template string)
    let和const
    svg实现放大效果
    svg制作风车旋转
    jquery实现某宝放大点击切换
    jQuery之文档处理
    jQuery之属性操作
    jQuery css操作
  • 原文地址:https://www.cnblogs.com/leleyao/p/10917183.html
Copyright © 2020-2023  润新知