Compare commits
No commits in common. "75cba09617053cfed68be7cdae109548be4ccd15" and "a35901b976571409d7ad57460aa41ee379d4025c" have entirely different histories.
75cba09617
...
a35901b976
@ -3,15 +3,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"haberdasher-twirp/haberdasher"
|
"haberdasher-twirp/haberdasher"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MaxSize = 12
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var host string = "http://localhost:8080"
|
var host string = "http://localhost:8080"
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
@ -20,7 +17,7 @@ func main() {
|
|||||||
|
|
||||||
client := haberdasher.NewHaberdasherProtobufClient(host, &http.Client{})
|
client := haberdasher.NewHaberdasherProtobufClient(host, &http.Client{})
|
||||||
|
|
||||||
hat, err := client.MakeHat(context.Background(), &haberdasher.Size{Inches: int32(rand.Intn(MaxSize))})
|
hat, err := client.MakeHat(context.Background(), &haberdasher.Size{Inches: 12})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("oh no: %v\n", err)
|
fmt.Printf("oh no: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -34,7 +34,7 @@ type Store struct {
|
|||||||
db *bolt.DB
|
db *bolt.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func PbToHatModel(h *pb.Hat) Hat {
|
func HatToHatModel(h *pb.Hat) Hat {
|
||||||
return Hat{
|
return Hat{
|
||||||
Inches: h.Inches,
|
Inches: h.Inches,
|
||||||
Color: h.Color,
|
Color: h.Color,
|
||||||
@ -42,7 +42,7 @@ func PbToHatModel(h *pb.Hat) Hat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HatModelToPb(h Hat) *pb.Hat {
|
func HatModelToHat(h Hat) *pb.Hat {
|
||||||
return &pb.Hat{
|
return &pb.Hat{
|
||||||
Inches: h.Inches,
|
Inches: h.Inches,
|
||||||
Color: h.Color,
|
Color: h.Color,
|
||||||
@ -50,16 +50,16 @@ func HatModelToPb(h Hat) *pb.Hat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HatsModelToPb(hs []Hat) (hats *pb.Hats) {
|
func HatsModelToHats(hs []Hat) (hats *pb.Hats) {
|
||||||
hats = &pb.Hats{}
|
hats = &pb.Hats{}
|
||||||
for _, h := range hs {
|
for _, h := range hs {
|
||||||
hat := HatModelToPb(h)
|
hat := HatModelToHat(h)
|
||||||
hats.Hats = append(hats.Hats, hat)
|
hats.Hats = append(hats.Hats, hat)
|
||||||
}
|
}
|
||||||
return hats
|
return hats
|
||||||
}
|
}
|
||||||
|
|
||||||
func PbToHatQueryModel(q *pb.HatQuery) HatQuery {
|
func HatQueryToHatQueryModel(q *pb.HatQuery) HatQuery {
|
||||||
return HatQuery{
|
return HatQuery{
|
||||||
Limit: q.Limit,
|
Limit: q.Limit,
|
||||||
}
|
}
|
||||||
@ -86,16 +86,16 @@ func (s *Server) MakeHat(ctx context.Context, size *pb.Size) (hat *pb.Hat, err e
|
|||||||
|
|
||||||
st.SaveHat(h)
|
st.SaveHat(h)
|
||||||
|
|
||||||
return HatModelToPb(h), nil
|
return HatModelToHat(h), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ListHats(ctx context.Context, q *pb.HatQuery) (hats *pb.Hats, err error) {
|
func (s *Server) ListHats(ctx context.Context, q *pb.HatQuery) (hats *pb.Hats, err error) {
|
||||||
st, _ := NewStore(s.DBPath, 0600, nil)
|
st, _ := NewStore(s.DBPath, 0600, nil)
|
||||||
defer st.Close()
|
defer st.Close()
|
||||||
|
|
||||||
hs, err := st.ListHats(PbToHatQueryModel(q))
|
hs, err := st.ListHats(HatQueryToHatQueryModel(q))
|
||||||
|
|
||||||
return HatsModelToPb(hs), nil
|
return HatsModelToHats(hs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func itob(v uint64) []byte {
|
func itob(v uint64) []byte {
|
||||||
|
Loading…
Reference in New Issue
Block a user