internal: implement GetRouteHost

This commit is contained in:
Cadey Ratio 2017-12-02 18:16:37 -08:00
parent 76a4931554
commit 45a0d08b27
3 changed files with 12 additions and 3 deletions

View File

@ -51,10 +51,18 @@ var (
_ Storage = &BoltDBStorage{} _ Storage = &BoltDBStorage{}
) )
// GetRoute gets a single route out of the database.
func (b *BoltDBStorage) GetRoute(ctx context.Context, id string) (Route, error) { 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{} r := Route{}
err := b.db.One("ID", id, &r) err := b.db.One(match, val, &r)
if err != nil { if err != nil {
ln.Error(ctx, err, ln.Action("get route"), ln.F{"id": id}) ln.Error(ctx, err, ln.Action("get route"), ln.F{"id": id})

View File

@ -10,6 +10,7 @@ import (
type Storage interface { type Storage interface {
// routes // routes
GetRoute(ctx context.Context, id string) (Route, error) GetRoute(ctx context.Context, id string) (Route, error)
GetRouteHost(ctx context.Context, host string) (Route, error)
GetAllRoutes(ctx context.Context, user string) ([]Route, error) GetAllRoutes(ctx context.Context, user string) ([]Route, error)
PutRoute(ctx context.Context, domain, kind string) (Route, error) PutRoute(ctx context.Context, domain, kind string) (Route, error)
DeleteRoute(ctx context.Context, id string) error DeleteRoute(ctx context.Context, id string) error

View File

@ -25,7 +25,7 @@ func (s *storageWrapper) HasToken(token string) (string, []string, error) {
} }
func (s *storageWrapper) HasRoute(domain 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 { if err != nil {
return "", err return "", err
} }