Skip to content

Instantly share code, notes, and snippets.

@Cartmanishere
Created November 1, 2019 10:55
Show Gist options
  • Save Cartmanishere/b4d6bfb8ed104b7757ba6745248ab268 to your computer and use it in GitHub Desktop.
Save Cartmanishere/b4d6bfb8ed104b7757ba6745248ab268 to your computer and use it in GitHub Desktop.
Golang client for grpc-python-golang-example
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