1. vim-go

https://github.com/fatih/vim-go-tutorial

curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
git clone https://github.com/fatih/vim-go.git ~/.vim/plugged/vim-go
echo "
call plug#begin()
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
call plug#end()
set autowrite
" >> ~/.vimrc  代码质量:go vet, golint, goimports

2. 学习资料

快速入门:

https://github.com/a8m/go-lang-cheat-sheet

了解go的基础数据类型

官方文档:

spec: https://golang.org/ref/spec

go-tour: https://tour.golang.org/list

blog: https://blog.golang.org/index

深入解析Go  这本书,分析了很多特例。 值得一看。

https://tiancaiamao.gitbooks.io/go-internals/content/zh/03.6.html

Go语言圣经(中文版)

The author Brian W. Kernighan is also write the 大名鼎鼎的  <The C Programming Lanuaguage>

go入门指南

学习go语言

在线练习  https://play.golang.org/p/e81LuPO_JR

丰富的example

go web 开发

在线文档

3. 对比学习

如果熟悉C的话,可以对比学习go

4.  继承

$ cat  base.go

 package base

 type BaseT struct {
a int
b int
} func (b *BaseT) Add() int{
return b.a+b.b
} func (b *BaseT) Sub() int {
return b.a-b.b
} type Bf interface {
Add() int
} func NewBasetT(a, b int) *BaseT{
return &BaseT{a, b}
}

$ cat test.go

 package main

 import (
"fmt"
"base"
) type BaseT struct{
base.BaseT
a int
b int
} func (b *BaseT) Add() int{
return b.a+b.b
} func main() {
nb := base.NewBasetT(, )
b := &BaseT{*nb, , }
fmt.Println(b.Add())
}

5.  内存指针转换为 slice

var ptr unsafe.Pointer
s := ((*[1<<10]byte)(ptr))[:200]

这里数组大小其实是假的。s是一个200个元素的slice。

这种方式其实是做了内存copy

或者这种方式:

var ptr unsafe.Pointer
var s1 = struct {
addr uintptr
len int
cap int
}{ptr, length, length}
s := *(*[]byte)(unsafe.Pointer(&s1))

 这种方式就是引用原内存的东西。

6. go 缺失了python的动态特性。 不过可以用reflect进行一些扩展。

http://studygolang.com/articles/4892

此外可以使用接口进行类似弱类型参数传递。

传递时需要注意的问题。

通过断言来动态获取接口类型,还是有些傻

接口实现原理, 简易介绍。还是看官方文档。

map转structexample

json转map,可以直接看官方文档。

使用reflect来设置struc field

7. 传递接口实现多态。

接口的操作

8. 优化

map 并发优化 map的操作跟python差不多

9. disclouser in filepath.Walk

https://xojoc.pw/justcode/golang-file-tree-traversal.html

10. go 第三方库

https://golanglibs.com/top?q=process+list

11. golang re

https://golang.org/pkg/regexp/syntax/

12.    排序例子

https://gobyexample.com/sorting-by-functions

13. 循环变量快照

在5.6.1中有讲解

在循环的闭包 引用循环变量存在这个问题。

14. 排空channel

goroutine泄露(§8.4.4)

15.  内部变量不能够在函数外部被访问到

变量(§2.3.4)在没有被转义的情况下是无法在函数外部访问的

16. plugin

since go_lang 1.8, we can use rpc for plugin.

rpc plugin: https://github.com/dkiser/go-plugin-example

more explain for 1.8 plugin:

https://jeremywho.com/go-1.8---plugins/

picture show the 1.8 plugin

https://github.com/grsmv/go-plugin-example

https://github.com/vladimirvivien/go-plugin-example

more example for plugin.

https://github.com/hashicorp/go-plugin

17. testcase

https://semaphoreci.com/community/tutorials/how-to-test-in-go

https://blog.golang.org/examples

https://golang.org/pkg/testing/

18. goroutine

golang的goroutine是如何实现的

运行时启动过程

19. nested struct

https://stackoverflow.com/questions/24809235/initialize-a-nested-struct-in-golang

20. 第三方库

https://golanglibs.com/

https://github.com/avelino/awesome-go

21. string 求最大值

sort.Sort(sort.Reverse(sort.StringSlice(s)))

22. errror handling

https://blog.golang.org/error-handling-and-go

23.  golang net/http self-sign certification.

One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.

https://golang.org/pkg/net/http/#ListenAndServeTLS

24. personal experience

http://www.jianshu.com/u/1381dc29fed9  _张晓龙_  的blog不错。详细介绍了怎么写testcase。

