Skip to content
Snippets Groups Projects
Select Git revision
  • cbaa5d0862c9d55c21e94075f6c714be999b77c6
  • main default protected
  • trading_hours
  • refactor_trading_hours
  • audit_cleaning_cater_for_non_struct_fields
  • remove-info-logs
  • sl-refactor
  • 18-use-scan-for-param-values
  • 17-order-search-results
  • 4-simplify-framework-2
  • 1-http-error
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
  • v1.278.0
31 results

oauth.go

Blame
  • key_reader.go 858 B
    package string_utils
    
    import (
    	"os"
    	"strings"
    )
    
    //KeyReader is an interface to read string "<key>":"<value>" pairs
    //which is common to read from the environment
    //it is abstracted so the same interface can be implemented for
    //reading for example from REDIS and other sources
    type KeyReader interface {
    	Keys(prefix string) []string
    	GetString(key string) (value string, ok bool)
    }
    
    func EnvironmentKeyReader() KeyReader {
    	return envKeyReader{}
    }
    
    type envKeyReader struct{}
    
    func (envKeyReader) GetString(key string) (value string, ok bool) {
    	value = os.Getenv(key)
    	if value == "" {
    		return "", false
    	}
    	return value, true
    }
    
    func (envKeyReader) Keys(prefix string) []string {
    	keys := []string{}
    	for _, env := range os.Environ() {
    		if strings.HasPrefix(env, prefix) {
    			keys = append(keys, strings.SplitN(env, "=", 2)[0])
    		}
    	}
    	return keys
    }