internal/{database,server}: use ID instead of host

This commit is contained in:
Cadey Ratio 2017-12-02 18:00:13 -08:00
parent 107d40fc87
commit bbfefefe3c
3 changed files with 6 additions and 6 deletions

View File

@ -52,11 +52,11 @@ var (
)
// GetRoute gets a single route out of the database.
func (b *BoltDBStorage) GetRoute(ctx context.Context, host string) (Route, error) {
func (b *BoltDBStorage) GetRoute(ctx context.Context, id string) (Route, error) {
r := Route{}
err := b.db.One("Hostname", host, &r)
err := b.db.One("ID", id, &r)
if err != nil {
ln.Error(ctx, err, ln.Action("get route"), ln.F{"host": host})
ln.Error(ctx, err, ln.Action("get route"), ln.F{"id": id})
switch err {
case storm.ErrNotFound:

View File

@ -9,7 +9,7 @@ import (
// Storage is the parent interface for the database backends of route.
type Storage interface {
// routes
GetRoute(ctx context.Context, host string) (Route, error)
GetRoute(ctx context.Context, id 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

View File

@ -24,9 +24,9 @@ func (r *Route) Get(ctx context.Context, req *proto.GetRouteRequest) (*proto.Rou
return nil, handleError(ctx, clitok, err, ln.F{"action": "Route.Get_getAuth"})
}
val, err := r.db.GetRoute(ctx, req.Host)
val, err := r.db.GetRoute(ctx, req.Id)
if err != nil {
return nil, handleError(ctx, clitok, err, ln.F{"action": "get single route from database", "host": req.Host})
return nil, handleError(ctx, clitok, err, ln.F{"action": "get single route from database", "id": req.Id})
}
if val.Creator != clitok.Owner {