• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang inidef.LoadConfigByte函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/shiguredo/fuji/inidef.LoadConfigByte函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadConfigByte函数的具体用法?Golang LoadConfigByte怎么用?Golang LoadConfigByte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LoadConfigByte函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestRetainJustPublish

// TestRetainJustPublish tests
// 1. connect gateway to local broker
// 2. send data with retaind flag dummy device normaly
func TestRetainJustPublish(t *testing.T) {
	assert := assert.New(t)
	iniStr := `
	[gateway]
	
	    name = retainham
	
	[broker "local/1"]
	
	    host = localhost
	    port = 1883
	
	[device "doraretain/dummy"]
	
	    broker = local
	    qos = 0
	
	    interval = 10
	    payload = Hello world retain true.
	
	    type = EnOcean
	    retain = true
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	assert.Nil(err)
	commandChannel := make(chan string)
	go fuji.StartByFileWithChannel(conf, commandChannel)

	time.Sleep(2 * time.Second)
}
开发者ID:taoyonggang,项目名称:fuji,代码行数:33,代码来源:retain_test.go


示例2: TestWillJustPublish

// TestWillJustPublish tests
// 1. connect localhost broker with will message
// 2. send data from a dummy device
// 3. disconnect
func TestWillJustPublish(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
	[gateway]
	    name = willjustpublishham
	[broker "local/1"]
	    host = localhost
	    port = 1883
	    will_message = no letter is good letter.
	[device "dora/dummy"]
	    broker = local
	    qos = 0
	    interval = 10
	    payload = Hello will just publish world.
	    type = EnOcean
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	assert.Nil(err)
	commandChannel := make(chan string)
	go fuji.StartByFileWithChannel(conf, commandChannel)
	time.Sleep(5 * time.Second)

	//	fuji.Stop()
}
开发者ID:chansuke,项目名称:fuji,代码行数:29,代码来源:will_test.go


示例3: TestStatus

func TestStatus(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[broker "sango"]
  host = 192.168.1.20
  port = 1033
[status "cpu"]
  cpu_times = user, system, idle, nice, iowait, irq, softirq, guest
[status "memory"]
  virtual_memory = total, available, percent, used, free
[status]
  broker = sango
  interval = 10
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	assert.Nil(err)
	tt, err := NewStatus(conf)
	assert.Nil(err)
	st, ok := tt.(Status)
	assert.True(ok)

	assert.Equal(st.BrokerName, "sango")
	assert.Equal(st.Interval, 10)

	assert.Equal(8, len(st.CPU.CpuTimes))
	assert.Equal(5, len(st.Memory.VirtualMemory))
}
开发者ID:chansuke,项目名称:fuji,代码行数:28,代码来源:status_test.go


示例4: TestNewGatewayMaxRetryCount

func TestNewGatewayMaxRetryCount(t *testing.T) {
	assert := assert.New(t)

	{ // default
		iniStr := `
[gateway]
name = sango
`
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		gw, err := NewGateway(conf)
		assert.Nil(err)
		assert.Equal(3, gw.MaxRetryCount)
	}
	{ // specified
		iniStr := `
[gateway]
name = sango
max_retry_count = 10
`
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		gw, err := NewGateway(conf)
		assert.Nil(err)
		assert.Equal(10, gw.MaxRetryCount)
	}
	{ // minus fail validation
		iniStr := `
[gateway]
name = sango
max_retry_count = -10
`
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		_, err = NewGateway(conf)
		assert.NotNil(err)
	}
	{ // invalid int
		iniStr := `
[gateway]
name = sango
max_retry_count = aabbcc
`
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		_, err = NewGateway(conf)
		assert.NotNil(err)
	}
}
开发者ID:chansuke,项目名称:fuji,代码行数:45,代码来源:gateway_test.go


示例5: generalIniWillTest

func generalIniWillTest(test iniWillTestCase, t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfigByte([]byte(test.iniStr))
	assert.Nil(err)

	brokers, err := broker.NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.NotEqual(0, len(brokers))
}
开发者ID:chansuke,项目名称:fuji,代码行数:10,代码来源:ini_will_test.go


示例6: TestBrokerValidationPort

func TestBrokerValidationPort(t *testing.T) {
	assert := assert.New(t)
	iniStr := `
[broker "sango/2"]
    host = 192.168.1.22
    port = 65536
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	_, err = NewBrokers(conf, make(chan message.Message))
	assert.NotNil(err)
}
开发者ID:chansuke,项目名称:fuji,代码行数:11,代码来源:broker_test.go


示例7: TestBrokerValidationWill

