Skip to content

Instantly share code, notes, and snippets.

@gotterdemarung
Created May 6, 2015 07:54
Show Gist options
  • Save gotterdemarung/810f96d4f46f10afb6ac to your computer and use it in GitHub Desktop.
Save gotterdemarung/810f96d4f46f10afb6ac to your computer and use it in GitHub Desktop.
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