code.gitea.io/gitea@v1.19.3/modules/options/options.go (about)

     1  // Copyright 2016 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package options
     5  
     6  type directorySet map[string][]string
     7  
     8  func (s directorySet) Add(key string, value []string) {
     9  	_, ok := s[key]
    10  
    11  	if !ok {
    12  		s[key] = make([]string, 0, len(value))
    13  	}
    14  
    15  	s[key] = append(s[key], value...)
    16  }
    17  
    18  func (s directorySet) Get(key string) []string {
    19  	_, ok := s[key]
    20  
    21  	if ok {
    22  		result := []string{}
    23  		seen := map[string]string{}
    24  
    25  		for _, val := range s[key] {
    26  			if _, ok := seen[val]; !ok {
    27  				result = append(result, val)
    28  				seen[val] = val
    29  			}
    30  		}
    31  
    32  		return result
    33  	}
    34  
    35  	return []string{}
    36  }
    37  
    38  func (s directorySet) AddAndGet(key string, value []string) []string {
    39  	s.Add(key, value)
    40  	return s.Get(key)
    41  }
    42  
    43  func (s directorySet) Filled(key string) bool {
    44  	return len(s[key]) > 0
    45  }