2017-11-20 4 views
-1

데이터 스토어 클라이언트에 대해 전역을 어떻게 선언 하시겠습니까?Google 데이터 스토어 글로벌 연결

지금까지 내가 가진 :

var (
    db  driver.Conn 
    ctx context.Context 
    client datastore.Client 
) 

이 DB를 무시합니다. 내 글로벌 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\n", err) 
    } 

} 

내 오류는 다음과 같습니다 은 다중 할당

에서 클라이언트 (유형 "cloud.google.com/go/datastore".Client)에 *"cloud.google.com/go/datastore ".Client을 할당 할 수 없습니다
+0

https://godoc.org/cloud.google.com/go/datastore#NewClient는 '* 클라이언트'와 '오류'를 반환합니다. – RayfenWindspear

+1

또한 전역 컨텍스트가 없어야합니다. 그건 말이 안되요. – RayfenWindspear

답변

3

client datastore.Client에서 client *datastore.Client으로 변경하십시오.

귀하의 오류 메시지가 모두 그것을 말한다 : ...

cannot assign *"cloud.google.com/go/datastore".Client to client (type "cloud.google.com/go/datastore".Client) in multiple assignment 

그것을 조금 응축 첫 번째 유형은 * 문자와 두 번째 유형으로 표시 포인터이라고

cannot assign *ds.Client to client (type ds.Client)... 
    pointer ━━━━┷━━━━━━━━┙     │  │ 
    plain type ━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━┙ 

주 일반 형식 (별표 없음)입니다.