func TestBrokerValidationWill(t *testing.T) {
	assert := assert.New(t)
	iniStr := `
	[broker "sango/1"]
    host = 192.168.1.22
    port = 1883
    will_message = will
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b, err := NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.Equal(1, len(b))
	assert.Equal([]byte("will"), b[0].WillMessage)

	iniStr = `
	[broker "sango/1"]
    host = 192.168.1.22
    port = 1883
    will_message = \x01\x0f
`
	conf, err = inidef.LoadConfigByte([]byte(iniStr))
	b, err = NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.Equal(1, len(b))
	assert.Equal([]byte{1, 15}, b[0].WillMessage)

	// either will message has invalid binary, not error, just warn
	iniStr = `
	[broker "sango/1"]
    host = 192.168.1.22
    port = 1883
    will_message = \x01\x0fffff
`
	conf, err = inidef.LoadConfigByte([]byte(iniStr))
	b, err = NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.Equal(1, len(b))
	assert.Equal([]byte{1, 15}, b[0].WillMessage)
}
开发者ID:chansuke,项目名称:fuji,代码行数:39,代码来源:broker_test.go


示例8: TestNewGatewayInvalidName

func TestNewGatewayInvalidName(t *testing.T) {
	assert := assert.New(t)

	{ // includes plus
		iniStr := `
[gateway]
name = bone+lessham
`
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		_, err = NewGateway(conf)
		assert.NotNil(err)
	}
	{ // includes sharp
		iniStr := `
[gateway]
name = ` + "`" + `bone\#lessham`
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		_, err = NewGateway(conf)
		assert.NotNil(err)
	}
	{ // too long
		iniStr := `
[gateway]
name = bonelesshaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
`
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		_, err = NewGateway(conf)
		assert.NotNil(err)
	}
	{ // \\U0000 string
		iniStr := fmt.Sprintf(`
[gateway]
name = 	na%cme
`, '\u0000')
		conf, err := inidef.LoadConfigByte([]byte(iniStr))
		_, err = NewGateway(conf)
		assert.NotNil(err)
	}
}
开发者ID:chansuke,项目名称:fuji,代码行数:39,代码来源:gateway_test.go


示例9: TestBrokerValidationHost

func TestBrokerValidationHost(t *testing.T) {
	assert := assert.New(t)

	// invalid host, too long
	iniStr := `
[broker "sango/2"]
    host = 192.168.1.22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    port = 1883
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	_, err = NewBrokers(conf, make(chan message.Message))
	assert.NotNil(err)
}
开发者ID:chansuke,项目名称:fuji,代码行数:13,代码来源:broker_test.go


示例10: generalIniRetainSerialDeviceTest

// generalIniRetainSerialDeviceTest checks retain function with serial device
func generalIniRetainSerialDeviceTest(test iniRetainTestCase, t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfigByte([]byte(test.iniStr))
	assert.Nil(err)

	brokers, err := broker.NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)

	devices, _, err := device.NewDevices(conf, brokers)
	assert.Nil(err)
	assert.Equal(1, len(devices))
}
开发者ID:chansuke,项目名称:fuji,代码行数:14,代码来源:ini_retain_test.go


示例11: TestNewSerialDeviceInvalidQoS

func TestNewSerialDeviceInvalidQoS(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[device "dora/serial"]
    broker = sango
    qos = -1
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b1 := &broker.Broker{Name: "sango"}
	brokers := []*broker.Broker{b1}
	_, err = NewSerialDevice(conf.Sections[1], brokers, make(chan message.Message))
	assert.NotNil(err)
}
开发者ID:taoyonggang,项目名称:fuji,代码行数:14,代码来源:serial_test.go


示例12: TestNewSerialDeviceInvalidBroker

func TestNewSerialDeviceInvalidBroker(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[device "dora/serial"]
    broker = doesNotExist
    qos = 1
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b1 := &broker.Broker{Name: "sango"}
	brokers := []*broker.Broker{b1}
	_, err = NewSerialDevice(conf.Sections[1], brokers, NewDeviceChannel())
	assert.NotNil(err)
}
开发者ID:chansuke,项目名称:fuji,代码行数:14,代码来源:serial_test.go


示例13: TestNewDummyDeviceInvalidBroker

func TestNewDummyDeviceInvalidBroker(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[device "dora/dummy"]
    broker = doesNotExist
    interval = 10
    qos = 1
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b1 := &broker.Broker{Name: "sango"}
	brokers := []*broker.Broker{b1}
	_, err = NewDummyDevice(conf.Sections[1], brokers, make(chan message.Message))
	assert.NotNil(err)
}
开发者ID:taoyonggang,项目名称:fuji,代码行数:15,代码来源:dummy_test.go


示例14: TestNewDummyDeviceInvalidQoS

func TestNewDummyDeviceInvalidQoS(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[device "dora/dummy"]
    broker = sango
    interval = -1
    qos = -1
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b1 := &broker.Broker{Name: "sango"}
	brokers := []*broker.Broker{b1}
	_, err = NewDummyDevice(conf.Sections[1], brokers, NewDeviceChannel())
	assert.NotNil(err)
}
开发者ID:chansuke,项目名称:fuji,代码行数:15,代码来源:dummy_test.go


示例15: TestNewBrokersSingle

func TestNewBrokersSingle(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[broker "sango/2"]
    host = 192.168.1.22
    port = 1883
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b, err := NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.Equal(1, len(b))
	assert.Equal("sango", b[0].Name)
	assert.Equal(2, b[0].Priority)
	assert.Equal("", b[0].TopicPrefix)
	assert.Equal([]byte{}, b[0].WillMessage)
}
开发者ID:chansuke,项目名称:fuji,代码行数:17,代码来源:broker_test.go


示例16: generalIniRetainDummyDeviceTest

// generalIniRetainDummyDeviceTest checks retain function with dummy device
func generalIniRetainDummyDeviceTest(test iniRetainTestCase, t *testing.T) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfigByte([]byte(test.iniStr))
	assert.Nil(err)

	brokers, err := broker.NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)

	dummy, err := device.NewDummyDevice(conf.Sections[2], brokers, device.NewDeviceChannel())
	if test.expectedError == nil {
		assert.Nil(err)
		assert.NotNil(dummy)
	} else {
		assert.NotNil(err)
	}
}
开发者ID:chansuke,项目名称:fuji,代码行数:18,代码来源:ini_retain_test.go


示例17: TestNewBrokersMulti

func TestNewBrokersMulti(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[broker "sango/1"]
    host = 192.168.1.22
    port = 1883
[broker "sango/2"]
    host = 192.168.1.22
    port = 1883
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b, err := NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.Equal(2, len(b))
	assert.Equal("sango", b[0].Name)
	assert.Equal(1, b[0].Priority)
	assert.Equal(2, b[1].Priority)
}
开发者ID:chansuke,项目名称:fuji,代码行数:19,代码来源:broker_test.go


示例18: TestNewSerialDeviceNotSetSize

func TestNewSerialDeviceNotSetSize(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[device "dora/serial"]
    broker = sango
    qos = 1
    serial = /dev/tty.ble
    baud = 9600
    type = BLE
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b1 := &broker.Broker{Name: "sango"}
	brokers := []*broker.Broker{b1}
	b, err := NewSerialDevice(conf.Sections[1], brokers, make(chan message.Message))
	assert.Nil(err)
	assert.NotNil(b.Broker)
	assert.Equal("dora", b.Name)
	assert.Equal(0, b.Size)
	assert.Equal("BLE", b.Type)
}
开发者ID:taoyonggang,项目名称:fuji,代码行数:21,代码来源:serial_test.go


示例19: TestNewBrokersSettings

func TestNewBrokersSettings(t *testing.T) {
	assert := assert.New(t)

	iniStr := `
[broker "sango/2"]
    host = 192.168.1.22
    port = 1883
    username = usr
    password = pass
    topic_prefix = pre
    will_message = will
`
	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	b, err := NewBrokers(conf, make(chan message.Message))
	assert.Nil(err)
	assert.Equal(1, len(b))
	assert.Equal("usr", b[0].Username)
	assert.Equal("pass", b[0].Password)
	assert.Equal("pre", b[0].TopicPrefix)
	assert.Equal([]byte("will"), b[0].WillMessage)
}
开发者ID:chansuke,项目名称:fuji,代码行数:21,代码来源:broker_test.go


示例20: genericWillTestDriver

func genericWillTestDriver(t *testing.T, iniStr string, expectedTopic string, expectedPayload []byte) (ok bool) {
	assert := assert.New(t)

	conf, err := inidef.LoadConfigByte([]byte(iniStr))
	assert.Nil(err)
	commandChannel := make(chan string)
	go fuji.StartByFileWithChannel(conf, commandChannel)

	gw, err := gateway.NewGateway(conf)
	assert.Nil(err)

	brokers, err := broker.NewBrokers(conf, gw.BrokerChan)
	assert.Nil(err)

	go func() {
		time.Sleep(1 * time.Second)

		subscriberChannel, err := setupWillSubscriber(gw, brokers[0])
		if err != inidef.Error("") {
			t.Error(err)
		}

		time.Sleep(1 * time.Second)

		// kill publisher
		brokers[0].FourceClose()
		fmt.Println("broker killed for getting will message")

		// check will message
		willMsg := <-subscriberChannel

		assert.Equal(expectedTopic, willMsg.Topic())
		assert.Equal(expectedPayload, willMsg.Payload())
		assert.Equal(byte(0), willMsg.Qos())
	}()
	time.Sleep(3 * time.Second)
	ok = true
	return ok
}
开发者ID:chansuke,项目名称:fuji,代码行数:39,代码来源:will_test.go



注:本文中的github.com/shiguredo/fuji/inidef.LoadConfigByte函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-28
下一篇:
Golang shared.NewInvalidTypeError函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap