简体   繁体   English

Firestore gRPC API Golang 中的示例用法

[英]Firestore gRPC API Sample Usage in Golang

New to firestore and gRPC in general.一般而言,Firestore 和 gRPC 是新手。 I've been trying to figure out how to interact with the Firestore RPC API from golang.我一直在尝试弄清楚如何与来自 golang 的 Firestore RPC API 进行交互。 They document the API well here , but do not show how to initialize the connections.他们在这里很好地记录了 API,但没有显示如何初始化连接。 Some questions I have are,我有一些问题,

  1. From golang, would I use the grpc package or the builtin rpc.在 golang 中,我会使用 grpc package 还是内置的 rpc。
  2. What URL would I use to connect to the API.我将使用什么 URL 连接到 API。
  3. When connnecting to a cloud based RPC API like this, do I need to have the.proto files locally to be able to interact with it?当像这样连接到基于云的 RPC API 时,我是否需要在本地拥有 .proto 文件才能与之交互?
  4. How to authenticate with a users firebase ID token.如何使用用户 firebase ID 令牌进行身份验证。
  5. How to create a record authenticated as said user.如何创建以所述用户身份验证的记录。

Cheers.干杯。

Edit: I have been able to connect thanks to Anar.编辑:多亏了 Anar,我才能够连接上。 But I can't test anything because Im not really sure how to authenticate or create a record.但我无法测试任何东西,因为我不确定如何验证或创建记录。 Any help with an example would be great.任何有关示例的帮助都会很棒。 Code so far:到目前为止的代码:

conn, err := grpc.Dial("firestore.googleapis.com", grpc.WithInsecure())
if err != nil {
    log.Fatalln(err)
}
defer conn.Close()
  1. You must use google.golang.org/grpc package你必须使用 google.golang.org/grpc package

  2. As documentation you must use firestore.googleapis.com to create client stub.作为文档,您必须使用firestore.googleapis.com来创建客户端存根。

在此处输入图像描述

3.You don't need it proto file locally. 3.本地不需要proto文件。 you can just create grpc client and use server methods which available here: https://cloud.google.com/firestore/docs/reference/rpc您可以只创建 grpc 客户端并使用此处提供的服务器方法: https://cloud.google.com/firestore/docs/reference/rpc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM