From 62cc053c109652759d2a30aaf0b47c96e6a567b8 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 13 Aug 2017 14:41:00 +1200 Subject: [PATCH] implement ArchiveServer.bestSlugFor() --- Router.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Router.go b/Router.go index a63405b..0912acf 100644 --- a/Router.go +++ b/Router.go @@ -1,6 +1,7 @@ package archive import ( + "errors" "fmt" "net/http" "net/url" @@ -36,6 +37,23 @@ func (this *ArchiveServer) lookupSource(slug string) *LogSource { return nil // not found } +func (this *ArchiveServer) bestSlugFor(ls *LogSource) (string, error) { + for i := 0; i < len(this.cfg.Logs); i += 1 { + if ls != &this.cfg.Logs[i] { + continue + } + + if len(this.cfg.Logs[i].Slugs) > 0 { + return this.cfg.Logs[i].Slugs[0], nil // first slug is preferred + } else { + return fmt.Sprintf(`%d`, i), nil // no slugs present? use numeric log index + } + + } + + return "", errors.New("Unregistered log source") +} + func (this *ArchiveServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", SERVER_VERSION)