func (m StringMap) LongestValue() (string, string) {
	longest := ""
	longestv := ""
	for k, v := range m.M {
		if len(v) > len(longestv) {
			longest = k
			longestv = v
		}
	}
	return longest, longestv
}
LongestValue returns the key and value with the longest value. The first
longest value will win and Go maps to not promise any specific order.
package util
import (
	"encoding/json"
	"fmt"
	"sort"
	"strings"
	"sync"
)
type StringMap struct {
	M map[string]string
	sync.Mutex
}
func NewStringMap() *StringMap {
	m := new(StringMap)
	m.Init()
	return m
}
func ToStringMap(m map[string]interface{}) *StringMap {
	n := NewStringMap()
	defer n.Unlock()
	n.Lock()
	for k, v := range m {
		n.M[k] = v.(string)
	}
	return n
}
func (m *StringMap) Init() {
	defer m.Unlock()
	m.Lock()
	if m.M == nil {
		m.M = make(map[string]string)
		return
	}
	for k := range m.M {
		delete(m.M, k)
	}
}
func (m *StringMap) Get(key string) string {
	defer m.Unlock()
	m.Lock()
	if v, has := m.M[key]; has {
		return v
	}
	return ""
}
func (m *StringMap) Set(key, val string) {
	defer m.Unlock()
	m.Lock()
	m.M[key] = val
}
func (m *StringMap) Delete(keys ...string) {
	defer m.Unlock()
	m.Lock()
	for _, k := range keys {
		delete(m.M, k)
	}
}
func (m *StringMap) Rename(from, to string) {
	defer m.Unlock()
	m.Lock()
	v, has := m.M[from]
	if !has {
		return
	}
	m.M[to] = v
	delete(m.M, from)
}
func (m StringMap) Same() []string {
	defer m.Unlock()
	m.Lock()
	same := []string{}
	for k, v := range m.M {
		if k == v {
			same = append(same, v)
		}
	}
	sort.Strings(same)
	return same
}
func (m StringMap) Keys() []string {
	defer m.Unlock()
	m.Lock()
	keys := make([]string, len(m.M))
	var i int
	for k, _ := range m.M {
		keys[i] = k
		i++
	}
	sort.Strings(keys)
	return keys
}
func (m StringMap) Values() []string {
	defer m.Unlock()
	m.Lock()
	vals := []string{}
	seen := map[string]bool{}
	for _, v := range m.M {
		if _, saw := seen[v]; saw {
			continue
		}
		vals = append(vals, v)
		seen[v] = true
	}
	sort.Strings(vals)
	return vals
}
func (m StringMap) Aliases() []string {
	defer m.Unlock()
	m.Lock()
	a := []string{}
	for k, v := range m.M {
		if k == v {
			continue
		}
		a = append(a, k)
	}
	sort.Strings(a)
	return a
}
func (m StringMap) AliasesFor(val string) []string {
	defer m.Unlock()
	m.Lock()
	aliases := []string{}
	for k, v := range m.M {
		if k != v && v == val {
			aliases = append(aliases, k)
		}
	}
	sort.Strings(aliases)
	return aliases
}
func (m StringMap) KeysFor(val string) []string {
	defer m.Unlock()
	m.Lock()
	keys := []string{}
	hasSelf := false
	for k, v := range m.M {
		if v == val {
			if k == v {
				hasSelf = true
				continue
			}
			keys = append(keys, k)
		}
	}
	sort.Strings(keys)
	if hasSelf {
		keys = append(keys, val)
	}
	return keys
}
func (m StringMap) AliasesCombined(delim string) *StringMap {
	n := NewStringMap()
	n.Lock()
	for _, name := range m.Values() {
		n.M[name] = strings.Join(m.AliasesFor(name), delim)
	}
	n.Unlock()
	return n
}
func (m StringMap) KeysCombined(delim string) *StringMap {
	n := NewStringMap()
	n.Lock()
	for _, name := range m.Values() {
		n.M[name] = strings.Join(m.KeysFor(name), delim)
	}
	n.Unlock()
	return n
}
func (m StringMap) Slice(keys ...string) []string {
	defer m.Unlock()
	m.Lock()
	vals := make([]string, len(keys))
	for i, k := range keys {
		vals[i] = m.M[k]
	}
	return vals
}
func (m StringMap) HasSuffix(s string) *StringMap {
	n := NewStringMap()
	defer n.Unlock()
	n.Lock()
	for k, v := range m.M {
		if strings.HasSuffix(v, s) {
			n.M[k] = v
		}
	}
	return n
}
func (m StringMap) HasPrefix(s string) *StringMap {
	n := NewStringMap()
	defer n.Unlock()
	n.Lock()
	for k, v := range m.M {
		if strings.HasPrefix(v, s) {
			n.M[k] = v
		}
	}
	return n
}
func (m StringMap) LongestKey() (string, string) {
	longest := ""
	longestv := ""
	for k, v := range m.M {
		if len(k) > len(longest) {
			longest = k
			longestv = v
		}
	}
	return longest, longestv
}