天天看點

golang import包前的字母與符号

import (
	"fmt"
	"strings"

	cb "github.com/hyperledger/fabric/protos/common"

	"github.com/golang/protobuf/proto"
)
           

像例子裡面的cb就是後面要引用的包的别名(防止沖突)

格式:别名+空格+引用的包名(包名加雙引号)

import (
	"fmt"
	"strings"

	_ "github.com/hyperledger/fabric/protos/common"

	"github.com/golang/protobuf/proto"
)
           

前面加下劃線,隻調用包裡面的init函數。無法調用包中别的函數。

import (
	. "fmt"
	"strings"

	cb "github.com/hyperledger/fabric/protos/common"

	"github.com/golang/protobuf/proto"
)
           

fmt前面加點,調用函數時可以省略包的名字。即:fmt.println()可以寫成println()