Skip to content

Instantly share code, notes, and snippets.

@robertBojor
Last active Jul 25, 2017
Embed
What would you like to do?
GoLang Questions

Questions

1. What is the output of the following program?

package main
import "fmt"
type User struct {
	Name string
}
var user User
func main() {
	fmt.Println(user)
}

2. What is the output of the following program?

package main
import "fmt"

func main() {
 x := 1
 y := &x
 fmt.Println(*y)
 *y = 2
 fmt.Println(x)
}

3. What is the output of the following program?

package main
import "fmt"

func main() {
 defer func() { fmt.Println("A") }()
 go func() { fmt.Println("C") }()
 fmt.Println("B")
}

4. How can you achieve polymorphism in golang. Please provide a short example.

5. Enumerate some standard libraries and their usage.

6. Write a short function that return a read only channel.

7. Write a short example of data synchronization in go

8. Enumerate some go cli commands

9. How can you achieve cross-compiling?

10. Fix this code to print the output.

package main

import "fmt"
import "encoding/json"

type Event struct {
	Name string
	Data interface{}
}

var e Event = Event{"x", "y"}

func main() {
	str, _ := json.Marshal(e)
	fmt.Println(str)
}

EXPECTED OUTPUT: {"name":"x","data":"y"}

Exercice ( ± 60min )

Write a minimal thread pool using go routines and channels.

Requirements:

  • Use 3 workers
  • Program should receive a json file like following ['{URL_TO_IMAGE}', ...] as first param demo ./images.json
  • All files should be stored in ./data folder ( Create folder if missing )
  • For each download print the following:

#X is the id of the thread number ( #1 - .... )

Done when:

  • A file name demo.go is provided
  • It successfully compiles
  • The binary output meets requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment