From 87be7e8a30cc9fe7b0595c111fa44c581206c98f Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 26 Mar 2017 12:51:23 -0700 Subject: [PATCH] database: add GetRouteForHost function --- database/db.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/database/db.go b/database/db.go index 8d20e64..fdba042 100644 --- a/database/db.go +++ b/database/db.go @@ -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.