(2)调用客户端
package main import ( "github.com/astaxie/beego" "github.com/astaxie/beego/logs" _ "github.com/lib/pq" "jingjinjiapi/controllers" _ "jingjinjiapi/routers" "jingjinjiapi/sdkInit" "os" ) const ( //config of SDK configFile = "config.yaml" //mark whehter the client is initialized initialized = false //the chaincode id EduCC = "educc" DOC_TYPE = "insObj" ) func main() { //setting loggers level and location logs.SetLogger("file", `{"filename":"logs/jingjinji_beego.log"}`) logs.SetLevel(logs.LevelInformational) logs.Info("setting logs level : information") //initialized the information of sdk initInfo := &sdkInit.InitInfo{ ChannelID: "institutionchannel", ChannelConfig: os.Getenv("GOPATH") + "/src/jingjinjiapi/fixtures/artifacts/channel.tx", OrgAdmin: "Admin", OrgName: "Org1", OrdererOrgName: "orderer.institution.com", ChaincodeID: EduCC, ChaincodeGoPath: os.Getenv("GOPATH"), ChaincodePath: "jingjinjiapi/chaincode/", UserName: "User1", } var serviceSetup controllers.ServiceSetup //initialize SDK,use the function:fabsdk.new sdk, err := sdkInit.SetupSDK(configFile, initialized) if err != nil { logs.Error(err.Error()) return } //free the resource until the main program finish defer sdk.Close() flag := false if flag{ //create channel and add the peer node to the channel err = sdkInit.CreateChannel(sdk, initInfo) if err != nil { logs.Error(err.Error()) return } //install chaincode and instantiate chaincode channelClient, err := sdkInit.InstallAndInstantiateCC(sdk, initInfo) if err != nil { logs.Error(err.Error()) return } serviceSetup.ChaincodeID = EduCC serviceSetup.Client = channelClient }else{ channelClient, err := sdkInit.ChannelClient(sdk,initInfo) if err != nil { logs.Error(err.Error()) return } serviceSetup.ChaincodeID = EduCC serviceSetup.Client = channelClient } logs.Informational(serviceSetup) //===========================================http://www.likecs.com// //start Testing ............................................. //start service beego.Router("/v1/institution", &controllers.InstitutionController{Setup: &serviceSetup}) }Hyperledger fabric-SDK-GO客户端开发篇(六) (5)
内容版权声明:除非注明,否则皆为本站原创文章。