gpt4 book ai didi

go - Chaincode 未构建 - Go 程序错误 - 无法引用未导出的名称

转载 作者:IT王子 更新时间:2023-10-29 02:37:10 25 4
gpt4 key购买 nike

我在 Ubuntu 机器上构建我的 go 代码时遇到错误。我检查了 GOPATH 变量,一切似乎都很好。下面是我得到的错误堆栈跟踪:

/go/src/Chaincodeexample$ 去构建 # _/home/ubuntu/go/src/链码示例

./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 values
type testuser struct{
Username string `json:"username"`
Fileuploaded string `json:"fileuploaded"`
}

//A function to create a user on the ledger

func 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
}

func (t *testuser) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
return nil, nil


}

func (t *testuser) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
if function == "Checkuploadstatus" {
return Checkuploadstatus(stub, args)
}
return nil, nil
}



func (t *testuser) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
if function == "CreateUser" {
return CreateUser(stub, args)
} else {
return nil, errors.New(username + " does not have access to create a User")
}

}
return nil, nil
}

给我解决这个问题的想法。

最佳答案

仅在 Go 中,您只能访问以大写字母开头的其他包中的名称。这有点像在 Java 或 C++ 中使用 publicprivate

调用您的类型 Logger 而不是 logger 它将起作用。

关于go - Chaincode 未构建 - Go 程序错误 - 无法引用未导出的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51642410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com