-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (29 loc) · 970 Bytes
/
main.go
File metadata and controls
36 lines (29 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"context"
"fmt"
"net/http"
v1 "github.com/jonbodner-buf/test-server/gen/greet/v1"
"github.com/jonbodner-buf/test-server/gen/greet/v1/greetv1connect"
)
func main() {
path, handler := greetv1connect.NewGreetServiceHandler(&GreetServiceHandler{})
mux := http.NewServeMux()
mux.Handle(path, handler)
h := &http.Server{
Addr: ":8080",
Handler: mux,
}
fmt.Println(
"serving",
path,
)
h.ListenAndServe()
}
type GreetServiceHandler struct{}
func (*GreetServiceHandler) GreetPerson(ctx context.Context, req *v1.GreetPersonRequest) (*v1.GreetPersonResponse, error) {
return &v1.GreetPersonResponse{Message: fmt.Sprintf("Hello, %s, you are %d!", req.Person.Name, req.Person.Age)}, nil
}
func (*GreetServiceHandler) GreetPet(ctx context.Context, req *v1.GreetPetRequest) (*v1.GreetPetResponse, error) {
return &v1.GreetPetResponse{Message: fmt.Sprintf("Hello, %s, I'd like to pet %s!", req.Person.Name, req.Person.Pet)}, nil
}