-
Notifications
You must be signed in to change notification settings - Fork 1
/
reverb.go
54 lines (45 loc) · 934 Bytes
/
reverb.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
53
54
// Package reverb - name is cheekily synonymized from the HTTPD package
// "Echo" and aims to serve a minimally similar purpose, though for gRPC
// instead of HTTP.
package reverb
import (
"log"
"net"
"google.golang.org/grpc"
)
// Reverb ...
type Reverb struct {
TCPListener net.Listener
GRPCServer *grpc.Server
}
// New ...
func New() *Reverb {
grpcServer := grpc.NewServer()
return &Reverb{
GRPCServer: grpcServer,
}
}
// Start ...
func (r *Reverb) Start(opts string) *Reverb {
server := New()
tcpListener, err := net.Listen("tcp", opts)
if err != nil {
log.Fatalf("Reverb gRPC server failed to listen: %v", err)
}
server.TCPListener = tcpListener
server.Register()
return server
}
// Register ...
func (r *Reverb) Register() {
}
// Serve ...
func (r *Reverb) Serve() {
r.GRPCServer.Serve(r.TCPListener)
}
// Close ...
func (r *Reverb) Close() {
if r.TCPListener != nil {
r.TCPListener.Close()
}
}