當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ctypes.ConfigValue類代碼示例

本文整理匯總了Golang中github.com/intelsdi-x/snap/core/ctypes.ConfigValue的典型用法代碼示例。如果您正苦於以下問題:Golang ConfigValue類的具體用法?Golang ConfigValue怎麽用?Golang ConfigValue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ConfigValue類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Validate

// Validate validates a config value against this rule.
func (b *BoolRule) Validate(cv ctypes.ConfigValue) error {
	// Check that type is correct
	if cv.Type() != "bool" {
		return wrongType(b.key, cv.Type(), "bool")
	}
	return nil
}
開發者ID:lynxbat,項目名稱:snap,代碼行數:8,代碼來源:bool.go

示例2: getConfigItemValue

// getConfigItemValue returns value of configuration item
func getConfigItemValue(item ctypes.ConfigValue) (interface{}, error) {

	var value interface{}

	switch item.Type() {
	case "string":
		value = item.(ctypes.ConfigValueStr).Value
		break

	case "float":
		value = item.(ctypes.ConfigValueFloat).Value
		break

	case "integer":
		value = item.(ctypes.ConfigValueInt).Value
		break

	case "bool":
		value = item.(ctypes.ConfigValueBool).Value
		break

	default:
		return nil, fmt.Errorf("Unsupported type of configuration item, type=%v", item.Type())
	}

	return value, nil
}
開發者ID:intelsdi-x,項目名稱:snap-plugin-utilities,代碼行數:28,代碼來源:config.go

示例3: Validate

// Validates a config value against this rule.
func (s *StringRule) Validate(cv ctypes.ConfigValue) error {
	// Check that type is correct
	if cv.Type() != "string" {
		return wrongType(s.key, cv.Type(), "string")
	}
	return nil
}
開發者ID:lynxbat,項目名稱:snap,代碼行數:8,代碼來源:string.go

示例4: Validate

// Validate Validates a config value against this rule.
func (f *FloatRule) Validate(cv ctypes.ConfigValue) error {
	// Check that type is correct
	if cv.Type() != FloatType {
		return wrongType(f.key, cv.Type(), FloatType)
	}
	// Check minimum. Type should be safe now because of the check above.
	if f.minimum != nil && cv.(ctypes.ConfigValueFloat).Value < *f.minimum {
		return errors.New(fmt.Sprintf("value is under minimum (%s value %f < %f)", f.key, cv.(ctypes.ConfigValueFloat).Value, *f.minimum))
	}
	// Check maximum. Type should be safe now because of the check above.
	if f.maximum != nil && cv.(ctypes.ConfigValueFloat).Value > *f.maximum {
		return errors.New(fmt.Sprintf("value is over maximum (%s value %f > %f)", f.key, cv.(ctypes.ConfigValueFloat).Value, *f.maximum))
	}
	return nil
}
開發者ID:Collinux,項目名稱:snap,代碼行數:16,代碼來源:float.go

示例5: Validate

// Validate Validates a config value against this rule.
func (i *IntRule) Validate(cv ctypes.ConfigValue) error {
	// Check that type is correct
	// when unmarshalling JSON numbers are converted to floats which is the reason
	// we are checking for integer below.
	// http://golang.org/pkg/encoding/json/#Marshal
	if cv.Type() != "integer" && cv.Type() != "float" {
		return wrongType(i.key, cv.Type(), "integer")
	}
	// Check minimum. Type should be safe now because of the check above.
	if i.minimum != nil && cv.(ctypes.ConfigValueInt).Value < *i.minimum {
		return errors.New(fmt.Sprintf("value is under minimum (%s value %d < %d)", i.key, cv.(ctypes.ConfigValueInt).Value, *i.minimum))
	}
	// Check maximum. Type should be safe now because of the check above.
	if i.maximum != nil && cv.(ctypes.ConfigValueInt).Value > *i.maximum {
		return errors.New(fmt.Sprintf("value is over maximum (%s value %d > %d)", i.key, cv.(ctypes.ConfigValueInt).Value, *i.maximum))
	}
	return nil
}
開發者ID:jeffweiss,項目名稱:snap,代碼行數:19,代碼來源:integer.go


注:本文中的github.com/intelsdi-x/snap/core/ctypes.ConfigValue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。