Skip to content

Instantly share code, notes, and snippets.

@hfogelberg
Last active June 29, 2017 07:31
Show Gist options
  • Save hfogelberg/d3695ba44cc59fda84e3386bdaac451b to your computer and use it in GitHub Desktop.
Save hfogelberg/d3695ba44cc59fda84e3386bdaac451b to your computer and use it in GitHub Desktop.
// Print header
func myFunc(w http.ResponseWriter, r *http.Request) {
for k, v := range r.Header {
log.Println("key:", k, "value:", v)
}
}
// A. Print type of variable
fmt.Printf("Type of x %T\n", x)
// B. Composite literals
type person struct {
fname string
lname string
}
func main() {
// 1. Slice
numbers := []int{1, 1, 2, 3, 5, 8, 13}
fmt.Println("Slice")
fmt.Println(numbers)
// 2. Map
ages := map[string] int {
"Henrik": 49,
"Ramona": 12,
"Obi": 6,
}
fmt.Println(ages)
// 3. struct
p1 := person{"Luke", "Skywalker"}
fmt.Println(p1)
}
// 3. Function calls
type person struct {
fname string
lname string
}
type jedi struct {
person
hasForce bool
}
func (p person) speak() {
fmt.Println("I want money, says " + p.fname + " " + p.lname)
}
func(j jedi) speak() {
fmt.Println(j.fname + " says May the force be with you")
}
func main() {
p1 := person{"Han", "Solo"}
fmt.Println(p1)
p1.speak()
j1 := jedi{
person {
"Luke",
"Skywalker",
} ,
true,
}
j1.speak()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment