remove pkg/strings

release-2.0
Blake Mizerany 2014-08-13 13:59:54 -07:00 committed by Yicheng Qin
parent 1039f3dcea
commit a2b9f9310c
4 changed files with 19 additions and 35 deletions

View File

@ -14,8 +14,6 @@ import (
"strconv"
"strings"
"time"
ustrings "github.com/coreos/etcd/pkg/strings"
)
// The default location for the etcd configuration file.
@ -158,7 +156,7 @@ func (c *Config) loadEnv(target interface{}) error {
case reflect.String:
value.Field(i).SetString(v)
case reflect.Slice:
value.Field(i).Set(reflect.ValueOf(ustrings.TrimSplit(v, ",")))
value.Field(i).Set(reflect.ValueOf(trimSplit(v, ",")))
case reflect.Float64:
newValue, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -239,10 +237,10 @@ func (c *Config) LoadFlags(arguments []string) error {
// Convert some parameters to lists.
if peers != "" {
c.Peers = ustrings.TrimSplit(peers, ",")
c.Peers = trimSplit(peers, ",")
}
if cors != "" {
c.CorsOrigins = ustrings.TrimSplit(cors, ",")
c.CorsOrigins = trimSplit(cors, ",")
}
return nil
@ -258,7 +256,7 @@ func (c *Config) LoadPeersFile() error {
if err != nil {
return fmt.Errorf("Peers file error: %s", err)
}
c.Peers = ustrings.TrimSplit(string(b), ",")
c.Peers = trimSplit(string(b), ",")
return nil
}
@ -415,3 +413,14 @@ func sanitizeBindAddr(bindAddr string, aurl *url.URL) (string, error) {
return net.JoinHostPort(bindAddr, aport), nil
}
// trimSplit slices s into all substrings separated by sep and returns a
// slice of the substrings between the separator with all leading and trailing
// white space removed, as defined by Unicode.
func trimSplit(s, sep string) []string {
trimmed := strings.Split(s, sep)
for i := range trimmed {
trimmed[i] = strings.TrimSpace(trimmed[i])
}
return trimmed
}

View File

@ -1,23 +0,0 @@
package string
import (
"strings"
)
// TrimSplit slices s into all substrings separated by sep and returns a
// slice of the substrings between the separator with all leading and trailing
// white space removed, as defined by Unicode.
func TrimSplit(s, sep string) []string {
trimmed := strings.Split(s, sep)
for i := range trimmed {
trimmed[i] = strings.TrimSpace(trimmed[i])
}
return trimmed
}
// Clone returns a copy of the string, so that we can safely point to the
// copy without worrying about changes via pointers.
func Clone(s string) string {
stringCopy := s
return stringCopy
}

View File

@ -6,7 +6,6 @@ import (
"time"
etcdErr "github.com/coreos/etcd/error"
ustrings "github.com/coreos/etcd/pkg/strings"
)
// explanations of Compare function result
@ -294,7 +293,7 @@ func (n *node) Repr(recurisive, sorted bool) *NodeExtern {
}
// since n.Value could be changed later, so we need to copy the value out
value := ustrings.Clone(n.Value)
value := n.Value
node := &NodeExtern{
Key: n.Path,
Value: &value,

View File

@ -26,7 +26,6 @@ import (
"time"
etcdErr "github.com/coreos/etcd/error"
ustrings "github.com/coreos/etcd/pkg/strings"
)
// The default version to set when the store is first initialized.
@ -236,7 +235,7 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
n.UpdateTTL(expireTime)
// copy the value for safety
valueCopy := ustrings.Clone(value)
valueCopy := value
eNode.Value = &valueCopy
eNode.Expiration, eNode.TTL = n.ExpirationAndTTL()
@ -432,7 +431,7 @@ func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (
eNode.Dir = true
} else {
// copy the value for safety
newValueCopy := ustrings.Clone(newValue)
newValueCopy := newValue
eNode.Value = &newValueCopy
}
@ -504,7 +503,7 @@ func (s *store) internalCreate(nodePath string, dir bool, value string, unique,
if !dir { // create file
// copy the value for safety
valueCopy := ustrings.Clone(value)
valueCopy := value
eNode.Value = &valueCopy
n = newKV(s, nodePath, value, nextIndex, d, "", expireTime)