在Ubuntu机器上构建go代码时遇到错误。我检查了GOPATH变量,一切似乎都很好。下面是我得到的错误的堆栈跟踪:/ go / src / Chaincodeexample $ go build#_ / home / ubuntu / go / src / Chaincodeexample./Samplesupplychain.go:13:14: cannot refer to unexported name shim.logger./Samplesupplychain.go:91:5: syntax error: non-declaration statement outside function body下面是我的代码:import("errors""fmt""encoding/json""github.com/hyperledger/fabric/core/chaincode/shim")var logger = shim.logger("my logger")//Create a struct for these 2 valuestype testuser struct{ Username string `json:"username"` Fileuploaded string `json:"fileuploaded"`}//A function to create a user on the ledgerfunc CreateUser(stub shim.ChaincodeStubInterface, args []string) ([]byte, error){ if len(args) < 2 { logger.Error("Invalid number of args") return nil, errors.New("Expected atleast 1 argument for user creation") } var Username = args[0] var UsernameInput = args[1] //trying to understand err := stub.PutState(Username, []byte(UsernameInput)) if err != nil { logger.Error("Could not save new User to ledger", err) return nil, err } var customEvent = "{eventType: 'UserCreation', description:" + Username + "' Successfully created'}" err = stub.SetEvent("evtSender", []byte(customEvent)) if err != nil { return nil, err } logger.Info("Successfully saved a supply chain user") return nil, nil}func Checkuploadstatus(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { logger.Debug("Entering supply-chain application") if len(args) < 1 { logger.Error("Invalid number of arguments") return nil, errors.New("Missing details") } var Fileuploadedstatus = args[0] bytes, err := stub.GetState(Fileuploadedstatus) if err != nil { logger.Error("Could not fetch Fileuploadedstatus with "+ Fileuploadedstatus +" from ledger", err) return nil, err } return bytes, nil}给我想法解决这个问题。
1 回答
杨魅力
TA贡献1811条经验 获得超6个赞
在Go中,只有其他包中的名称以大写字母开头时,您才可以访问它们。这有点像在Java或C ++中使用public
和private
。
呼叫您的类型Logger
而不是logger
它,它将起作用。
- 1 回答
- 0 关注
- 225 浏览
添加回答
举报
0/150
提交
取消