dongtan3395 2018-08-01 21:20
浏览 73
已采纳

链码未生成-Go程序错误-无法引用未导出的名称

I am getting an error while building my go code on an Ubuntu machine. I have check GOPATH variables and everything seems fine. Below is stack trace of error I am getting:

/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

Below is my code :

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
}

Give me idea to resolve this.

  • 写回答

1条回答 默认 最新

  • donglu8334 2018-08-02 09:29
    关注

    In Go only you can only access names in other packages if they start with an upper-case letter. This is kind of like using public and private in Java or C++.

    Call your type Logger instead of logger and it will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同