database: add GetRouteForHost function

This commit is contained in:
Cadey Ratio 2017-03-26 12:51:23 -07:00
parent ede0affbdc
commit 87be7e8a30
1 changed files with 16 additions and 0 deletions

View File

@ -66,6 +66,22 @@ func (db *DB) SaveRoute(resp *routerpc.AddHostResponse) error {
return nil
}
func (db *DB) GetRouteForHost(name string) (*Route, error) {
rows, err := r.Table("routes").Filter(r.Row.Field("hostname", name).Or(r.Row.Field("onionhostname", name))).Run(db.s)
if err != nil {
return nil, err
}
result := &Route{}
err = rows.One(result)
if err != nil {
return nil, err
}
return result, nil
}
// GetAllRoutes fetches all of the route entries from the database
// and returns them. This is intended for the startup process or
// admin tooling.