commit a174bcaa72327f7ea119df2d4ec162b5f0f9656b Author: stephen mcquay Date: Tue Jan 16 20:57:04 2018 -0800 init diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..340187d --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +MIT License +Copyright (c) 2017 Stephen McQuay + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..92ea74b --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +# from http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + +default: ${GOPATH}/bin/hwtd ${GOPATH}/bin/hwtc + +${GOPATH}/bin/hwtd: $(call rwildcard,,*.go) + go install -v mcquay.me/hwt/cmd/hwtd + +${GOPATH}/bin/hwtc: $(call rwildcard,,*.go) + go install -v mcquay.me/hwt/cmd/hwtc + +service.twirp.go: service.proto + protoc --proto_path=${GOPATH}/src:. --twirp_out=. --go_out=. ./service.proto + +service.pb.go: service.proto + protoc --proto_path=${GOPATH}/src:. --twirp_out=. --go_out=. ./service.proto diff --git a/README.md b/README.md new file mode 100644 index 0000000..3ce9224 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# hwt + +Hello World [twirp](https://github.com/twitchtv/twirp) project. diff --git a/cmd/hwtc/main.go b/cmd/hwtc/main.go new file mode 100644 index 0000000..fc3550f --- /dev/null +++ b/cmd/hwtc/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "os" + "strings" + + "mcquay.me/hwt" +) + +const usage = "hwtc [subject]" + +func main() { + if len(os.Args) < 2 { + fmt.Fprintf(os.Stderr, "%v\n", usage) + os.Exit(1) + } + + c := hwt.NewHelloWorldProtobufClient("http://localhost:8080", &http.Client{}) + + resp, err := c.Hello(context.Background(), &hwt.HelloReq{Subject: strings.Join(os.Args[1:], " ")}) + if err != nil { + fmt.Fprintf(os.Stderr, "hello: %v\n", err) + os.Exit(1) + } + fmt.Printf("%v\n", resp) +} diff --git a/cmd/hwtd/main.go b/cmd/hwtd/main.go new file mode 100644 index 0000000..fdb5b31 --- /dev/null +++ b/cmd/hwtd/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "log" + "net/http" + + "mcquay.me/hwt" +) + +func main() { + s := &hwt.Server{} + th := hwt.NewHelloWorldServer(s, nil) + if err := http.ListenAndServe(":8080", th); err != nil { + log.Fatalf("listen and serve: %v", err) + } +} diff --git a/hwt.go b/hwt.go new file mode 100644 index 0000000..fffc3de --- /dev/null +++ b/hwt.go @@ -0,0 +1,12 @@ +package hwt + +import ( + "context" + fmt "fmt" +) + +type Server struct{} + +func (s *Server) Hello(ctx context.Context, req *HelloReq) (*HelloResp, error) { + return &HelloResp{Text: fmt.Sprintf("echo: %v", req.Subject)}, nil +} diff --git a/service.proto b/service.proto new file mode 100644 index 0000000..9cf77fa --- /dev/null +++ b/service.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package me.mcquay.hwt; + +option go_package = "hwt"; + +service HelloWorld { + rpc Hello(HelloReq) returns (HelloResp); +} + +message HelloReq { + string subject = 1; +} + +message HelloResp { + string text = 1; +}