Skip to content
Snippets Groups Projects
Select Git revision
  • 6969dc60948892a7180f3ac9a85c496cc5ae8d35
  • main default protected
  • v1.302.0
  • v1.301.0
  • v1.300.0
  • v1.299.0
  • v1.298.0
  • 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
22 results

struct_utils.go

Blame
  • struct_utils.go 944 B
    package struct_utils
    
    import "strings"
    
    // KeyValuePair defines a key/value pair derived from form data
    type KeyValuePair struct {
    	Key   string `json:"key"`
    	Value string `json:"value"`
    }
    
    // FormToKeyValuePairs returns a string-based map of strings as derived from posted form keys and values.
    // e.g. oauth_consumer_key=mlhgs&oauth_consumer_secret=x240ar&oauth_verifier=b0qjbx&store_base_url=http%3A%2F%2Flocalhost.com%2Fstore
    func FormToKeyValuePairs(body string) []KeyValuePair {
    	out := []KeyValuePair{}
    	parts := strings.Split(body, "&")
    	for _, p := range parts {
    		split := strings.Split(p, "=")
    		k := split[0]
    		v := split[1]
    		kv := KeyValuePair{
    			Key:   k,
    			Value: v,
    		}
    		out = append(out, kv)
    	}
    
    	return out
    }
    
    // GetValue returns the value for the given key from a KeyValuePair slice.
    func GetValue(key string, kv []KeyValuePair) string {
    	for _, v := range kv {
    		if v.Key == key {
    			return v.Value
    		}
    	}
    
    	return ""
    }