Created
May 6, 2015 07:54
-
-
Save gotterdemarung/810f96d4f46f10afb6ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func GetParser () KeyParser { | |
compiledRegex := regexp.MustCompile("^([a-z0-9\\-_]*)\\+([a-z\\-]*)://(.+)") | |
return func(addr string) (*Key, error) { | |
matches := compiledRegex.FindStringSubmatch(addr) | |
if len(matches) != 4 { | |
return nil, fmt.Errorf("Wrong Eos tracking address format \"%s\"", addr) | |
} | |
tags := strings.Split(strings.ToLower(matches[3]), ":") | |
sort.Strings(tags) | |
key := new (Key); | |
key.Realm = matches[1] | |
key.Schema = matches[2] | |
key.Tags = tags | |
key.Fqn = key.Realm + "+" + key.Schema + "://" + strings.Join(key.Tags, ":") | |
h := fnv.New32a() | |
h.Write([]byte(key.Fqn)) | |
key.HashCode = h.Sum32(); | |
return key, nil; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment