route/internal/database/route.go

57 lines
1.2 KiB
Go
Raw Normal View History

package database
import (
"io"
"time"
2017-04-29 01:09:14 +00:00
proto "git.xeserv.us/xena/route/proto"
2017-04-29 02:47:24 +00:00
"github.com/Xe/ln"
"golang.org/x/net/context"
)
// Routes is the set of API calls needed to manage Route resources.
//
// Database backends should implement this interface.
type Routes interface {
io.Closer
Get(ctx context.Context, id string) (Route, error)
GetHost(ctx context.Context, host string) (Route, error)
GetAll(ctx context.Context, user string) ([]Route, error)
Put(ctx context.Context, r Route) (Route, error)
Delete(ctx context.Context, r Route) (Route, error)
}
// Route is a single HTTP route.
type Route struct {
2017-04-29 05:43:04 +00:00
ID string `storm:"id"`
Creator string
2017-04-29 06:04:22 +00:00
Hostname string `storm:"unique"`
CreatedAt time.Time
EditedAt time.Time
Active bool
}
2017-04-29 02:47:24 +00:00
// F https://godoc.org/github.com/Xe/ln#F
func (r Route) F() ln.F {
return ln.F{
"route-id": r.ID,
"route-creator": r.Creator,
"route-hostname": r.Hostname,
}
}
func (r *Route) Scan(row Scanner) error {
return row.Scan(&r.ID, &r.Creator, &r.Hostname, &r.CreatedAt, &r.EditedAt, &r.Active)
}
// AsProto converts this into a protobuf Route.
2017-04-29 01:09:14 +00:00
func (r Route) AsProto() *proto.Route {
return &proto.Route{
Id: r.ID,
Creator: r.Creator,
Host: r.Hostname,
}
}