src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

string_slice.go (439B)


      1 package rulesfn
      2 
      3 // StringSlice is a string slice with a negative-index-aware Get method for use
      4 // in endpoint rule evaluation.
      5 type StringSlice []string
      6 
      7 // Get returns a pointer to the string at index i, or nil if the index is out
      8 // of bounds. Negative indices count from the end of the slice.
      9 func (s StringSlice) Get(i int) *string {
     10 	if i < 0 {
     11 		i = len(s) + i
     12 	}
     13 	if i < 0 || i >= len(s) {
     14 		return nil
     15 	}
     16 	v := s[i]
     17 	return &v
     18 }