@ -98,14 +98,18 @@ var shardConfigs []ConfigType
var defaultConfig ConfigType
var defaultConfig ConfigType
var onceForConfigs sync . Once
var onceForConfigs sync . Once
// GetShardConfig return the shard's ConfigType variable
func ensureShardConfigs ( ) {
func GetShardConfig ( shardID uint32 ) * ConfigType {
onceForConfigs . Do ( func ( ) {
onceForConfigs . Do ( func ( ) {
shardConfigs = make ( [ ] ConfigType , MaxShards )
shardConfigs = make ( [ ] ConfigType , MaxShards )
for i := range shardConfigs {
for i := range shardConfigs {
shardConfigs [ i ] . ShardID = uint32 ( i )
shardConfigs [ i ] . ShardID = uint32 ( i )
}
}
} )
} )
}
// GetShardConfig return the shard's ConfigType variable
func GetShardConfig ( shardID uint32 ) * ConfigType {
ensureShardConfigs ( )
if int ( shardID ) >= cap ( shardConfigs ) {
if int ( shardID ) >= cap ( shardConfigs ) {
return nil
return nil
}
}
@ -213,6 +217,7 @@ func (conf *ConfigType) Role() Role {
// SetNetworkType set the networkType
// SetNetworkType set the networkType
func SetNetworkType ( networkType NetworkType ) {
func SetNetworkType ( networkType NetworkType ) {
ensureShardConfigs ( )
defaultConfig . networkType = networkType
defaultConfig . networkType = networkType
for i := range shardConfigs {
for i := range shardConfigs {
shardConfigs [ i ] . networkType = networkType
shardConfigs [ i ] . networkType = networkType