From 2cb0fbf58964929b36b9e70a0a51ef841bf1fb44 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 8 Aug 2015 17:03:13 +0200 Subject: [PATCH] backend: Add String() to IDs --- backend/ids.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/ids.go b/backend/ids.go index f2569f7e0..11cf436d2 100644 --- a/backend/ids.go +++ b/backend/ids.go @@ -1,5 +1,10 @@ package backend +import ( + "encoding/hex" + "fmt" +) + // IDs is an ordered list of IDs that implements sort.Interface. type IDs []ID @@ -48,3 +53,17 @@ func (ids IDs) Uniq() (list IDs) { return list } + +type shortID ID + +func (id shortID) String() string { + return hex.EncodeToString(id[:shortStr]) +} + +func (ids IDs) String() string { + elements := make([]shortID, 0, len(ids)) + for _, id := range ids { + elements = append(elements, shortID(id)) + } + return fmt.Sprintf("%v", elements) +}