[Golong]学习笔记(一) 基础知识

Go编程基础

Go的内置关键字(25个) 不多

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

Go的注释方法(和js一样)

单行注释: //
多行注释: /**/

Go程序一般结构 common_structure.go
  • 通过 package 组织代码结构(类似python的模块)
  • 只有 package 名称为 main 的包可以包含 main 函数
  • 一个可执行程序 有且仅有一个 main 包
  • 通过 import 来导入包
  • const 用来定义常量(类似c)
  • 函数体外部使用 var 来进行全局变量的声明和赋值
  • 复杂类型 struct , interface 要用 type 关键字来声明
  • func 来声明函数

简单的demo

/*
title: common_structure.go
author: orangleliu
date: 2014-08-05
des: the simple demo of erlang
*/

// a package only have a main
package main

// use “import” import other packages
import “fmt”

const Lzz = “Orangleliu”

var name = “erlong”

type age int

type golang struct{

}

func main(){
    fmt.Println(“I love Erlog!”)
}

1 导入多个包的方法

import (
    “fmt”
    “os”
    “time”
)

2 使用别名

import (
    std “fmt”
)
命名约定

使用大小写来区分 常量,变量,类型,接口,结构 或函数是共有还是私有

例如:
1. 函数名称 首字母小写: private
2. 函数名称 首字母大写: public

学习资料地址

本文出自  orangleliu笔记本  博客,请务必保留此出处 http://blog.csdn.net/orangleliu/article/details/38393085

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值