Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 为从其他包声明的结构赋值_Go - Fatal编程技术网

Go 为从其他包声明的结构赋值

Go 为从其他包声明的结构赋值,go,Go,这是我的密码。 我将struct OperatInfo提取到struct.go,并希望在worker.go中的主包中使用此结构 结构go package batch type OperatInfo struct { eventId string hallId string userId string operating string operatingID string ip string } 工人,加油 package main impor

这是我的密码。 我将struct OperatInfo提取到struct.go,并希望在worker.go中的主包中使用此结构

结构go

package batch

type OperatInfo struct {
    eventId string
    hallId string
    userId string
    operating string
    operatingID string
    ip string
}
工人,加油

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
}
我就是不能设置operatInfo字段


任何建议或提示都会有所帮助。谢谢。

只有以大写字母开头的字段才是公共可见的。
要解决您的问题,您可以为每个字段创建getter和setter,或按如下方式重命名字段的结构:

type OperatInfo struct {
    EventId string
    HallId string
    UserId string
    Operating string
    OperatingID string
    Ip string
}