mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
39 lines
850 B
Go
39 lines
850 B
Go
package client
|
|
|
|
import (
|
|
"errors"
|
|
"regexp"
|
|
)
|
|
|
|
const (
|
|
atlarMetadataSpecNamespace = "com.atlar.spec/"
|
|
)
|
|
|
|
func ExtractNamespacedMetadataIgnoreEmpty(metadata map[string]string, key string) *string {
|
|
value := metadata[atlarMetadataSpecNamespace+key]
|
|
return &value
|
|
}
|
|
|
|
type IdentifierData struct {
|
|
Market string
|
|
Type string
|
|
Number string
|
|
}
|
|
|
|
var identifierMetadataRegex = regexp.MustCompile(`^com\.atlar\.spec/identifier/([^/]+)/([^/]+)$`)
|
|
|
|
func metadataToIdentifierData(key, value string) (*IdentifierData, error) {
|
|
// Find matches in the input string
|
|
matches := identifierMetadataRegex.FindStringSubmatch(key)
|
|
if matches == nil {
|
|
return nil, errors.New("input does not match the expected format")
|
|
}
|
|
|
|
// Extract values from the matched groups
|
|
return &IdentifierData{
|
|
Market: matches[1],
|
|
Type: matches[2],
|
|
Number: value,
|
|
}, nil
|
|
}
|