An online book focusing on Go syntax/semantics and runtime related things

Go 101 in Leanpub store | Go 101 in Apple Books store | Go 101 in Kindle store | eBooks | update history | wiki


Go 101 is a book focusing on Go syntax/semantics and all kinds of runtime related things. It tries to help gophers gain a deep and thorough understanding of Go. This book also collects many details of Go and in Go programming. The book is expected to be helpful for both beginner and experienced Go programmers.

To get latest changes of Go 101, please follow the official twitter account: @go100and1.

Install, Update, and Read Locally

If you use Go toolchain v1.16+, then you don't need to clone the project respository:

### Install or update.

$ go install -tags=embed go101.org/go101@latest

### Read. (GOBIN path, defaulted as GOPATH/bin, should be set in PATH)

$ go101
Server started:
   http://localhost:55555 (non-cached version)
   http://127.0.0.1:55555 (cached version)

If you use Go toolchain v1.15-, or you would make some modifications (for contribution, etc.):

### Install.

$ git clone https://github.com/go101/go101.git

### Update. Enter the Go 101 project directory (which
# contains the current `README.md` file), then run

$ git pull

### Read. Enter the Go 101 project directory, then run

$ go run .
Server started:
   http://localhost:55555 (non-cached version)
   http://127.0.0.1:55555 (cached version)

The start page should be opened in a browser automatically. If it is not opened, please visit http://localhost:55555.

Options:

-port=1234
-theme=light # or dark (default)

Contributing

Welcome to improve Go 101 by:

  • Submitting corrections for all kinds of mistakes, such as typos, grammar errors, wording inaccuracies, description flaws, code bugs and broken links.
  • Suggesting interesting Go related contents.

Current contributors are listed on this page.

Translations are also welcome. Here is a list of the ongoing translation projects:

License

Please read the LICENSE for more details.

Owner
Go101
All about Go programming language. GUI/gfx/games are important for Go's larger popularity, which requires Go programs to run with stabilized high performance.
Go101
Comments
  • Typo[s]

    Typo[s]

    https://github.com/go101/go101/blob/a08fc0c3c37a4a8b326fdfcdf83f8552950d68f4/articles/channel.html#L1097

    solutuon

    I'll collect typos here and submit them in a single commit.

  • Article about closing channels

    Article about closing channels

    Inspired by your article https://go101.org/article/channel-closing.html , I wrote this one https://dev.to/leolara/closing-a-go-channel-written-by-several-goroutines-52j2

    I wanted to let you know

  • Small grammatical adjustments

    Small grammatical adjustments

    Hi @TapirLiu - as I like Your content, I started reading it in my editor, and could not resist to adjust some wordings in order to allow more lucid reading. If You like it, I may be motivated to do more like this.

  • The unsafe article states a runtime.KeepAlive call is needed in the String2ByteSlice example. This is wrong.

    The unsafe article states a runtime.KeepAlive call is needed in the String2ByteSlice example. This is wrong.

    @bcmills's opinion is right in this thread.

    func String2ByteSlice(str string) (bs []byte) {
    	strHdr := (*reflect.StringHeader)(unsafe.Pointer(&str))
    	sliceHdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs))
    	sliceHdr.Data = strHdr.Data
    	sliceHdr.Cap = strHdr.Len
    	sliceHdr.Len = strHdr.Len
    	// This KeepAlive line is essential to make the
    	// String2ByteSlice function be always valid
    	// when it is used in other custom packages.
    	runtime.KeepAlive(&str)
    	return
    }
    

    Bryan C. Mills said The GC tracks pointers through their original allocations — the pointer scan does not care about lexical types, only allocation types.

    @tliron, as that old thread is frozen, so I created this thread to let you get acknowledged.

  • panic-and-recover

    panic-and-recover

    hi, go101 is very helpful for me. 👍

    but when reading panic-and-recover of go101, i found someting wrong in the last example :

    // This program exits without panic 1 being recovered.
    package main
    
    func demo() {
    	defer func() {
    		defer func() {
    			recover() // this one recovers panic 2
    		}()
    
    		defer recover() // no-op
    
    		panic(2)
    	}()
    	panic(1)
    }
    
    func main() {
    	demo()
    }
    

    it says

    In fact, the current Go specification also doesn't explain well why the second recover call, which is expected to recover panic 1, in the following example doesn't take effect.

    and

    What Go specification doesn't mention is that, at any given time, only the newest unrecovered panic in a goroutine is recoverable. In other words, each recover call is viewed as an attempt to recover the newest unrecovered panic in the currrent goroutine. This is why the second recover call in the above example is a no-op.

    i do not think so. the current verson of Go specification says :

    The return value of recover is nil if any of the following conditions holds:

    1. panic's argument was nil;
    2. the goroutine is not panicking;
    3. recover was not called directly by a deferred function.

    the third condition that is the reason why the second recover call, which is expected to recover panic 1, in the following example doesn't take effect.

    then i found something interesting:

    example 1 :

    // This program exits without panic 1 being recovered.
    package main
    
    func demo() {
    	defer func() {
    		defer func() {
    			recover() // this one recovers panic 2
    		}()
    
    		defer recover() // no-op
    
    		panic(2)
    	}()
    	panic(1)
    }
    
    func main() {
    	demo()
    }
    

    example 2 :

    // This program exits with no panic.
    package main
    
    func demo() {
    	defer func() {
    		defer func() {
    			recover() // this one recovers panic 2
    		}()
    
    		defer fmt.Println(recover()) // this one recover panic 1
    
    		panic(2)
    	}()
    	panic(1)
    }
    
    func main() {
    	demo()
    }
    

    example 3 :

    // This program exits without panic 1 being recovered.
    package main
    
    func demo() {
    	defer func() {
    		defer func() {
    			recover() // this one recovers panic 2
    		}()
    
    		defer func() {
    			fmt.Println(recover()) //no-ops
    		}()
    
    		panic(2)
    	}()
    	panic(1)
    }
    
    func main() {
    	demo()
    }
    

    now i know the reason why example 1 exit whit panic , but i don't know why example 2 and example 3 play different.

  • Would it be worth converting to Gitbook?

    Would it be worth converting to Gitbook?

    https://www.gitbook.com/ or something along those lines (such as a static site generator like hugo) so that content can be mostly separated from the HTML

  • Add an explanation

    Add an explanation

    Hello,

    This is to avoid the first notification is missed when it is sent before the moderator goroutine gets ready to receive notification from toStop.

    When reading this path, I misunderstood the meaning, I thought that Go will ignore the message if the channel is not ready. So I made this explanation. I hope it will have a clearer meaning.

    Regards, Huy Dang

  • Update incorrect assumption in memory model article

    Update incorrect assumption in memory model article

    I think you meant the receive happens before the following send. It doesn't make sense otherwise. (Also, it violates rule 1). TBH, the second assumption can be removed as it's not really an assumption since it can be derived from the first one.

    Maybe you can summarize them together to something along those lines: A send on a channel happens before the corresponding receive from that channel completes. If the channel is buffered with a capacity of m, then the n-th receive where n<m has to complete before the n+m send.

  • starting local server

    starting local server

    go run main.go .\main.go:29:8: undefined: openBrowser .\main.go:34:5: undefined: go101

    go run *.go CreateFile *.go: The filename, directory name, or volume label syntax is incorrect.

    go version go1.12.4 windows/amd64

    what might be the problem?

  • Go Generics

    Go Generics

    Ever since the release of the go2go tool which allows for the usage of generics in Golang, you haven't included it in your great and awesome book "Go101". I think I speak for some when I say that you should add a few topics in your book that include Golang generics usage, installation.

  • add dark theme

    add dark theme

    For many people it will be easier to read, especially in a low light environment.

    You can read this property of useragent https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme

  • write a

    write a "Go Modules 101" book

    https://go101.org/article/packages-and-imports.html states:

    Similar to package dependencies, a module might also depend on some other modules.

    However, the term "module" has not yet been defined on this page or, AFAICT, on any page in the ordered sequence leading up to this page. It would be easier for the reader if some definition (or a link to a subsequent definition) was provided first.

  • Go Optimizations 101

    Go Optimizations 101

    3.9 Use value cache pool to avoid some allocations

    You write:

    Personally, I find the design of sync.Pool seldom satisfies the needs in practice. So I often use custom value cache pool implementations in my Go projects.

    Could you give some examples of your custom value cache pool?

  • book: change `println` to `fmt.Println` entirely

    book: change `println` to `fmt.Println` entirely

    Hey! Thanks for writing such an awesome book but I had noticed that you have used print and println for printing to stdout. These function use should be discouraged as its for bootstrapping and it can be removed whenever Go Team wants to.

    I prefer we should switch to fmt.Println() and fmt.Print().

    EDIT: I saw the opening pages which has a note about it but this should be scrapped and can be given in Some Special Topic.

