本文整理汇总了Golang中github.com/intelsdi-x/snap/control/plugin/cpolicy.NewIntegerRule函数的典型用法代码示例。如果您正苦于以下问题:Golang NewIntegerRule函数的具体用法?Golang NewIntegerRule怎么用?Golang NewIntegerRule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewIntegerRule函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetConfigPolicy
func (m *mockSessionStatePluginProxy) GetConfigPolicy(args []byte, reply *[]byte) error {
cp := cpolicy.New()
n1 := cpolicy.NewPolicyNode()
if m.c {
r1, _ := cpolicy.NewStringRule("name", false, "bob")
n1.Add(r1)
r2, _ := cpolicy.NewIntegerRule("someInt", true, 100)
n1.Add(r2)
r3, _ := cpolicy.NewStringRule("password", true)
n1.Add(r3)
r4, _ := cpolicy.NewFloatRule("somefloat", false, 3.14)
n1.Add(r4)
cp.Add([]string{"foo", "bar"}, n1)
} else {
r1, _ := cpolicy.NewIntegerRule("SomeRequiredInt", true, 1)
r2, _ := cpolicy.NewStringRule("password", true)
r3, _ := cpolicy.NewFloatRule("somefloat", false, 3.14)
n1.Add(r1, r2, r3)
cp.Add([]string{""}, n1)
}
cpr := plugin.GetConfigPolicyReply{Policy: cp}
var err error
*reply, err = m.e.Encode(cpr)
return err
}
示例2: GetConfigPolicy
func (f *HostedtsdbPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
c := cpolicy.New()
rule, _ := cpolicy.NewStringRule("raintank_tsdb_url", true)
rule2, _ := cpolicy.NewStringRule("raintank_api_key", true)
rule3, _ := cpolicy.NewIntegerRule("interval", true)
rule4, _ := cpolicy.NewIntegerRule("orgId", false, 0)
p := cpolicy.NewPolicyNode()
p.Add(rule)
p.Add(rule2)
p.Add(rule3)
p.Add(rule4)
c.Add([]string{""}, p)
return c, nil
}
示例3: GetConfigPolicy
func (f *influxPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
config := cpolicy.NewPolicyNode()
r1, err := cpolicy.NewStringRule("host", true)
handleErr(err)
r1.Description = "Influxdb host"
config.Add(r1)
r2, err := cpolicy.NewIntegerRule("port", true)
handleErr(err)
r2.Description = "Influxdb port"
config.Add(r2)
r3, err := cpolicy.NewStringRule("database", true)
handleErr(err)
r3.Description = "Influxdb db name"
config.Add(r3)
r4, err := cpolicy.NewStringRule("user", true)
handleErr(err)
r4.Description = "Influxdb user"
config.Add(r4)
r5, err := cpolicy.NewStringRule("password", true)
handleErr(err)
r5.Description = "Influxdb password"
config.Add(r4)
cp.Add([]string{""}, config)
return cp, nil
}
示例4: GetConfigPolicy
// GetConfigPolicy returns a config policy
func (s *PostgreSQLPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
config := cpolicy.NewPolicyNode()
username, err := cpolicy.NewStringRule("username", true)
handleErr(err)
username.Description = "Username to login to the PostgreSQL server"
password, err := cpolicy.NewStringRule("password", true)
handleErr(err)
password.Description = "Password to login to the PostgreSQL server"
database, err := cpolicy.NewStringRule("database", true)
handleErr(err)
database.Description = "The postgresql database that data will be pushed to"
tableName, err := cpolicy.NewStringRule("table_name", true)
handleErr(err)
tableName.Description = "The postgresql table within the database where information will be stored"
hostName, err := cpolicy.NewStringRule("hostname", true, "localhost")
handleErr(err)
tableName.Description = "The postgresql server ip or domain name"
port, err := cpolicy.NewIntegerRule("port", true, 5432)
handleErr(err)
port.Description = "The postgresql server port number"
config.Add(username, password, database, tableName, hostName, port)
cp.Add([]string{""}, config)
return cp, nil
}
示例5: GetConfigPolicy
func (p *movingAverageProcessor) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
config := cpolicy.NewPolicyNode()
r1, err := cpolicy.NewIntegerRule("MovingAvgBufLength", true)
handleErr(err)
r1.Description = "Buffer Length for moving average "
config.Add(r1)
cp.Add([]string{""}, config)
return cp, nil
}
示例6: GetConfigPolicy
func (f *influxPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
config := cpolicy.NewPolicyNode()
r1, err := cpolicy.NewStringRule("host", true)
handleErr(err)
r1.Description = "Influxdb host"
config.Add(r1)
r2, err := cpolicy.NewIntegerRule("port", true)
handleErr(err)
r2.Description = "Influxdb port"
config.Add(r2)
r3, err := cpolicy.NewStringRule("database", true)
handleErr(err)
r3.Description = "Influxdb db name"
config.Add(r3)
r4, err := cpolicy.NewStringRule("user", true)
handleErr(err)
r4.Description = "Influxdb user"
config.Add(r4)
r5, err := cpolicy.NewStringRule("password", true)
handleErr(err)
r5.Description = "Influxdb password"
config.Add(r5)
r6, err := cpolicy.NewStringRule("retention", false, "autogen")
handleErr(err)
r6.Description = "Influxdb retention policy"
config.Add(r6)
r7, err := cpolicy.NewBoolRule("https", false, false)
handleErr(err)
r7.Description = "Influxdb HTTPS connection"
config.Add(r7)
r8, err := cpolicy.NewBoolRule("skip-verify", false, false)
handleErr(err)
r8.Description = "Influxdb HTTPS Skip certificate verification"
config.Add(r8)
r9, err := cpolicy.NewStringRule("precision", false, "s")
handleErr(err)
r9.Description = "Influxdb timestamp precision"
config.Add(r9)
cp.Add([]string{""}, config)
return cp, nil
}
示例7: GetConfigPolicy
func (p *opentsdbPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
config := cpolicy.NewPolicyNode()
r1, err := cpolicy.NewStringRule("host", true)
handleErr(err)
r1.Description = "Opentsdb host"
config.Add(r1)
r2, err := cpolicy.NewIntegerRule("port", true)
handleErr(err)
r2.Description = "Opentsdb port"
config.Add(r2)
cp.Add([]string{""}, config)
return cp, nil
}
示例8: GetConfigPolicy
// GetConfigPolicy returns a config policy
func (p *Osv) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
config := cpolicy.NewPolicyNode()
swagIP, err := cpolicy.NewStringRule("swagIP", true)
handleErr(err)
swagIP.Description = "Osv ip address"
config.Add(swagIP)
swagPort, err := cpolicy.NewIntegerRule("swagPort", false, 8000)
handleErr(err)
swagPort.Description = "Swagger port / default 8000"
config.Add(swagPort)
cp.Add([]string{""}, config)
return cp, nil
}
示例9: GetConfigPolicy
func (p *mockPlugin) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
cpn := cpolicy.NewPolicyNode()
r1, _ := cpolicy.NewStringRule("username", false, "root")
r2, _ := cpolicy.NewStringRule("password", true)
r3, _ := cpolicy.NewBoolRule("bool_rule_default_true", false, true)
r4, _ := cpolicy.NewBoolRule("bool_rule_default_false", false, false)
r5, _ := cpolicy.NewIntegerRule("integer_rule", true, 1234)
r5.SetMaximum(9999)
r5.SetMinimum(1000)
r6, _ := cpolicy.NewFloatRule("float_rule", true, 0.1234)
r6.SetMaximum(.9999)
r6.SetMinimum(.001)
cpn.Add(r1, r2, r3, r4, r5, r6)
ns := []string{"one", "two", "potato"}
cp.Add(ns, cpn)
return cp, nil
}
示例10: GetConfigPolicy
// GetConfigPolicy returns the config of the Heka plugin
func (p *hekaPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
cp := cpolicy.New()
config := cpolicy.NewPolicyNode()
r1, err := cpolicy.NewStringRule("host", true)
handleErr(err)
r1.Description = "Heka host"
config.Add(r1)
r2, err := cpolicy.NewIntegerRule("port", true)
handleErr(err)
r2.Description = "Heka port"
config.Add(r2)
r3, err := cpolicy.NewStringRule("mappings-file", false)
handleErr(err)
r3.Description = "Heka plugin mappings JSON/XML file"
config.Add(r3)
cp.Add([]string{vendor, pluginName}, config)
return cp, nil
}
示例11: TestHTTPJSONRPC
//.........这里部分代码省略.........
Namespace_: []string{"foo", "bar"},
Config_: cdn,
},
})
So(err, ShouldBeNil)
So(mts, ShouldNotBeNil)
So(mts, ShouldHaveSameTypeAs, []core.Metric{})
So(len(mts), ShouldBeGreaterThan, 0)
So(mts[0].Config().Table(), ShouldNotBeEmpty)
So(mts[0].Config().Table()["someInt"].Type(), ShouldResemble, "integer")
Convey("Get and process the ConfigPolicy", func() {
cp, err := c.GetConfigPolicy()
So(err, ShouldBeNil)
So(cp, ShouldNotBeNil)
node := cp.Get([]string{"foo", "bar"})
So(node, ShouldNotBeNil)
So(err, ShouldBeNil)
_, cserrs := node.Process(mts[0].Config().Table())
//So(cpn, ShouldBeNil)
So(cserrs.Errors(), ShouldNotBeEmpty)
So(len(cserrs.Errors()), ShouldEqual, 1)
So(cserrs.Errors()[0].Error(), ShouldContainSubstring, "password")
})
})
})
Convey("Processor Client", t, func() {
session.c = false
p, _ := NewProcessorHttpJSONRPCClient(fmt.Sprintf("http://%v", addr), 1*time.Second, &key.PublicKey, true)
cl := p.(*httpJSONRPCClient)
cl.encrypter.Key = symkey
So(p, ShouldNotBeNil)
Convey("GetConfigPolicy", func() {
cp, err := p.GetConfigPolicy()
So(err, ShouldBeNil)
So(cp, ShouldNotBeNil)
cp_ := cpolicy.New()
cpn_ := cpolicy.NewPolicyNode()
r1, err := cpolicy.NewIntegerRule("SomeRequiredInt", true, 1)
r2, _ := cpolicy.NewStringRule("password", true)
r3, _ := cpolicy.NewFloatRule("somefloat", false, 3.14)
So(err, ShouldBeNil)
cpn_.Add(r1, r2, r3)
cp_.Add([]string{""}, cpn_)
cpjson, _ := cp.MarshalJSON()
cp_json, _ := cp_.MarshalJSON()
So(string(cpjson), ShouldResemble, string(cp_json))
})
Convey("Process metrics", func() {
pmt := plugin.NewPluginMetricType([]string{"foo", "bar"}, time.Now(), "", nil, nil, 1)
b, _ := json.Marshal([]plugin.PluginMetricType{*pmt})
contentType, content, err := p.Process(plugin.SnapJSONContentType, b, nil)
So(contentType, ShouldResemble, plugin.SnapJSONContentType)
So(content, ShouldNotBeNil)
So(err, ShouldEqual, nil)
var pmts []plugin.PluginMetricType
err = json.Unmarshal(content, &pmts)
So(err, ShouldBeNil)
So(len(pmts), ShouldEqual, 1)
So(pmts[0].Data(), ShouldEqual, 1)
So(pmts[0].Namespace(), ShouldResemble, []string{"foo", "bar"})
})
})
Convey("Publisher Client", t, func() {
session.c = false
p, _ := NewPublisherHttpJSONRPCClient(fmt.Sprintf("http://%v", addr), 1*time.Second, &key.PublicKey, true)
cl := p.(*httpJSONRPCClient)
cl.encrypter.Key = symkey
So(p, ShouldNotBeNil)
Convey("GetConfigPolicy", func() {
cp, err := p.GetConfigPolicy()
So(err, ShouldBeNil)
So(cp, ShouldNotBeNil)
cp_ := cpolicy.New()
cpn_ := cpolicy.NewPolicyNode()
r1, err := cpolicy.NewIntegerRule("SomeRequiredInt", true, 1)
r2, _ := cpolicy.NewStringRule("password", true)
r3, _ := cpolicy.NewFloatRule("somefloat", false, 3.14)
So(err, ShouldBeNil)
cpn_.Add(r1, r2, r3)
cp_.Add([]string{""}, cpn_)
cpjson, _ := cp.MarshalJSON()
cp_json, _ := cp_.MarshalJSON()
So(string(cpjson), ShouldResemble, string(cp_json))
})
Convey("Publish metrics", func() {
pmt := plugin.NewPluginMetricType([]string{"foo", "bar"}, time.Now(), "", nil, nil, 1)
b, _ := json.Marshal([]plugin.PluginMetricType{*pmt})
err := p.Publish(plugin.SnapJSONContentType, b, nil)
So(err, ShouldBeNil)
})
})
}
示例12: ToConfigPolicy
func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy {
result := cpolicy.New()
nodes := make(map[string]*cpolicy.ConfigPolicyNode)
for k, v := range reply.BoolPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
var br *cpolicy.BoolRule
var err error
if val.HasDefault {
br, err = cpolicy.NewBoolRule(key, val.Required, val.Default)
} else {
br, err = cpolicy.NewBoolRule(key, val.Required)
}
if err != nil {
rpcLogger.Warn("Empty key found with value %v", val)
continue
}
nodes[k].Add(br)
}
}
for k, v := range reply.StringPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
var sr *cpolicy.StringRule
var err error
if val.HasDefault {
sr, err = cpolicy.NewStringRule(key, val.Required, val.Default)
} else {
sr, err = cpolicy.NewStringRule(key, val.Required)
}
if err != nil {
rpcLogger.Warn("Empty key found with value %v", val)
continue
}
nodes[k].Add(sr)
}
}
for k, v := range reply.IntegerPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
var ir *cpolicy.IntRule
var err error
if val.HasDefault {
ir, err = cpolicy.NewIntegerRule(key, val.Required, int(val.Default))
} else {
ir, err = cpolicy.NewIntegerRule(key, val.Required)
}
if err != nil {
rpcLogger.Warn("Empty key found with value %v", val)
continue
}
if val.HasMin {
ir.SetMinimum(int(val.Minimum))
}
if val.HasMax {
ir.SetMaximum(int(val.Maximum))
}
nodes[k].Add(ir)
}
}
for k, v := range reply.FloatPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
var fr *cpolicy.FloatRule
var err error
if val.HasDefault {
fr, err = cpolicy.NewFloatRule(key, val.Required)
} else {
fr, err = cpolicy.NewFloatRule(key, val.Required)
}
if err != nil {
rpcLogger.Warn("Empty key found with value %v", val)
continue
}
if val.HasMin {
fr.SetMinimum(val.Minimum)
}
if val.HasMax {
fr.SetMaximum(val.Maximum)
}
nodes[k].Add(fr)
}
}
//.........这里部分代码省略.........
示例13: ToConfigPolicy
func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy {
result := cpolicy.New()
nodes := make(map[string]*cpolicy.ConfigPolicyNode)
for k, v := range reply.BoolPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
br, err := cpolicy.NewBoolRule(key, val.Required, val.Default)
if err != nil {
// The only error that can be thrown is empty key error, ignore something with empty key
continue
}
nodes[k].Add(br)
}
}
for k, v := range reply.StringPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
sr, err := cpolicy.NewStringRule(key, val.Required, val.Default)
if err != nil {
continue
}
nodes[k].Add(sr)
}
}
for k, v := range reply.IntegerPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
sr, err := cpolicy.NewIntegerRule(key, val.Required, int(val.Default))
if err != nil {
continue
}
nodes[k].Add(sr)
}
}
for k, v := range reply.FloatPolicy {
if _, ok := nodes[k]; !ok {
nodes[k] = cpolicy.NewPolicyNode()
}
for key, val := range v.Rules {
sr, err := cpolicy.NewFloatRule(key, val.Required, val.Default)
if err != nil {
continue
}
nodes[k].Add(sr)
}
}
for key, node := range nodes {
keys := strings.Split(key, ".")
result.Add(keys, node)
}
return result
}