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.

options.go 870B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }