How would you declare a global for a datastore client?
So far, I have:
var (
db driver.Conn
ctx context.Context
client datastore.Client
)
ignore the db. That's for my global db conn.
func bootstrap() {
ctx = context.Background()
pId := ProjectId
var err error
client, err = datastore.NewClient(ctx, pId)
if err != nil {
fmt.Printf("caught error:%v
", err)
}
}
My error is: cannot assign *"cloud.google.com/go/datastore".Client to client (type "cloud.google.com/go/datastore".Client) in multiple assignment
Change client datastore.Client
to client *datastore.Client
.
Your error message says it all:
cannot assign *"cloud.google.com/go/datastore".Client to client (type "cloud.google.com/go/datastore".Client) in multiple assignment
Condensing it a bit...
cannot assign *ds.Client to client (type ds.Client)...
pointer ━━━━┷━━━━━━━━┙ │ │
plain type ━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━┙
Note that the first type is a pointer, denoted by the *
character and the second type is a plain type (with no asterisk).