Drop direct connection and uses consul

This commit is contained in:
2024-06-19 23:25:40 +08:00
parent 5a3c6fcada
commit d9aa478d10
9 changed files with 78 additions and 59 deletions

View File

@ -1,21 +0,0 @@
package grpc
import (
pcpb "git.solsynth.dev/hydrogen/paperclip/pkg/grpc/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var Attachments pcpb.AttachmentsClient
func ConnectPaperclip() error {
addr := viper.GetString("paperclip.grpc_endpoint")
if conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil {
return err
} else {
Attachments = pcpb.NewAttachmentsClient(conn)
}
return nil
}

View File

@ -34,10 +34,10 @@ func NewGRPC() {
}
func ListenGRPC() error {
listen, err := net.Listen("tcp", viper.GetString("grpc_bind"))
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err
}
return S.Serve(listen)
return S.Serve(listener)
}