The resource repository of the book "gRPC - Up and Running".
The resource repository of the book

The resource repository of the book "gRPC - Up and Running".

Feb 4, 2022
The Little Go Book is a free introduction to Google's Go programming language
The Little Go Book is a free introduction to Google's Go programming language

The Little Go Book is a free introduction to Google's Go programming language. It's aimed at developers who might not be quite comfortable with the idea of pointers and static typing. It's longer than the other Little books, but hopefully still captures that little feeling.

Jan 2, 2023
Dec 7, 2021
Coding along the book
Coding along the book

Learn Go with Tests Art by Denise Formats Gitbook EPUB or PDF Translations 中文 Português 日本語 한국어 Türkçe Support me I am proud to offer this resource fo

Oct 30, 2021
📖 A little guide book on Ethereum Development with Go (golang)
📖 A little guide book on Ethereum Development with Go (golang)

?? A little guide book on Ethereum Development with Go (golang)

Dec 29, 2022
Book Catalogue, Order RESTful API

Book Catalogue, Order RESTful API try on heroku: https://pacific-island-57943.herokuapp.com Note: '/' endpoint redirect to github repository for docum

Dec 13, 2021
Source code of the 100 Go Mistakes book

100 Go Mistakes and How to Avoid Them Source code of 100 Go Mistakes and How to Avoid Them. Table of Contents Chapter 1 - Introduction Chapter 2 - Cod

Dec 30, 2022
Mastering-go-exercises - Some code examples from Mihalis Tsoukalos book titled Mastering GO

Mastering go exercises This is a training repository. Here are some code example

Feb 16, 2022
Go from the beginning - A book on Go, contains fundamentals but also recipes

Go from the beginning Welcome to Go from the beginning, a free book containing 25+ lessons that will take you from "zero to hero" in the amazing langu

Dec 28, 2022
Go Cheat Sheet - An overview of Go syntax and features.

Go Cheat Sheet - An overview of Go syntax and features.

Dec 31, 2022
An open source, online coding platform that offers code practice and tutoring in 50 different programming languages
An open source, online coding platform that offers code practice and tutoring in 50 different programming languages

Exercism Golang En este repositorio voy a subir los ejercicios de la plataforma

Jan 7, 2022
Tool (in Go!) to compare and diff container and host environments. Dinosaur fun!

Compe compare environments and other things between containers, and host ??️ This is a simple tool to compare environments and other features of conta

Sep 24, 2022
This slide deck and supporting material is part of the Introduction to Go training course by Dave Cheney

This slide deck and supporting material is part of the Introduction to Go training course by Dave Cheney.

Nov 14, 2022
📖 Build a RESTful API on Go: Fiber, PostgreSQL, JWT and Swagger docs in isolated Docker containers.
📖 Build a RESTful API on Go: Fiber, PostgreSQL, JWT and Swagger docs in isolated Docker containers.

?? Tutorial: Build a RESTful API on Go Fiber, PostgreSQL, JWT and Swagger docs in isolated Docker containers. ?? The full article is published on Marc

Dec 27, 2022
Assert your Go code is inlined and bounds-check eliminated

gcassert gcassert is a program for making assertions about compiler decisions in Golang programs, via inline comment directives like //gcassert:inline

Oct 27, 2022
1000+ Hand-Crafted Go Examples, Exercises, and Quizzes

A Huge Number of Go Examples, Exercises and Quizzes Best way of learning is doing. Inside this repository, you will find thousands of Go examples, exe

Jan 1, 2023
Official provider for VMware desktop products: Fusion, Player, and Workstation.

Vagrant VMware Desktop Providers This is the common codebase for the official providers for VMware desktop products: Fusion, Player, and Workstation.

Jan 7, 2023
A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb

Golang series A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb LearnCodeonline.in 01

Jan 1, 2023
Golang Clean Architecture based on Uncle Bob's Clean Architecture and Summer internship in 2021

clean-architecture-api Description This is an example of implemention of Clean Architecture in Golang projects. This project has 4 layer : Infrastruct

Feb 20, 2022