0
点赞
收藏
分享

微信扫一扫

go包名

kolibreath 2022-02-15 阅读 105


规则

包名是不能包含有小数点(.)的

类似java的包名,在go中是不合法的

package com.oracle;  // go是不合法的

目录结构

go包名_目录结构

例子

Employee.go

// src/mycom/eneity
//. 用 _代替
package mycom_entity

import "fmt"

func init() {
fmt.Printf("Employee init is called.")
}


func Empoyee()(name string,age int8,cname string) {
return name,age,cname;
}

main.go

package main

import "fmt"
import "mycom/entity"

func main() {
name,age,_ := mycom_entity.Empoyee();
fmt.Printf("name=%s,age=%d \n",name,age)

}

导入规则

包名前下划线_


当导入一个包时,该包下的所有go文件的init函数被执行


包名前点.


你调用这个包的函数时,你可以省略前缀的包名


import . "mycom/entity"

name,age,_ := Empoyee();

// name,age,_ := mycom_entity.Empoyee(); 上面没有.的话,需要包名调



举报

相关推荐

0 条评论