Created
November 1, 2019 10:55
-
-
Save Cartmanishere/b4d6bfb8ed104b7757ba6745248ab268 to your computer and use it in GitHub Desktop.
Golang client for grpc-python-golang-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"google.golang.org/grpc" | |
"fmt" | |
"bufio" | |
"os" | |
nltk "golang/nltk_service" | |
) | |
type GrpcClient struct { | |
conn *grpc.ClientConn | |
client nltk.KeywordServiceClient | |
} | |
const SERVER_ADDR = "127.0.0.1:6000" | |
func InitGrpcConnection() (*GrpcClient, error) { | |
conn, err := grpc.Dial(SERVER_ADDR, grpc.WithInsecure()) | |
if err != nil { | |
return nil, err | |
} | |
client := nltk.NewKeywordServiceClient(conn) | |
return &GrpcClient{conn, client}, nil | |
} | |
func (g *GrpcClient) MyKeywords(text string) ([]string, error) { | |
req := nltk.Request{ | |
Text: text, | |
} | |
res, err := g.client.GetKeywords(context.Background(), &req) | |
if err != nil { | |
return nil, err | |
} | |
return res.Keywords, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment