func (v *TLSConfig) Build() (*serial.TypedMessage, error) { config := new(tls.Config) config.Certificate = make([]*tls.Certificate, len(v.Certs)) for idx, certConf := range v.Certs { cert, err := ioutil.ReadFile(certConf.CertFile) if err != nil { return nil, errors.Base(err).Message("Failed to load TLS certificate file: ", certConf.CertFile) } key, err := ioutil.ReadFile(certConf.KeyFile) if err != nil { return nil, errors.Base(err).Message("Failed to load TLS key file: ", certConf.KeyFile) } config.Certificate[idx] = &tls.Certificate{ Key: key, Certificate: cert, } } config.AllowInsecure = v.Insecure if len(v.ServerName) > 0 { config.ServerName = v.ServerName } return serial.ToTypedMessage(config), nil }