# README
Cryptomood b2b client - golang
Client example
-
When connecting to the server use x509 cert.pem file located in certs directory. You won't be able to access the server without it
-
Make sure you have at least the latest stable version of Golang
-
(optional) install protoc tool and protoc-gen-go
-
(optional) transpile proto file to
*.go
file withprotoc -I .. -I $GOPATH/src --go_out=plugins=grpc:./ ../types.proto
This will generate transpiled file into current directory. To adhere golang conventions and also to make these examples work, compiler should be able to find this file. Otherwise put it into your GOPATH directory ($GOPATH/src/types
) and then just import it likeimport types
.Steps 3-4 are optional, because this directory already contains prepared
types.pb.go
file -
Load credentials
creds, err := credentials.NewClientTLSFromFile(CertFile, "")
-
Dial the server. You must provide your api token (to obtain it visit our website) to authorize your requests
conn, err := grpc.Dial(Server, grpc.WithTransportCredentials(creds), grpc.WithPerRPCCredentials(tokenAuth{Token}), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
-
Initialize required service and call required method (in this case subscription)
proxyClient := types.NewMessagesProxyClient(conn) sub, err := proxyClient.SubscribeTweet(context.Background(), &empty.Empty{})
-
Read data indefinitely
for { msg, err := sub.Recv() if err == io.EOF { continue } if sub.Context().Err() != nil { _ = sub.CloseSend() fmt.Println("Closing connection to server") break } fmt.Println(msg.Base.Content, err) }
For full example, see any example directory.