Questions tagged [go]

Go is an open-source programming language, with a syntax loosely derived from C. It's statically typed, with limited dynamic typing capabilities; it also features automatic memory management, built-in concurrency primitives, variable-length arrays – called slices –, and a large standard library.

Go (sometimes "Golang" for search-ability) is a general-purpose programming language. While originally created by Google, Go is an open source project with a large contributor base. It aims to be efficient both for development and execution with a focus on fast compilation and increased maintainability of large projects. Go was originally targeted at systems programming tasks such as building server/web applications, high throughput middleware, and databases, but it has a growing ecosystem of libraries allowing it to be used for a wide variety of tasks such as developing end-user daemons, CLIs, and desktop/mobile applications.

The first class concurrency mechanisms of Go make it easier to write programs that get the most out of multicore and networked machines, while its structural type system enables flexible and modular program construction. Go compiles quickly to memory safe machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that develops like a dynamically typed, interpreted language, but performs like native code.

Go Reference Documentation

Go Tutorials

Go Books (Paid)

Go Books (Free)

Popular Go Projects

Go Mailing Lists

Go chat

Online Go Compilers

Go FAQ

Go Code Editors & IDEs

Go Dependency Management

Go2 Resources

Go2 is an umbrella term used to indicate language changes under discussion that may break Go's compatibility promise. Even if a feature ends up being suited for a Go 1.x release, it is still often tagged and referred to as Go2. This includes proposals, draft specifications, dev implementations, etc.

70688 questions
29
votes
3 answers

Passing by reference and value in Go to functions

I am a bit confused about passing by reference and value in Go. I've seen this explained of the * in front of a type. * in front of a type name, means that the declared variable will store an address of another variable of that type (not a value of…
N P
  • 2,319
  • 7
  • 32
  • 54
29
votes
5 answers

Buffer implementing io.WriterAt in go

I'm using the aws-sdk to download a file from an s3 bucket. The S3 download function want's something that implements io.WriterAt however bytes.Buffer doesn't implement that. Right now I'm creating a file which implements io.WriterAt but I'd like…
Onestay
  • 458
  • 1
  • 5
  • 12
29
votes
2 answers

Passing an optimization flag to a Go compiler?

To compile a Go program you type go build myprogram.go, can you pass an optimization flags along or the code is always compiled in the same way? I am talking about speed optimizations, code size optimizations or other optimizations. I know if you…
exebook
  • 32,014
  • 33
  • 141
  • 226
29
votes
1 answer

When do you embed mutex in struct in Go?

NOTE: I found the word 'embed' in the title was bad choice, but I will keep it. I see a lot of code does like this: type A struct { mu sync.Mutex ... } And use it like this: a := &A{} a.mu.Lock() defer a.mu.Unlock() a.Something() Is it…
kim yong bin
  • 439
  • 1
  • 4
  • 9
29
votes
2 answers

How do I serve CSS and JS in Go

I followed the Go Writing Web Applications tutorial but for whatever reason I am having trouble getting the app to serve CSS and JS. If I run my static page without the Go server the page CSS works fine. When I run the Go server on the other hand…
bmacrevolution
  • 553
  • 2
  • 6
  • 14
29
votes
4 answers

Printing " (double quote) in GoLang

I am writing a Go code which reads from a file. To do so I use fmt.Println() to print into that intermediate file. How can I print "?
bender
  • 369
  • 1
  • 4
  • 9
29
votes
4 answers

Is there a way to extract JSON from an http response without having to build structs?

All of the ways I'm seeing involve building structs and unmarshalling the data into the struct. But what if I'm getting JSON responses with hundreds of fields? I don't want to have to create 100 field structs just to be able to get to the data I…
user2494770
29
votes
3 answers

How to verify JWT signature with JWK in Go?

I have been searching for an example I can understand of how to validate the signature of a JWT with the Go Language. This might be especially tricky since I am using Okta, and it uses JWKs, so it is not especially straight forward. When I receive a…
user3888307
  • 2,825
  • 5
  • 22
  • 32
29
votes
4 answers

Golang dynamically creating member of struct

I know there is struct in Go, but for all I know, you have to define struct type Circle struct{ x,y,r float64 } I am wondering how you can declare a new variable that doesn't exist in the struct circle := new(Circle) circle.color = "black"
UniSound Waterloo
  • 531
  • 1
  • 7
  • 22
29
votes
4 answers

Optimising datastructure/word alignment padding in golang

Similar to what I've learned in C++, I believe it's the padding that causes a difference in the size of instances of both structs. type Foo struct { w byte //1 byte x byte //1 byte y uint64 //8 bytes } type Bar struct { x byte //1…
nohup
  • 3,105
  • 3
  • 27
  • 52
29
votes
1 answer

error parsing regexp: invalid or unsupported Perl syntax: `(?!`

When I try this regex in golang I'm getting regex parsing error. error parsing regexp: invalid or unsupported Perl syntax: (?! regexp.MustCompile("^(?!On.*On\\s.+?wrote:)(On\\s(.+?)wrote:)$"), Can someone tell me why its not working and help me…
Giri
  • 4,849
  • 11
  • 39
  • 48
29
votes
1 answer

How to get count of sql.Rows without using Next()?

I need to get the length of *sql.Rows before I begin my Next() loop to get the values out. One way is to create a slice of rows by looping over Next() twice, getting the count, and then looping over that new slice to pull the values out, but that…
b0xxed1n
  • 2,063
  • 5
  • 20
  • 30
29
votes
5 answers

golang cannot execute binary file: Exec format error

my go env GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread…
mg03
  • 667
  • 2
  • 9
  • 14
29
votes
4 answers

How to run `go fmt` on save, in Visual Studio Code?

How to make Visual Studio Code (or Go Programming Language Extension) to run go fmt (or other tools/commands) on save? Even auto save? Update: It is working now perfectly inside VSCode, at this time; just need to add some config files inside .vscode…
Kaveh Shahbazian
  • 13,088
  • 13
  • 80
  • 139
29
votes
2 answers

What is the difference between cookie and cookiejar?

Today I faced the term "cookiejar" (package net/http/cookiejar). I tried to gather some information regarding it, but got nothing intelligible came out. I know that cookie is key/value pairs that server sends to a client, eg: Set-Cookie: foo=10,…
Timur Fayzrakhmanov
  • 17,967
  • 20
  • 64
  • 95