From efdd3a29b38f49332ee6383aea275636e5e9a3e7 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 5 Oct 2022 22:33:03 +0200 Subject: [PATCH] Identifier: New functions to create from string and know if empty --- model/identifier.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/model/identifier.go b/model/identifier.go index 31a3207..d1f00bb 100644 --- a/model/identifier.go +++ b/model/identifier.go @@ -5,8 +5,18 @@ import ( "errors" ) +const IDENTIFIER_LEN = 48 + type Identifier []byte +func NewIdentifierFromString(src string) (id Identifier, err error) { + return base64.RawURLEncoding.DecodeString(src) +} + +func (i *Identifier) IsEmpty() bool { + return len(*i) == 0 +} + func (i *Identifier) ToString() string { return base64.RawURLEncoding.EncodeToString(*i) }