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.

46 lines
870 B

  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. type directorySet map[string][]string
  6. func (s directorySet) Add(key string, value []string) {
  7. _, ok := s[key]
  8. if !ok {
  9. s[key] = make([]string, 0, len(value))
  10. }
  11. s[key] = append(s[key], value...)
  12. }
  13. func (s directorySet) Get(key string) []string {
  14. _, ok := s[key]
  15. if ok {
  16. result := []string{}
  17. seen := map[string]string{}
  18. for _, val := range s[key] {
  19. if _, ok := seen[val]; !ok {
  20. result = append(result, val)
  21. seen[val] = val
  22. }
  23. }
  24. return result
  25. }
  26. return []string{}
  27. }
  28. func (s directorySet) AddAndGet(key string, value []string) []string {
  29. s.Add(key, value)
  30. return s.Get(key)
  31. }
  32. func (s directorySet) Filled(key string) bool {
  33. return len(s[key]) > 0
  34. }