代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package pluggable
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/spf13/viper"
)
const (
EndorsementPluginEnvVar = "ENDORSEMENT_PLUGIN_ENV_VAR"
ValidationPluginEnvVar = "VALIDATION_PLUGIN_ENV_VAR"
)
// EndorsementPluginActivationFolder returns the name of the folder that if
// the file of the peer's id in it exists - it indicates that the endorsement plugin was activated
// for that peer
func EndorsementPluginActivationFolder() string {
return os.Getenv(EndorsementPluginEnvVar)
}
// SetEndorsementPluginActivationFolder sets the name of the folder
// that if the file of the peer's id in it exists - it indicates that the endorsement plugin was activated
// for that peer
func SetEndorsementPluginActivationFolder(path string) {
os.Setenv(EndorsementPluginEnvVar, path)
}
// ValidationPluginActivationFilePath returns the name of the folder that if
// the file of the peer's id in it exists - it indicates that the validation plugin was activated
// for that peer
func ValidationPluginActivationFolder() string {
return os.Getenv(ValidationPluginEnvVar)
}
// SetValidationPluginActivationFolder sets the name of the folder
// that if the file of the peer's id in it exists - it indicates that the validation plugin was activated
// for that peer
func SetValidationPluginActivationFolder(path string) {
os.Setenv(ValidationPluginEnvVar, path)
}
func markPluginActivation(dir string) {
fileName := filepath.Join(dir, viper.GetString("peer.id"))
_, err := os.Create(fileName)
if err != nil {
panic(fmt.Sprintf("failed to create file %s: %v", fileName, err))
}
}
// PublishEndorsementPluginActivation makes it known that the endorsement plugin
// was activated for the peer that is invoking this function
func PublishEndorsementPluginActivation() {
markPluginActivation(EndorsementPluginActivationFolder())
}
// PublishValidationPluginActivation makes it known that the validation plugin
// was activated for the peer that is invoking this function
func PublishValidationPluginActivation() {
markPluginActivation(ValidationPluginActivationFolder())
}
// CountEndorsementPluginActivations returns the number of peers that activated
// the endorsement plugin
func CountEndorsementPluginActivations() int {
return listDir(EndorsementPluginActivationFolder())
}
// CountValidationPluginActivations returns the number of peers that activated
// the validation plugin
func CountValidationPluginActivations() int {
return listDir(ValidationPluginActivationFolder())
}
func listDir(d string) int {
dir, err := ioutil.ReadDir(d)
if err != nil {
panic(fmt.Sprintf("failed listing directory %s: %v", d, err))
}
return len(dir)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。