N
N
NOONE2018-07-29 21:01:44
go
NOONE, 2018-07-29 21:01:44

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

1 answer(s)
M
m0nym, 2018-07-29
@Djam36

how an entry from the config.json file appeared in the Configuration variable if we read the file into the file variable.

So
decoder := json.NewDecoder(file)
err = decoder.Decode(Configuration)

That is
Pointers here insofar as.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question