{"id":18260030,"url":"https://github.com/roppa/learning-go","last_synced_at":"2025-04-08T23:44:40.362Z","repository":{"id":146092887,"uuid":"140450161","full_name":"roppa/learning-go","owner":"roppa","description":"Learning Go","archived":false,"fork":false,"pushed_at":"2019-10-25T11:51:43.000Z","size":1025,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T18:36:27.081Z","etag":null,"topics":[],"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/roppa.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":"2018-07-10T15:09:15.000Z","updated_at":"2019-10-25T11:51:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"2859c849-dcbf-45cd-a031-651d1b0837cd","html_url":"https://github.com/roppa/learning-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/roppa%2Flearning-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roppa%2Flearning-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roppa%2Flearning-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roppa%2Flearning-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roppa","download_url":"https://codeload.github.com/roppa/learning-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247947825,"owners_count":21023058,"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":[],"created_at":"2024-11-05T10:41:35.263Z","updated_at":"2025-04-08T23:44:40.348Z","avatar_url":"https://github.com/roppa.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Learning GoLang\n\nYou usually have to start with a [hello world](/01-hello/hello.go). But the best way to learn programming is with [TDD](/00-testing/first_test.go).\n\n## Setup\n\nFirst [install go](https://golang.org/doc/install) and then setup your [Go path](https://golang.org/doc/code.html#GOPATH).\n\nLets test the setup by creating a folder called `$GOPATH/src/learning`. Paste the below into a file called `hello.go`:\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"hello, world\\n\")\n}\n```\n\nTo execute use `go run hello.go`.\n\nGo is also compiled into an executable. To do so run:\n\n```bash\ncd learning\ngo build hello.go // this creates the hello executable\n./hello\n```\n\nThe `package main` tells GoLang that this is an executable file and not a library. An executable file must also have a `func main()`. If it is named something other than `main` that would be a library.\n\nThe `fmt` is a package that handles input/output, in this case printing to stdout.\n\n## Offline Go\n\nIf you have go installed, run:\n\n```bash\ngodoc -http=:6060\n```\n\nThen open to http://127.0.0.1:6060/ in your browser.\n\n## Packages/Libraries\n\nA package, or library, groups together code which is utilised by another program.\n\n## Types\n\nStrongly typed language.\n\n`bool`, `string`, `int`, `float64`\n\nGo word size is the memory address size. Based on your machine, 32bit, 64bit etc. An integer is based on your word size, so on a 64bit machine it will be 64 bits long, 32bits on a 32 bit machine.\n\nGo zero values:\n\n- nil\n- 0\n- false\n- “”\n\n## Testing and TDD\n\nTesting, like a lot of languages, is included in GoLang.\n\n[00-testing](/00-testing)\n\nTo run a test:\n\n```bash\ngo test --cover\n```\n\n## Variables\n\n[02-variables](02-variables/variabls.go)\n\nVariable names. I can't beleive I have to mention this. Reading a lot of peoples interpretations of [pikestyle](http://doc.cat-v.org/bell_labs/pikestyle) reinforces my opinion of the human race. Oh yeah, you commute on the London tube every day for years and lets hear your opnion. Anyway, I digress. Pike clearly mentions 'clarity of expression'. The variable should describe exactly what it is. Our conventions for i in for loops is totally fine. Anyone who has programmed will know this one. That doesn't mean to say that all variables should be single letters does it? Code is written for humans. Beautiful code should read like well written prose.\n\nYou can do multiple assignment:\n\n```golang\na, b, c := 10, 100, 1000\nfmt.Println(a, b, c)\n```\n\n## Numbers\n\n[03-numbers](/03-numbers)\n\n## Strings\n\n[04-strings](/04-strings)\n\n## Arrays and Slices\n\n[05-array-slices](/05-array-slices)\n\nSo Go does a lot of things for you. For this example we want to demonstrate arrays and slices. So lets have seperate files for this. Oh, so how do you import these files then? Aahhh, you don't have to do anything. Well, apart from change the run command to:\n\n```bash\ngo run main.go array.go slice.go\ngo build main.go array.go slice.go\n```\n\nThe run command needs to group all these files into an executable.\n\nRarely use arrays directly as they are pretty inflexible. Use slices instead. Of course arrays have their uses.\n\nYou will see the reserved word 'make'. This function takes care of allocating memory for the slice in this example.\n\n`make` does a few things, one is creating a channel, takes care of allocating memory for a slice.\n\n## Conditionals\n\n[06-conditionals-iterators/statements.go](/06-conditionals-iterators)\n\n## Functions\n\n[07-functions/functions.go](/07-functions)\n\nfunc [name]([[paramName/s,] type]) [[[name]return type], {(return types,)] {\n...\n}\n\nFunctions beginning with a capital letter are exported. Fat.Println etc, notice the capital P.\n\n## Structs\n\nA struct is a custom type, which is an aggregate of other types.\n\nIn structs, always have attributes listed from shortest length of the data type. int8, int16 etc as go pads out the structure with memory allocation based on the first longest?\n\n[struct/struct.go](struct/struct.go)\n\n## Pointers\n\nGo is pass by value. To pass by reference you need to use pointers in the calling function parameter (\\*) and use 'address of' in the callee function parameters and body (\u0026) \u0026[variable name] i.e. \u0026count.\n\n- `\u0026` - 'the address of'\n- `*` - 'the value of'\n\n```go\n  hello := \"Hello\"\n  var helloPointer *string = \u0026hello\n  fmt.Println(\u0026hello) // 0xc0000101e0\n  fmt.Println(*\u0026hello) // Hello\n  fmt.Println(*helloPointer) // Hello\n```\n\n[pointers/pointer.go](./pointers)\n\n## Go routines\n\nAll Go you write gets run on a goroutine - an OS thread.\n\n## Channels\n\nChannels are pipes that connect concurrent goroutines.\n\n## HTTP Server\n\nhttp-server/server.go\n\n## Pipes\n\n- [Golang pipes](https://golang.org/src/io/pipe.go)\n- [Zup Zup pipes](https://zupzup.org/io-pipe-go/)\n\n## Time and Tickers\n\nhttp-json/http-json.go\n\n## Command Line\n\n- [Go by example - flags](https://gobyexample.com/command-line-flags)\n\n## Race Conditions\n\n- [GoLang data race and how to fix it](https://www.sohamkamani.com/blog/2018/02/18/golang-data-race-and-how-to-fix-it/)\n\n## References\n\n- [Go Start](https://github.com/alco/gostart)\n- [Glang writing unit tests](https://blog.alexellis.io/golang-writing-unit-tests/)\n- [How to write Go code](https://golang.org/doc/code.html).\n- [Go by example](https://gobyexample.com/)\n- [Learn go with tests](https://github.com/quii/learn-go-with-tests)\n- [GoLang tour](https://tour.golang.org/list)\n- [Awesome GoLang information from rakyll.org!](https://rakyll.org/)\n- [TDD](https://leanpub.com/golang-tdd/read)\n- [Web apps with GoLang](https://astaxie.gitbooks.io/build-web-application-with-golang/en/)\n- [GoLang talks](https://talks.golang.org/2012/10things.slide#8)\n- [Thinking in Go](https://hackmongo.com/post/thinking-in-go/)\n- [Ultimate Go programming](https://www.safaribooksonline.com/videos/ultimate-go-programming/9780134757476/9780134757476-ugpg_02_02_03_02)\n- [Programming guide](https://programming.guide/go/three-dots-ellipsis.html)\n- [research.swtch.com](https://research.swtch.com/)\n- [golangbot.com](https://golangbot.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froppa%2Flearning-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froppa%2Flearning-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froppa%2Flearning-go/lists"}