26. net/http unix socket example

https://gist.github.com/hakobe/6f70d69b8c5243117787fd488ae7fbf2

27. golang command

http://wiki.jikexueyuan.com/project/go-command-tutorial/0.7.html

office link

28. golang.org blog

https://blog.golang.org/defer-panic-and-recover

29. grpc

chinese doc: http://doc.oschina.net/grpc?t=60133

30. protobuf

https://developers.google.com/protocol-buffers/docs/overview

install: https://github.com/google/protobuf/blob/master/src/README.md

readme: https://github.com/google/protobuf/blob/master/README.md

31. go offical RPC example

https://play.golang.org/p/4BZQbM9lNN

 package main

 import (
"io"
"log"
"net/rpc"
) type pipePair struct {
reader *io.PipeReader
writer *io.PipeWriter
} func (this *pipePair) Read(p []byte) (int, error) {
return this.reader.Read(p)
} func (this *pipePair) Write(p []byte) (int, error) {
return this.writer.Write(p)
} func (this *pipePair) Close() error {
this.writer.Close()
return this.reader.Close()
} type Serv struct {
token string
} func (this *Serv) SetToken(token string, dummy *int) error {
this.token = token
return nil
} func (this *Serv) GetToken(dummy int, token *string) error {
*token = this.token
return nil
} type Registrar struct {
} func (this *Registrar) Register(name string, dummy *int) error {
rpc.RegisterName(name, new(Serv))
return nil
} func server(pipes pipePair) {
rpc.Register(new(Registrar))
rpc.ServeConn(&pipes)
} func main() {
var token string
var in, out pipePair
in.reader, out.writer = io.Pipe()
out.reader, in.writer = io.Pipe()
go server(out)
client := rpc.NewClient(&in)
// Register some objects
client.Call("Registrar.Register", "First", nil)
client.Call("Registrar.Register", "Second", nil)
// Assign token values individually
client.Call("First.SetToken", "abc", nil)
client.Call("Second.SetToken", "def", nil)
// Now try to read them
client.Call("First.GetToken", , &token)
log.Printf("first token is %v", token)
client.Call("Second.GetToken", , &token)
log.Printf("second token is %v", token)
}

32.  golang process drop privilege

https://play.golang.org/p/dXBizm4xl3

 package main

 import (
"fmt"
"net"
"net/http"
"os"
"os/exec"
"syscall"
) func main() {
if os.Getuid() == {
fmt.Println("Dropping privileges...")
if err := drop(); err != nil {
fmt.Println("Failed to drop privileges:", err)
os.Exit()
}
} l, err := net.FileListener(os.NewFile(, "[socket]"))
if err != nil {
// Yell into the void.
fmt.Println("Failed to listen on FD 3:", err)
os.Exit()
} http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "I am process %d running as %d/%d", os.Getpid(), os.Getuid(), os.Getgid())
}))
} func drop() error {
l, err := net.Listen("tcp", ":80")
if err != nil {
return err
} f, err := l.(*net.TCPListener).File()
if err != nil {
return err
} cmd := exec.Command(os.Args[])
cmd.ExtraFiles = []*os.File{f}
cmd.SysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: ,
Gid: ,
},
Setsid: true,
} if err := cmd.Start(); err != nil {
return err
} fmt.Printf("Spawned process %d, exiting\n", cmd.Process.Pid)
cmd.Process.Release()
os.Exit()
return nil /* unreachable */
}

文若的python实现: https://www.ovirt.org/develop/release-management/features/infra/supervdsm-service/

in golang father to notify child: https://github.com/opencontainers/runc/blob/master/libcontainer/system/linux.go

https://github.com/mindreframer/golang-devops-stuff/blob/master/src/github.com/dotcloud/docker/vendor/src/github.com/docker/libcontainer/system/linux.go

33. // Create a timer that will kill the process

cmd.Process.Signal  http://www.darrencoxall.com/golang/executing-commands-in-go/

34. difference os.Pipe and io.Pipe 

io.Pipe: https://golang.org/pkg/io/#Pipe Pipe creates a synchronous in-memory pipe

os.Pipe: https://golang.org/pkg/os/#Pipe  Pipe returns a connected pair of Files; 

35. os signal Notify

Notify: https://golang.org/pkg/os/signal/#example_Notify

36.  tls revoke

https://github.com/cloudflare/cfssl/tree/master/revoke

37. print struct name

https://stackoverflow.com/questions/24512112/how-to-print-struct-variables-in-console

38. all channel exit.

