如何将类型作为参数传递

I have the code which parses json config:

import (
    "encoding/json"
    "os"
    "fmt"
)

type Configuration struct {
    Users    []string
    Groups   []string
}

type AnotherConfiguration struct {
    Names    []string
}

file, _ := os.Open("conf.json")
decoder := json.NewDecoder(file)
configuration := Configuration{}
err := decoder.Decode(&configuration)
if err != nil {
  fmt.Println("error:", err)
}
fmt.Println(configuration.Users)

As you can see, I have two different types Configuration and AnotherConfiguration.

I can't quite figure out how to create a generic function, which would return a config for any type (Configuration or AnotherConfiguration).

Something like this:

func make(typename) {
  file, _ := os.Open("conf.json")
  decoder := json.NewDecoder(file)
  configuration := typename{}
  err := decoder.Decode(&configuration)
  if err != nil {
    fmt.Println("error:", err)
  }
  return configuration
}

Write your decode function to accept a pointer to the value to be decoded:

func decode(v interface{}) {
 file, _ := os.Open("conf.json")
 defer file.Close()
 decoder := json.NewDecoder(file)
 err := decoder.Decode(v)
 if err != nil {
   fmt.Println("error:", err)
 }
}

Call it like this:

var configuration Configuration
decode(&configuration)

var another AnotherConfiguration
decode(&another)

BTW, I renamed make to decode to avoid shadowing the builtin function.