// NewProtocolFromString converts a string into a govpn.Protocol
func NewProtocolFromString(p string) (Protocol, error) {
+ var k Protocol
+ var v string
lowP := strings.ToLower(p)
- for k, v := range protocolText {
+ for k, v = range protocolText {
if strings.ToLower(v) == lowP {
return k, nil
}
choices := make([]string, len(protocolText))
var index = 0
- for k, v := range protocolText {
- if v == p {
- z := k
- p = &z
- return nil
- }
- choices[index] = v
+ for k = range protocolText {
+ choices[index] = protocolText[k]
index++
}
- return Protocol(-1), errors.Errorf("Invalid protocol %q: %s", p, strings.Join(choices, ","))
+ return Protocol(-1), errors.Errorf(
+ "Invalid protocol %q: %s", p, strings.Join(choices, ","),
+ )
}
// SliceZero zeros each byte.
// CloseLog log an error if a io.Closer fail to Close
func CloseLog(c io.Closer, l *logrus.Logger, fields logrus.Fields) {
if err := c.Close(); err != nil {
- logrus.WithFields(fields).WithError(err).Error("Couldn't close connection")
+ logrus.WithFields(fields).WithError(err).Error("Can't close connection")
}
}