hwt/hwt.go

31 lines
523 B
Go
Raw Normal View History

2018-01-16 20:57:04 -08:00
package hwt
import (
"context"
fmt "fmt"
"github.com/twitchtv/twirp"
pb "mcquay.me/hwt/rpc/hwt"
2018-01-16 20:57:04 -08:00
)
2018-01-20 09:07:57 -08:00
type Server struct {
Hostname string
}
2018-01-16 20:57:04 -08:00
func (s *Server) Hello(ctx context.Context, req *pb.HelloReq) (*pb.HelloResp, error) {
if req.Subject == "" {
return nil, twirp.RequiredArgumentError("subject")
}
2018-01-20 09:07:57 -08:00
2018-01-21 20:18:28 -08:00
u, err := getUser(ctx)
if err != nil {
return nil, twirp.InternalErrorWith(err)
}
2018-01-20 09:07:57 -08:00
r := &pb.HelloResp{
2018-01-21 20:18:28 -08:00
Text: fmt.Sprintf("%s said: %v", u, req.Subject),
2018-01-20 09:07:57 -08:00
Hostname: s.Hostname,
}
return r, nil
2018-01-16 20:57:04 -08:00
}