Go 为从其他包声明的结构赋值
这是我的密码。 我将struct OperatInfo提取到struct.go,并希望在worker.go中的主包中使用此结构 结构goGo 为从其他包声明的结构赋值,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
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
}