Make database path more dynamic

This commit is contained in:
2021-07-26 19:47:29 -05:00
parent fbeb439bc0
commit 3ad49a082c
2 changed files with 26 additions and 4 deletions

View File

@ -16,7 +16,9 @@ import (
const dbBucket = "hats"
type Server struct{}
type Server struct {
DBPath string
}
type Hat struct {
Inches int32 `json:"inchues"`
@ -64,7 +66,7 @@ func HatQueryToHatQueryModel(q *pb.HatQuery) HatQuery {
}
func (s *Server) MakeHat(ctx context.Context, size *pb.Size) (hat *pb.Hat, err error) {
st, _ := NewStore("hat.db", 0600, nil)
st, _ := NewStore(s.DBPath, 0600, nil)
defer st.Close()
if size.Inches <= 0 {
@ -85,7 +87,7 @@ func (s *Server) MakeHat(ctx context.Context, size *pb.Size) (hat *pb.Hat, err e
}
func (s *Server) ListHats(ctx context.Context, q *pb.HatQuery) (hats *pb.Hats, err error) {
st, _ := NewStore("hat.db", 0600, nil)
st, _ := NewStore(s.DBPath, 0600, nil)
defer st.Close()
hs, err := st.ListHats(HatQueryToHatQueryModel(q))