1、Go基础知识

Go程序是通过package来组织的(与Python类似)

只有package名称为main的包可以包含mian()函数

一个可执行程序有且仅有一个main包

// 当前程序包名
package main

import "fmt"

// 常量的定义
const PI  = 3.14

// 全局变量的声明和赋值
var name  = "goer"

// 一般类型的声明
type newType int

// 结构的声明
type newStr struct {

}

// 接口的声明
type goInter interface {

}

// 由 main 函数作为程序入口点启动
func main()  {
	fmt.Println("hello world")
}

###Go导入package的格式

import "fmt"
import "os"
import "time"

也可以简化成如下

import (
	"fmt"
	"os"
	"time"
)

**注意点:**如果导入的包未调用其中的函数或者类型,将会报“编译错误 ”

###可见性规则
Go语言中,使用大小写来决定该 常量、变量、类型、接口、结构或者函数 是否可以被外部调用。根据约定,函数名首字母小写即为private函数名首字母大写即为public

猜你喜欢

转载自blog.csdn.net/github_26672553/article/details/84678112