我正在编写一个用Postgres方言与Cloud Spanner对话的程序.我的应用程序是一台GIN服务器,并且我正在使用pgAdapter进行连接,如this doc中所述.
My application runs fine locally. But when I deploy it to cloud run, I get the following log.
误差主要来自StartPGAdapterWithCredentials
函数.
func StartPGAdapter(ctx context.Context, project, instance string) (port int, cleanup func(), err error) {
credentials, err := google.FindDefaultCredentials(ctx)
fmt.Println("credentials " + (credentials.ProjectID) + "json " + utils.ToString(credentials.JSON) + "ts " + utils.ToString(credentials.TokenSource))
if err != nil {
return 0, func() {}, err
}
return StartPGAdapterWithCredentials(ctx, project, instance, credentials)
}
func StartPGAdapterWithCredentials(ctx context.Context, project, instance string, credentials *google.Credentials) (port int, cleanup func(), err error) {
if credentials == nil {
return 0, func() {}, fmt.Errorf("credentials cannot be nil")
}
if credentials.JSON == nil || len(credentials.JSON) == 0 {
return 0, func() {}, fmt.Errorf("only JSON based credentials are supported")
}
credentialsFile, err := os.CreateTemp(os.TempDir(), "pgadapter-credentials")
if err != nil {
return 0, func() {}, err
}
在我的本地系统上,设置了GOOGLE_APPLICATION_CREDENTIALS
,因此它能够获得凭据.然而,这在云运行中是行不通的.
我如何让它在云运行中运行?
附加信息:按照示例呈现here.