Use net.JoinHostPort to concatenate the values you have in the struct
and pass the to http.Server struct.

  if _, err := toml.Decode("config.toml", &conf); err != nil {
    // handle error
  }

  addr, err := net.JoinHostPort(conf.Address, conf.PORT)

  if err != nil {
    // handle error
  }

  src := &http.Server{
    Addr: addr,
  }

Be sure to set explicit struct tags on your destination struct that
will be used for unmarshalling the toml. This way the decoder will know
which struct fields to populate.

  type Config struct {
    PORT    string `toml:"port"`
    Address string `toml:"address"`
  }

This will only be necessary though if you want the fields to map
differently depending on their name.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/594dc8061305a9d24a85bba3c403524eb4c9c637.camel%40andrewpillar.com.

Reply via email to