https://nathanleclaire.com/blog/2014/02/15/how-to-wait-for-all-goroutines-to-finish-executing-before-continuing/

39. Singleton Pattern in Go

http://marcio.io/2015/07/singleton-pattern-in-go/

go learning的更多相关文章

  1. 【Machine Learning】KNN算法虹膜图片识别

    K-近邻算法虹膜图片识别实战 作者:白宁超 2017年1月3日18:26:33 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...

  2. 【Machine Learning】Python开发工具:Anaconda+Sublime

    Python开发工具:Anaconda+Sublime 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现 ...

  3. 【Machine Learning】机器学习及其基础概念简介

    机器学习及其基础概念简介 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...

  4. 【Machine Learning】决策树案例:基于python的商品购买能力预测系统

    决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本 ...

  5. Deep learning:五十一(CNN的反向求导及练习)

    前言: CNN作为DL中最成功的模型之一,有必要对其更进一步研究它.虽然在前面的博文Stacked CNN简单介绍中有大概介绍过CNN的使用,不过那是有个前提的:CNN中的参数必须已提前学习好.而本文 ...

  6. Programming Learning - Based on Project

    Today when taking a bath I got a good idea that it is an efficient and interesting way to learn a ne ...

  7. 做中学(Learning by Doing)之背单词-扇贝网推荐

    做中学(Learning by Doing)之背单词-扇贝网推荐 看完杨贵福老师(博客,知乎专栏,豆瓣)的「继续背单词,8个月过去了」,我就有写这篇文章的冲动了,杨老师说: 有时候我会感觉非常后悔,如 ...

  8. 【原】Learning Spark (Python版) 学习笔记(一)----RDD 基本概念与命令

    <Learning Spark>这本书算是Spark入门的必读书了,中文版是<Spark快速大数据分析>,不过豆瓣书评很有意思的是,英文原版评分7.4,评论都说入门而已深入不足 ...

  9. 【原】Learning Spark (Python版) 学习笔记(四)----Spark Sreaming与MLlib机器学习

    本来这篇是准备5.15更的,但是上周一直在忙签证和工作的事,没时间就推迟了,现在终于有时间来写写Learning Spark最后一部分内容了. 第10-11 章主要讲的是Spark Streaming ...

  10. 【机器学习Machine Learning】资料大全

    昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...

随机推荐

  1. codeforces 888A/B/C/D/E - [数学题の小合集]

    这次CF不是很难,我这种弱鸡都能在半个小时内连A四道……不过E题没想到还有这种折半+状压枚举+二分的骚操作,后面就挂G了…… A.Local Extrema 题目链接:https://cn.vjudg ...

  2. mysqli_report

    MYSQLI_REPORT_OFF Turns reporting off MYSQLI_REPORT_ERROR Report errors from mysqli function calls M ...

  3. [python-opencv] 模糊操作

    @不要在奋斗的年纪 选择安逸 均值模糊 中值模糊 自定义模糊 意义与应用场景 模糊的基本原理: 1.基于离散卷积 2.定义好每个卷积核 3.不同卷积核得到不同的卷积效果 4.模糊是卷积的一种表象 #均 ...

  4. linux桌面与命令模式切换

    在图形下面按Ctrl+alt+F1(F2\F3\F4)进入命令模式 在命令模式下,按Ctrl+alt+F7回到图形,或登录用户输入startx进入图形!

  5. 如何使用Soft-NMS实现目标检测并提升准确率

    非极大值抑制(Non-Maximum suppression,NMS)是物体检测流程中重要的组成部分.它首先基于物体检测分数产生检测框,分数高的检测框M被选中,其他与被选中检测框又明显重叠的检测框被抑 ...

  6. sql server内置存储过程、查看系统信息

    1.检索关键字:sql server内置存储过程,sql server查看系统信息 2.查看磁盘空间:EXEC master.dbo.xp_fixeddrives , --查看各个数据库所在磁盘情况S ...

  7. linux平台mysql密码设置

    登录mysql默认没有指定账号 查看默认账号是谁 select user(); mysql> select user();+----------------+| user() |+------- ...

  8. linux命令之复制

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zkn_CS_DN_2013/article/details/24464547 语法:cp [选项] ...

  9. 解压赋值及python的一些基础运算

    #解压赋值lis=[11,22,33,44,55] money1,money2,money3,money4,money5=lis print(money1,money2,money3,money4,m ...

  10. mysql 实时统计脚本 QPS,TPS和线程连接数等

    #!/bin/bash mysqladmin -uroot -p'root' extended-status -i1|awk 'BEGIN{local_switch=0;print "QPS ...