加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 18:51:02 所属栏目:大数据 来源:网络整理
导读: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编程基础

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://www.52php.cn/article/p-zanqcaya-re.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读