github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/pkg/uuid/uuid.go (about) 1 /*This file is part of kuberpult. 2 3 Kuberpult is free software: you can redistribute it and/or modify 4 it under the terms of the Expat(MIT) License as published by 5 the Free Software Foundation. 6 7 Kuberpult is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 MIT License for more details. 11 12 You should have received a copy of the MIT License 13 along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. 14 15 Copyright 2023 freiheit.com*/ 16 17 package uuid 18 19 import ( 20 "github.com/onokonem/sillyQueueServer/timeuuid" 21 "google.golang.org/protobuf/types/known/timestamppb" 22 ) 23 24 type UUID = timeuuid.UUID // just an alias for convenience 25 26 type GenerateUUIDs interface { 27 Generate() string 28 } 29 30 type RealUUIDGenerator struct { 31 } 32 33 func (t RealUUIDGenerator) Generate() string { 34 return timeuuid.TimeUUID().String() 35 } 36 37 func GetTime(id *UUID) *timestamppb.Timestamp { 38 var ts = id.Time() 39 result := timestamppb.New(ts) 40 return result 41 } 42 43 func TimeFromUUID(uuidStr string) *timestamppb.Timestamp { 44 uuidVar, _ := timeuuid.ParseUUID(uuidStr) 45 return GetTime(&uuidVar) 46 }