-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
45 lines (34 loc) · 989 Bytes
/
server.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
package main
// This file contains the base gRPC server implementation
// You probably don't need to change this
import (
"fmt"
"log"
"net"
plugin "github.com/pact-foundation/pact-plugin-template-golang/io_pact_plugin"
"google.golang.org/grpc"
)
type serverDetails struct {
Port int
ServerKey string
}
func startPluginServer(details serverDetails) {
log.Println("starting server on port", details.Port)
lis, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", details.Port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
// Required JSON structure for plugin framework to
fmt.Printf(`{"port": %d, "serverKey": "%s"}%s`, details.Port, details.ServerKey, "\n")
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
plugin.RegisterPactPluginServer(grpcServer, newServer())
grpcServer.Serve(lis)
}
func newServer() *pluginServer {
s := &pluginServer{}
return s
}
type pluginServer struct {
plugin.UnimplementedPactPluginServer
}