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)

转载于:https://www.cnblogs.com/marks-gui/p/7707873.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值