Jasper Ji

开口不在舌头上

0%

Go学习笔记

开始用Go应该是17年底的时候,那会做游戏,后台是用Go写的,虽然我主要负责Unity客户端方面的工作,不过也是经常帮忙给后端的Go小伙解决一些问题,自己也写一些Go的小东西。

后来又做物流系统,重写系统时有考虑用Go,不过因为大部分的外部接口对接都是Java的,为了省事就使用了Java。不过如果是自己的项目的话,还是愿意用Go,毕竟Java还是有点重。

IDE

原来有用过GoLand,为了轻量点,先用VS Code,众所周知的原因安装插件老失败,最后设置Go的代理就可以了。

1
go env -w GOPROXY=https://goproxy.cn,direct

C程序员的礼物

直接试着写个搜索二叉树,其实除了语法上跟C的一些类型定义次序上有点不习惯外,其他方面对于C程序员来说,还是熟悉的用法,比如指针的指针这样的概念,毕竟Go是原来C的那帮人搞的,兼顾C的同时也结合不少Python这样的现代语言的特性。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import "fmt"

type Node struct {
data int
leftNode *Node
rightNode *Node
}

func insert(tree **Node, value int) {
if *tree == nil {
var tempNode Node
tempNode.data = value
*tree = &tempNode
return
}

if (*tree).data > value {
insert(&(*tree).leftNode, value)
} else if (*tree).data < value {
insert(&(*tree).rightNode, value)
}
}

func perOrder(tree *Node) {
if tree != nil {
fmt.Printf("data: %d\n", tree.data)
perOrder(tree.leftNode)
perOrder(tree.rightNode)
}
}

func main() {
var tree *Node

insert(&tree, 9)
insert(&tree, 4)
insert(&tree, 15)
insert(&tree, 6)
insert(&tree, 12)
insert(&tree, 17)
insert(&tree, 2)

perOrder(tree)
}