-
Notifications
You must be signed in to change notification settings - Fork 2
/
hook.go
52 lines (38 loc) · 1.33 KB
/
hook.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package main
import (
"context"
"log"
"net"
"github.com/PKUHPC/scow-go-demo/gen/go/hook"
"google.golang.org/grpc"
"google.golang.org/protobuf/encoding/protojson"
)
type MyHookServer struct{}
func (s *MyHookServer) OnEvent(ctx context.Context, req *hook.OnEventRequest) (*hook.OnEventResponse, error) {
log.Printf("Received event: %+v", protojson.Format(req))
return &hook.OnEventResponse{}, nil
}
func StartHookServer() {
addr := "0.0.0.0:5000"
lis, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
server := MyHookServer{}
hook.RegisterHookServiceServer(grpcServer, &server)
log.Printf("Listening at %s", addr)
grpcServer.Serve(lis)
}