美文网首页
go basic slides

go basic slides

作者: 戈壁堂 | 来源:发表于2021-07-13 19:30 被阅读0次

我的学习经历

  • 2017年Go十周年时想学(go1.9),使用hugo搭建静态站点
  • 零星学习
  • 2020年esproxy log filter
  • 2021 medusa实战

语言历史

  • Go is a procedural, open-source programming language developed by Google that made its first stable release in 2011
  • Rob Pike, Ken Thompson, and Robert Griesemer started designing Go in 2007
  • it became open sourced in 2009

Go 1 2012.03.28
Go 1.1 2013.05.13
Go 1.2 2013.12.01
Go 1.3 2014.06.18
Go 1.4 2014.12.10
Go 1.5 2015.08.19
Go 1.6 2016.02.17
Go 1.7 2016.08.15
Go 1.8 2017.02.16
Go 1.9 2017.08.24
Go 1.10 2018.02.16
Go 1.11 2018.08.24
Go 1.12 2019.02.25
Go 1.13 2019.09.03
Go 1.14 2020.02.25
Go 1.15 2020.08.11
Go 1.16 2021.02.16


git log --reverse --pretty=oneline

first commit 7chars

commit 7d7c6a97f815e9279d08cfaea7d5efb5e90695a8
Author: Brian Kernighan <bwk>
Date:   Tue Jul 18 19:05:45 1972 -0500

    hello, world

    R=ken
    DELTA=7  (7 added, 0 deleted, 0 changed)

语言特点

我的视角

  • 编译为可执行文件,直接执行(无需依赖)
  • 多线程go func
  • go fmt:代码一致性
  • 简洁(不允许引入不使用的类库)
  • 自动判断循环引用(medusa项目)

FTP文件服务器

package main

import (
  "log"
  "net/http"
  //"os"
)

func main() {
  // fs := http.FileServer(HTMLDir{http.Dir("./static")})
  fs := http.FileServer(http.Dir("./go")) //absolute path if necessary
  http.Handle("/", fs)

  log.Println("Listening on :3000...")
  err := http.ListenAndServe(":3000", nil)
  if err != nil {
    log.Fatal(err)
  }
}

如何学习

任意一本你可以找到的tutorial


基础知识

  • 1.5之后实现自举(自己编译出自己):语言的自举Go的自举
  • 安装、添加到环境变量: go version
  • go env几个关键的环境变量:
    • GOPATH的历史遗留:统一代码管理,缺失版本概念;go1.11启用GOMOD;go install安装到$GOPATH/bin
    • GOROOT安装目录
    • GOPROXY代理问题
  • go run main.go

Java对比理解

Go vs. Java: main differences

  • Built-in types: string, map, json 内置
  • Pointers and references 包含指针
  • Error handling 必须立即处理err(已经成为了meme)
  • Object-oriented programming 无继承;使用组合;大小写决定访问关键字
  • Functional programming 函数第一公民
  • Concurrency 并发 go
  • go不支持强制转换,例如int to string;不支持方法重载(同名函数);暂无泛型
  • 原生支持复数? 极少使用……吧

Variables

Control flow

Files

Data

Functions

Concurrency

Time

JSON

Additional


Go编程模式系列


实战

saber演示


相关文章

网友评论

      本文标题:go basic slides

      本文链接:https://www.haomeiwen.com/subject/ktrspltx.html