2020-08-21 15:01:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-08-22 11:03:45 +00:00
|
|
|
"fmt"
|
2020-08-21 15:01:59 +00:00
|
|
|
"net"
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
func initGRPC(c *cfg) {
|
|
|
|
var err error
|
2020-08-21 15:01:59 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
c.cfgGRPC.listener, err = net.Listen("tcp", c.cfgGRPC.endpoint)
|
|
|
|
fatalOnErr(err)
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
c.cfgGRPC.server = grpc.NewServer()
|
|
|
|
}
|
2020-08-22 11:03:45 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
func serveGRPC(c *cfg) {
|
2020-08-22 11:03:45 +00:00
|
|
|
go func() {
|
|
|
|
c.wg.Add(1)
|
|
|
|
defer func() {
|
|
|
|
c.wg.Done()
|
|
|
|
}()
|
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
if err := c.cfgGRPC.server.Serve(c.cfgGRPC.listener); err != nil {
|
2020-08-22 11:03:45 +00:00
|
|
|
fmt.Println("gRPC server error", err)
|
|
|
|
}
|
|
|
|
}()
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|