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)