Skip to content

Instantly share code, notes, and snippets.

@robertBojor
Last active July 25, 2017 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertBojor/1c69026e3c56b4cfd62c529fccb3fbab to your computer and use it in GitHub Desktop.
Save robertBojor/1c69026e3c56b4cfd62c529fccb3fbab to your computer and use it in GitHub Desktop.
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