Here is my code. I extract my struct OperatInfo to the struct.go and wanna to use this struct in the main package which in worker.go.
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
}
I just can't set operatInfo fields.
Any suggestions or tips will helps. Thanks.
Only the fields that starts with an upper case letter are public visible.
To solve your problem you can create getter and setter for each field or rename your fields' struct as follow:
type OperatInfo struct {
EventId string
HallId string
UserId string
Operating string
OperatingID string
Ip string
}