本站源代码
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.

49 satır
912B

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