implement ArchiveServer.bestSlugFor()

This commit is contained in:
mappu 2017-08-13 14:41:00 +12:00
parent 4a7a3ba867
commit 62cc053c10
1 changed files with 18 additions and 0 deletions

View File

@ -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)