init
This commit is contained in:
commit
a174bcaa72
20
LICENSE
Normal file
20
LICENSE
Normal file
@ -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.
|
16
Makefile
Normal file
16
Makefile
Normal file
@ -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
|
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# hwt
|
||||
|
||||
Hello World [twirp](https://github.com/twitchtv/twirp) project.
|
29
cmd/hwtc/main.go
Normal file
29
cmd/hwtc/main.go
Normal file
@ -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)
|
||||
}
|
16
cmd/hwtd/main.go
Normal file
16
cmd/hwtd/main.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
12
hwt.go
Normal file
12
hwt.go
Normal file
@ -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
|
||||
}
|
17
service.proto
Normal file
17
service.proto
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user