github.com/lusis/distribution@v2.0.1+incompatible/registry/auth/token/stringset.go (about) 1 package token 2 3 // StringSet is a useful type for looking up strings. 4 type stringSet map[string]struct{} 5 6 // NewStringSet creates a new StringSet with the given strings. 7 func newStringSet(keys ...string) stringSet { 8 ss := make(stringSet, len(keys)) 9 ss.add(keys...) 10 return ss 11 } 12 13 // Add inserts the given keys into this StringSet. 14 func (ss stringSet) add(keys ...string) { 15 for _, key := range keys { 16 ss[key] = struct{}{} 17 } 18 } 19 20 // Contains returns whether the given key is in this StringSet. 21 func (ss stringSet) contains(key string) bool { 22 _, ok := ss[key] 23 return ok 24 } 25 26 // Keys returns a slice of all keys in this StringSet. 27 func (ss stringSet) keys() []string { 28 keys := make([]string, 0, len(ss)) 29 30 for key := range ss { 31 keys = append(keys, key) 32 } 33 34 return keys 35 }