From f66609bbaeb5a31e3574bcbcb0796e1cc7fabde2 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 7 Nov 2024 09:18:11 +0300 Subject: [PATCH] add helper for getting db key from string --- common/db.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/db.go b/common/db.go index 1992476..e90fd47 100644 --- a/common/db.go +++ b/common/db.go @@ -2,6 +2,7 @@ package common import ( "encoding/binary" + "errors" "git.defalsify.org/vise.git/logging" ) @@ -48,3 +49,23 @@ func PackKey(typ DataTyp, data []byte) []byte { v := typToBytes(typ) return append(v, data...) } + +func StringToDataTyp(str string) (DataTyp, error) { + switch str { + case "DATA_FIRST_NAME": + return DATA_FIRST_NAME, nil + case "DATA_FAMILY_NAME": + return DATA_FAMILY_NAME, nil + case "DATA_YOB": + return DATA_YOB, nil + case "DATA_LOCATION": + return DATA_LOCATION, nil + case "DATA_GENDER": + return DATA_GENDER, nil + case "DATA_OFFERINGS": + return DATA_OFFERINGS, nil + + default: + return 0, errors.New("invalid DataTyp string") + } +}