65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"schain/common/signer"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// GetClientConf 获取客户端的信息配置
|
|
func KGCClientConf() (*signer.Config, error) {
|
|
viper.SetDefault("client.MSPID", "*.wxy.com")
|
|
viper.SetDefault("client.ClientPubPath", "cert/client_pubkey.txt")
|
|
viper.SetDefault("client.ClientPriPath", "cert/client_prikey.txt")
|
|
|
|
viper.AddConfigPath(configFilePath)
|
|
viper.SetConfigName("config")
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return &signer.Config{
|
|
MSPID: viper.GetString("client.MSPID"),
|
|
IdentityPath: ProjectPath + viper.GetString("client.ClientPubPath"),
|
|
KeyPath: ProjectPath + viper.GetString("client.ClientPriPath"),
|
|
}, nil
|
|
}
|
|
|
|
// GetPeerConf 获取Peer节点的信息配置
|
|
func KGCPeerConf() (*signer.Config, error) {
|
|
viper.SetDefault("peer.MSPID", "*.wxy.com")
|
|
viper.SetDefault("peer.PeerPubPath", "cert/peer_pubkey.txt")
|
|
viper.SetDefault("peer.PeerPriPath", "cert/peer_prikey.txt")
|
|
|
|
viper.AddConfigPath(configFilePath)
|
|
viper.SetConfigName("config")
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &signer.Config{
|
|
MSPID: viper.GetString("peer.MSPID"),
|
|
IdentityPath: ProjectPath + viper.GetString("peer.PeerPubPath"),
|
|
KeyPath: ProjectPath + viper.GetString("peer.PeerPriPath"),
|
|
}, nil
|
|
}
|
|
|
|
// GetOrderConf 获取Order节点的配置信息
|
|
func KGCOrderConf() (*signer.Config, error) {
|
|
viper.SetDefault("order.MSPID", "*.wxy.com")
|
|
viper.SetDefault("order.OrderPubPath", "cert/order_pubkey.txt")
|
|
viper.SetDefault("order.OrderPriPath", "cert/order_prikey.txt")
|
|
|
|
viper.AddConfigPath(configFilePath)
|
|
viper.SetConfigName("config")
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &signer.Config{
|
|
MSPID: viper.GetString("order.MSPID"),
|
|
IdentityPath: ProjectPath + viper.GetString("order.OrderPubPath"),
|
|
KeyPath: ProjectPath + viper.GetString("order.OrderPriPath"),
|
|
}, nil
|
|
}
|