You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package options
  5. //go:generate go-bindata -tags "bindata" -ignore "TRANSLATORS" -pkg "options" -o "bindata.go" ../../options/...
  6. //go:generate go fmt bindata.go
  7. //go:generate sed -i.bak s/..\/..\/options\/// bindata.go
  8. //go:generate rm -f bindata.go.bak
  9. type directorySet map[string][]string
  10. func (s directorySet) Add(key string, value []string) {
  11. _, ok := s[key]
  12. if !ok {
  13. s[key] = make([]string, 0, len(value))
  14. }
  15. s[key] = append(s[key], value...)
  16. }
  17. func (s directorySet) Get(key string) []string {
  18. _, ok := s[key]
  19. if ok {
  20. result := []string{}
  21. seen := map[string]string{}
  22. for _, val := range s[key] {
  23. if _, ok := seen[val]; !ok {
  24. result = append(result, val)
  25. seen[val] = val
  26. }
  27. }
  28. return result
  29. }
  30. return []string{}
  31. }
  32. func (s directorySet) AddAndGet(key string, value []string) []string {
  33. s.Add(key, value)
  34. return s.Get(key)
  35. }
  36. func (s directorySet) Filled(key string) bool {
  37. return len(s[key]) > 0
  38. }