internal: implement GetRouteHost
This commit is contained in:
parent
76a4931554
commit
45a0d08b27
|
@ -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})
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue