{"id":21078371,"url":"https://github.com/lki/go","last_synced_at":"2026-05-19T17:42:00.422Z","repository":{"id":83188470,"uuid":"98007850","full_name":"LKI/go","owner":"LKI","description":"我的 GoLang 试验田","archived":false,"fork":false,"pushed_at":"2019-11-16T08:33:18.000Z","size":112,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T23:17:10.923Z","etag":null,"topics":["go","golang","gotutorials"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LKI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-22T04:56:10.000Z","updated_at":"2019-11-16T08:32:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5aa06c3-81b4-4840-a645-8ee23831c656","html_url":"https://github.com/LKI/go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKI%2Fgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKI%2Fgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKI%2Fgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKI%2Fgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LKI","download_url":"https://codeload.github.com/LKI/go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243521287,"owners_count":20304187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","gotutorials"],"created_at":"2024-11-19T19:40:13.271Z","updated_at":"2025-12-28T17:29:49.850Z","avatar_url":"https://github.com/LKI.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 我的 Go 旅程\n\n## Kotlin vs Go ?\n\n前阵子 [Kevin][kevin] 跟我们分享了一波 [Kotlin][kotlin]。\n我感觉 [Kotlin][kotlin] 很好玩，\n于是想尝试一下。\n但后来 [张总][tothegump] 又问我，\n你既然想玩一下 [Kotlin][kotlin]，\n那怎么不试一下 [Go][go] 呢？\n我就去查了查 `Kotlin VS Go` 的这个话题，\n发现 [知乎上有人这么说][zhihu-kotlin-go]：\n\n\u003e Kotlin 的大优势和大劣势都是完全兼容 Java。\n\u003e 而 Go 最大优势就是对多线程的优化。\n\n我又去看了看 [Slant上面的对比][slant-kotlin-go]。\n嗯，感觉其实两个语言都很有前途啊！\n然而 :wink: 我选择 ~~Python~~ Go...\n\n![go-name][go-name]\n\n值得一提的是，\n`GoLang` 只是网站名，\n有的时候 Google 搜 Go 不好搜，\n也会用 GoLang 来搜索。\n\n但 **[Go][go] 语言没有别的名字，本身就叫 `Go`**\n\n\n## Start my journey\n\n好了，既然选择了 [Go][go]，\n那我们首先从语言本身开始走起。\n\n* 安装：因为[我是 Windows 党][windows-setup]，\n所以用 [Choco 安装][choco] 或者[去官网下载 msi 装一下][go-dl]都行。\n\n* IDE：因为我是 IDE 党...\n而且 [JetBrains 也出了 Go 的 IDE Gogland][https://www.jetbrains.com/go/]\n那自然就是选择它了。\n\n* 语法学习：认识新语言的语法，\n我首先就会去 [Learn X In Y Minutes][xy-go] 上看看……\n然后再[稍微看了看官方的 Go Tour][go-tour]。\n\n![wtf-tabs][tabs]\n\n\u003e 注: 这里十分蛋疼地发现 Go 是推崇 Tabs 的...\n\u003e 我思索了一下，决定~~还是用 Space~~入乡随俗，使用 tabs。\n\n百看不如一练，\n直接上手用吧。\n\n\n## Hi, Lirian\n\n首先我们新建一个Project，\n等等，\n问题来了，\n**Go 语言的 Workspace 一般是什么样子？**\n\n[文档里面是这么说的][go-workspace]：\n\n\u003e 一般来说，项目目录下面会有三个文件夹：src, pkg, bin。\n\u003e\n\u003e 其中 src 是放源文件的，pkg 是放各种~~内裤~~类库、包的，bin是放可执行文件的。\n\u003e\n\u003e 而项目一般是放在 home 目录下的。\n\u003e 假如你要放在其它目录，\n\u003e 你就要去设定一下 GOPATH 这个环境变量了。\n\n噢，这里引入了一个新的词，\n叫 `GOPATH`。\n再看看文档，\n发现这个概念跟 [Java 的 classpath][classpath]、\n[Python 的 sys.path][sys-path] 很类似。\n\n在我们用 `go build` 命令编译项目的时候，\n在 `$GOPATH/src` 下面的源文件们就会被翻出来然后编译。\n\n这里有几条命令可以跑跑看：\n\n```\n\u003e go env\nset GOROOT=C:\\CodeEnv\\Go  # Go语言的安装路径\nset GOPATH=C:\\Code\\github\\LKI\\go  # 本项目的路径\n...\n\n\u003e go env GOPATH  # 只查看 GOPATH 这个环境变量\nC:\\Code\\github\\LKI\\go\n\n\u003e go help gopath  # 简单地看一看关于 GOPATH 的说明\nThe Go path is bla bla...\nbla bla...\nbla bla...\n\n\u003e go help build  # 理论上这个也可以跑\nusage: go build [bla bla] bla bla [packages]\n\n\u003e go build hi  # 跑跑看\n\n\n\u003e hi\nHi, Lirian\n```\n\n在边玩边学中，\n我们第一个程序就跑成功了。\n我们可以试试各种各样的语法，\n比如 `defer`, `error` 等。\n\n接下来我们尝试写一个 [Low DB][lowdb] 那样的 json/in-memory database吧。\n取个名，就叫…\n\n\n## Fate DB\n\n首先我们要写一个 In Memory DB，\n期待它的用法类似如下：\n\n``` go\nvar db = fatedb.DB{}\n\ndb.Set(\"key\", \"value\")\ndb.Get(\"key\")  // \"value\"\ndb.Get(\"no-such-key\", \"default\") // \"default\"\ndb.Del(\"key\")\ndb.Get(\"key\")  // nil\n```\n\n先不考虑 Thread Safe 的问题，\n首先我们要解决的是 Go 里面 Dictionary/Map 要怎么写？\n那自然是找一下官方的文档: [Go maps in action][go-maps]\n\n学到了 map 的用法以后，\n为了解决 default value 的问题，\n类比于 Python，\n我们要看看有没有 Named Parameter 或者 Optional Parameter 的概念。\n然而，很可惜，\nGo 并没有（或者说我目前没找到）对应的做法。\n而且 [Go 还不支持 method overloading][go-overload]...\n哭，于是我们只能这么去实现了：\n\n```\ndb.Get(\"key\")  // \"value\"\ndb.GetWithDefault(\"no-such-key\", \"default\") // \"default\"\n```\n\n*开始怀念起了 Python ...*\n\n然后是 `map[string]string` 的问题，\nGo 里面有没有类似于 `map[object]object` 这样的表达呢？\n查了一下，\n可以用 `map[interface{}]interface{}` 来达到效果。\n很神奇嘛，\n那这个 interface 关键字又是干什么的呢？\n\nTODO: 施工中...\n\n\n[kevin]: http://www.heyongjian.com/\n[kotlin]: http://kotlinlang.org/\n[tothegump]: https://github.com/tothegump\n[go]: https://golang.org/\n[zhihu-kotlin-go]: https://www.zhihu.com/question/60064789\n[slant-kotlin-go]: https://www.slant.co/versus/126/1543/~golang_vs_kotlin\n[go-name]: /doc/images/go.jpg\n[windows-setup]: http://www.liriansu.com/windows-dev-env\n[choco]: https://chocolatey.org/\n[go-dl]: https://golang.org/dl/\n[gogland]: https://www.jetbrains.com/go/\n[xy-go]: https://learnxinyminutes.com/docs/go/\n[go-tour]: https://tour.golang.org/welcome/\n[tabs]: /doc/images/tabs_wtf.jpg\n[go-workspace]: https://golang.org/doc/code.html#Workspaces\n[classpath]: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html\n[sys-path]: https://docs.python.org/3/library/sys.html\n[lowdb]: https://github.com/typicode/lowdb\n[go-maps]: https://blog.golang.org/go-maps-in-action\n[go-overload]: https://golang.org/doc/faq#overloading\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flki%2Fgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flki%2Fgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flki%2Fgo/lists"}