]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/cypherpunks.ru/govpn/common.go
Stylistical change
[govpn.git] / src / cypherpunks.ru / govpn / common.go
index ca629c06317ec50f4c5f3608e18846bdd29459a4..72873d05f17e716f4064315979dcf7b6ce475727 100644 (file)
@@ -89,7 +89,11 @@ func (p Protocol) MarshalJSON() ([]byte, error) {
 func (p *Protocol) UnmarshalJSON(encoded []byte) error {
        var str string
        if err := json.Unmarshal(encoded, &str); err != nil {
-               return errors.Wrapf(err, "Can't unmarshall to string %q", hex.EncodeToString(encoded))
+               return errors.Wrapf(
+                       err,
+                       "Can't unmarshall to string %q",
+                       hex.EncodeToString(encoded),
+               )
        }
        proto, err := NewProtocolFromString(str)
        if err != nil {
@@ -117,8 +121,10 @@ func (p *Protocol) UnmarshalYAML(unmarshal func(interface{}) error) error {
 
 // 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
                }
@@ -126,17 +132,14 @@ func NewProtocolFromString(p string) (Protocol, error) {
 
        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.
@@ -146,12 +149,12 @@ func SliceZero(data []byte) {
        }
 }
 
-// VersionGet return version of GoVPN
+// VersionGet returns version of GoVPN
 func VersionGet() string {
        return "GoVPN version " + Version + " built with " + runtime.Version()
 }
 
-// CatchSignalShutdown return a channel.
+// CatchSignalShutdown returns a channel.
 // that channel will get a SIG_INT or SIG_KILL signal is received
 // this is intended to be used to stop a client/server
 func CatchSignalShutdown() chan interface{} {
@@ -178,6 +181,6 @@ func SetLogger(l *logrus.Logger) {
 // 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")
        }
 }