Initial commit
This commit is contained in:
35
cmd/client/main.go
Normal file
35
cmd/client/main.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"haberdasher-twirp/haberdasher"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var host string = "http://localhost:8080"
|
||||
if len(os.Args) > 1 {
|
||||
host = os.Args[1]
|
||||
}
|
||||
|
||||
client := haberdasher.NewHaberdasherProtobufClient(host, &http.Client{})
|
||||
|
||||
hat, err := client.MakeHat(context.Background(), &haberdasher.Size{Inches: 12})
|
||||
if err != nil {
|
||||
fmt.Printf("oh no: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("I have a nice new hat: %+v\n", hat)
|
||||
|
||||
hats, err := client.ListHats(context.Background(), &haberdasher.HatQuery{Limit: 20})
|
||||
if err != nil {
|
||||
fmt.Printf("oh no: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for i, h := range hats.Hats {
|
||||
fmt.Printf("%d: %+v\n", i, h)
|
||||
}
|
||||
}
|
20
cmd/main.go
Normal file
20
cmd/main.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"haberdasher-twirp/haberdasher"
|
||||
"haberdasher-twirp/internal/haberdasherserver"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var bind string = ":8080"
|
||||
if len(os.Args) > 1 {
|
||||
bind = os.Args[1]
|
||||
}
|
||||
server := &haberdasherserver.Server{}
|
||||
twirpHandler := haberdasher.NewHaberdasherServer(server)
|
||||
|
||||
http.ListenAndServe(bind, twirpHandler)
|
||||
}
|
Reference in New Issue
Block a user