From 45a0d08b273b4dc7b103d59383ce65287b964bd6 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 2 Dec 2017 18:16:37 -0800 Subject: [PATCH] internal: implement GetRouteHost --- internal/database/boltdb.go | 12 ++++++++++-- internal/database/storage.go | 1 + internal/server/storage.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/database/boltdb.go b/internal/database/boltdb.go index fa6531d..dfe8b45 100644 --- a/internal/database/boltdb.go +++ b/internal/database/boltdb.go @@ -51,10 +51,18 @@ var ( _ Storage = &BoltDBStorage{} ) -// GetRoute gets a single route out of the database. func (b *BoltDBStorage) GetRoute(ctx context.Context, id string) (Route, error) { + return b.getRouteBy(ctx, "ID", id) +} + +func (b *BoltDBStorage) GetRouteHost(ctx context.Context, id string) (Route, error) { + return b.getRouteBy(ctx, "Hostname", id) +} + +// getRouteBy gets a single route out of the database by a given field data. +func (b *BoltDBStorage) getRouteBy(ctx context.Context, match, val string) (Route, error) { r := Route{} - err := b.db.One("ID", id, &r) + err := b.db.One(match, val, &r) if err != nil { ln.Error(ctx, err, ln.Action("get route"), ln.F{"id": id}) diff --git a/internal/database/storage.go b/internal/database/storage.go index 27de07d..5c34e23 100644 --- a/internal/database/storage.go +++ b/internal/database/storage.go @@ -10,6 +10,7 @@ import ( type Storage interface { // routes GetRoute(ctx context.Context, id string) (Route, error) + GetRouteHost(ctx context.Context, host string) (Route, error) GetAllRoutes(ctx context.Context, user string) ([]Route, error) PutRoute(ctx context.Context, domain, kind string) (Route, error) DeleteRoute(ctx context.Context, id string) error diff --git a/internal/server/storage.go b/internal/server/storage.go index 23f2e55..da63ea0 100644 --- a/internal/server/storage.go +++ b/internal/server/storage.go @@ -25,7 +25,7 @@ func (s *storageWrapper) HasToken(token string) (string, []string, error) { } func (s *storageWrapper) HasRoute(domain string) (string, error) { - r, err := s.Storage.GetRoute(context.Background(), domain) + r, err := s.Storage.GetRouteHost(context.Background(), domain) if err != nil { return "", err }