a8m / golang-cheat-sheet Goto Github PK
View Code? Open in Web Editor NEWAn overview of Go syntax and features.
An overview of Go syntax and features.
https://github.com/basti1302/go-lang-cheat-sheet/blame/master/README.markdown#L345
and
https://github.com/basti1302/go-lang-cheat-sheet/blame/master/README.markdown#L361-L363
Seem to imply that functions can only be assigned to structs, however all user defined types can have methods. There is nothing unique about structs with regard to method/function declaration.
see example:
https://play.golang.org/p/DPFZz0mCbi
There is an example regarding pointers, but there is no comment that describes when to use pointers.
Please add break
& continue
that controls the for loop. Thx.
Hi, I'm new to go, but I can't compile source code from 'Functions As Values And Closures' chapter.
I had to change:
outer_var = 444
to outer_var := 444
,
func outer() func() int, int{
to func outer() (func() int, int){
and in both another_scope
and outer
functions I'm facing undefined foo
error. Am I doing smth wrong?
My go version
output is go version go1.4.2 linux/amd64
Hi,
I believe the example about Closures is not quite correct. The comment says that the returned outer_var is still 2 because inner() has only modified a copy of it. However, when outer() returns, inner() has not been called yet, and this is why outer_var is 2 at that time. When inner is executed before outer() returns, then outer_var is returned as 101. See this Playground test code: https://play.golang.org/p/e_wktwN6me
Thanks,
Christoph
Could you add information about generic of Golang 1.18 for cheat sheet. Tks!
Is it ok if I begin to translate the document to Spanish, or is someone else already working on it?
You don't need to include fmt package for printing "hello world"
package main
func main(){
println("Hello world")
}
Would you be looking to add common Go modules to this guide, or is it no longer being maintained? I'd be happy to contribute.
Hello, we have indexd this cheat sheet to awesome-cheatsheet
Thank You !!! ๐ ๐ ๐
This repo is really useful when I want to check the syntax of Go.
I have translated a chinese version of this repo.
golang-cheat-sheet-cn
If you'd like to to add other languages's translation into your repo, I can open a PR.
Thanks.
outer_var in the outer func wasn't changed because the anonymous inner function hadn't been called yet.
// Closures: don't mutate outer vars, instead redefine them!
func outer() (func() int, int) {
outer_var := 2 // NOTE outer_var is outside inner's scope
inner := func() int {
outer_var += 99 // attempt to mutate outer_var
return outer_var // => 101 (but outer_var is a newly redefined
// variable visible only inside inner)
}
return inner, outer_var // => 101, 2 (still!)
}
I saw you made updates on the README file, but some people may also read your pdf file.
Hello,
Please explain how one can replace map[string]interface{} functionality with an anonymous struct
Personally, I think adding a "comment" section will be better for this cheat sheet.
I wish there was a section on strings. How to index them, some formatting tricks, etc.
elem, ok = m["key"] // test if key "key" is present and retrieve it, if so
should actually be
elem, ok := m["key"] // test if key "key" is present and retrieve it, if so
You are missing a :
An example can be found here
I have printed the pages, but there are no page numbers. In my opinion, the pdf and odt should be part of a release rather than being stored in git.
Goroutines are lightweight threads (managed by Go, not OS threads).
Actually, the way goroutines are implemented are subject to the specific implementation. With gccgo, it does (or did?) use an OS thread for each goroutine.
from http://www.airs.com/blog/archives/448 :
"
On the functionality side, the gccgo library uses a single operating system thread for each goroutine. That is not what 6g/8g do: they multiplex goroutines onto operating system threads. Multiplexing is more efficient for a language like Go, and I need to change gccgo to work that way.
"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.