2017-08-10 14 views
-2

これは私のコードです。 私は構造体OperatInfoをstruct.goに抽出し、この構造体をworker.goのメインパッケージで使用したいと考えています。私はちょうどフィールドoperatInfo設定することはできません他のパッケージから宣言された構造体に値を代入する

struct.go

package batch 

type OperatInfo struct { 
    eventId string 
    hallId string 
    userId string 
    operating string 
    operatingID string 
    ip string 
} 

worker.go

package main 

import (
    "time" 
    "fmt" 
    "strconv" 
    "./kernel/api" 
    "./kernel/db" 
    "./batch/basic" 
    "./batch/struct" 
) 

var operatInfo batch.OperatInfo 

func BatchDeposit(eventId string, userId string, hallId string, operating string, operatingID string, ip string) { 
    // I get an error here 
    operatInfo.eventId = eventId 
    operatInfo.hallId = hallId 
    operatInfo.userId = userId 
    operatInfo.operating = operating 
    operatInfo.operatingID = operatingID 
    operatInfo.ip = ip 
} 

提案やヒントが役立ちます。ありがとう。

答えて

1

大文字で始まるフィールドのみが公開されます。
問題を解決するには、フィールドごとにgetterとsetterを作成するか、フィールドの構造体の名前を次のように変更します。

type OperatInfo struct { 
    EventId string 
    HallId string 
    UserId string 
    Operating string 
    OperatingID string 
    Ip string 
} 
関連する問題