Golang学习笔记1——基础知识

1.Go内置关键字和注释方法

break      default       func     interface   select
case       defer         go       map         struct
chan       else          goto     package     switch
const      fallthrough   if       range       type
continue   for           import   return      var

2.Go程序的一般结构

//当前程序的包名
package main

//导入其它的包
import "fmt"

//全部变量的声明与赋值
var name = "gopher"

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

//结构的声明
type gopher struct{}

//接口的声明
type golang interface{}

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

3.包的导入

  • package别名与省略调用
别名:
import std "fmt"

省略调用(这样可以不用写包名,直接调用):
import . "fmt" 

初始化,但不调用:
import _ "github.com/go-sql-driver/mysql"
  • 可见性规则
只有首字母为大写的才能被其它包调用(类似面向对象里面的属性public 和private)
posted @ 2017-10-22 09:42  MarksGui  阅读(122)  评论(0编辑  收藏  举报