Update 26th July 2019 (for go >=1.11)
go run .
Will work on windows as well.
Original answer (for non windows environments)
The code actually works. The problem was that instead of running go run main.go
I should run:
go run *.go
More Related Contents:
- How to import local packages without gopath
- Is there any way to access private fields of a struct from another package?
- Create a generic channel
- How to use a module that is outside of “GOPATH” in another module?
- How can I convert string to integer in golang
- Cyclic dependencies and interfaces
- Accessing struct fields inside a map value (without copying)
- Why do I get a “cannot assign” error when setting value to a struct as a value in a map? [duplicate]
- Can I concurrently write different slice elements
- Organize local code in packages using Go modules
- Golang Dependency Management Best Practice
- How can I pass a slice as a variadic input?
- Does Go provide REPL?
- How to compare if two structs, slices or maps are equal?
- Golang defer behavior
- Example for sync.WaitGroup correct?
- Stack vs heap allocation of structs in Go, and how they relate to garbage collection
- How to fix parsing go.mod module declares its path as “x” but was required as “y”
- What is the meaning of “dot parenthesis” syntax? [duplicate]
- What is the idiomatic Go equivalent of C’s ternary operator?
- Can I construct a slice of a generic type with different type parameters?
- Why would I make() or new()?
- How do I reverse a slice in go?
- How to delete an element from a Slice in Golang
- How do I compare two functions for pointer equality in the latest Go weekly?
- Go struct tags with underscore before function names
- calling command with some arguments works but not with others but works from console
- Do buffered channels maintain order?
- Build Docker Image From Go Code
- What do “value semantics’” and “pointer semantics” mean in Go?