# resmgmt

By [olpsda](https://paragraph.com/@olpsda) · 2021-11-24

---

1、resmgmt简介 resmgmt支持在Fabric网络上创建和更新资源。resmgmt允许管理员创建、更新通道，并允许Peer节点加入通道。管理员还可以在Peer节点上执行与链码相关的操作，例如安装，实例化和升级链码。 官方文档：  [https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt](https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt)

2、resmgmt使用流程 resmgmt使用基本流程如下： A、准备客户端上下文 B、创建资源管理客户端 C、创建新通道 D、将Peer节点加入通道 E、将链码安装到Peer节点的文件系统 F、在通道上实例化链码 G、查询通道上的Peer节点，已安装/实例化的链码等 使用示例：

登录后复制 // Create new resource management client c, err := New(mockClientProvider()) if err != nil { fmt.Println("failed to create client") }

// Read channel configuration r, err := os.Open(channelConfig) if err != nil { fmt.Printf("failed to open channel config: %s\\n", err) } defer r.Close()

// Create new channel 'mychannel' \_, err = c.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: r}) if err != nil { fmt.Printf("failed to save channel: %s\\n", err) }

peer := mockPeer()

// Peer joins channel 'mychannel' err = c.JoinChannel("mychannel", WithTargets(peer)) if err != nil { fmt.Printf("failed to join channel: %s\\n", err) }

// Install example chaincode to peer installReq := InstallCCRequest{Name: "ExampleCC", Version: "v0", Path: "path", Package: &resource.CCPackage{Type: 1, Code: \[\]byte("bytes")}} \_, err = c.InstallCC(installReq, WithTargets(peer)) if err != nil { fmt.Printf("failed to install chaincode: %s\\n", err) }

// Instantiate example chaincode on channel 'mychannel' ccPolicy := cauthdsl.SignedByMspMember("Org1MSP") instantiateReq := InstantiateCCRequest{Name: "ExampleCC", Version: "v0", Path: "path", Policy: ccPolicy} \_, err = c.InstantiateCC("mychannel", instantiateReq, WithTargets(peer)) if err != nil { fmt.Printf("failed to install chaincode: %s\\n", err) }

---

*Originally published on [olpsda](https://paragraph.com/@olpsda/resmgmt)*
