Answer the question
In order to leave comments, you need to log in
Golang explain by pointers? How it works?
Hello, I understand what pointers are, but I don’t understand this piece of code, it seems simple, but the question arises how the entry from the config.json file appeared in the Configuration variable if we read the file into the file variable.
package Parser
import (
"os"
"encoding/json"
)
type Configuration struct {
Directory string
}
func ParsConfig() *Configuration {
file, err := os.Open("conf.json")
if err != nil {
panic(err)
}
defer file.Close()
Configuration := &Configuration{}
decoder := json.NewDecoder(file)
err = decoder.Decode(Configuration)
if err != nil {
panic(err)
}
return Configuration
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question