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 944B

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