当前位置: 首页>>代码示例>>Golang>>正文


Golang JSONStruct.SetString方法代码示例

本文整理汇总了Golang中github.com/myshkin5/jsonstruct.JSONStruct.SetString方法的典型用法代码示例。如果您正苦于以下问题:Golang JSONStruct.SetString方法的具体用法?Golang JSONStruct.SetString怎么用?Golang JSONStruct.SetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/myshkin5/jsonstruct.JSONStruct的用法示例。


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

示例1:

	var (
		values jsonstruct.JSONStruct
	)

	Describe("SetString()", func() {
		It("overrides existing values", func() {
			err := json.Unmarshal([]byte(`{
				"this": "that",
				"parent": {
					"child": "value"
				}
			}`), &values)

			Expect(err).NotTo(HaveOccurred())

			Expect(values.SetString(".this", "something else")).To(Succeed())

			value, ok := values.String(".this")
			Expect(ok).To(BeTrue())
			Expect(value).To(Equal("something else"))

			Expect(values.SetString(".parent.child", "new value")).To(Succeed())

			value, ok = values.String(".parent.child")
			Expect(ok).To(BeTrue())
			Expect(value).To(Equal("new value"))
		})

		It("can set a string to empty string", func() {
			values = jsonstruct.New()
			Expect(values.SetString(".value", "something")).To(Succeed())
开发者ID:myshkin5,项目名称:jsonstruct,代码行数:31,代码来源:setters_test.go

示例2:

			port = 49282
		}
		port++

		go func() {
			defer GinkgoRecover()
			err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), http.HandlerFunc(handle))
			Expect(err).NotTo(HaveOccurred())
		}()

		events = []*vitosse.Event{}

		time.Sleep(50 * time.Millisecond)

		config = jsonstruct.New()
		config.SetString(sse.RemoteWriterAddr, "localhost")
		config.SetInt(sse.Port, port)

		reader = sse.Reader{}
	})

	It("connects to a writer via HTTP and reads SSE messages", func() {
		event := &vitosse.Event{
			ID:   "event-id",
			Name: "event-name",
			Data: make([]byte, 100),
		}
		events = append(events, event)
		events = append(events, event)

		err := reader.Init(config)
开发者ID:myshkin5,项目名称:netspel,代码行数:31,代码来源:reader_test.go

示例3:

var _ = Describe("Scheme", func() {
	var (
		writer *mocks.MockWriter
		reader *mocks.MockReader
		scheme *simple.Scheme
		config jsonstruct.JSONStruct
	)

	BeforeEach(func() {
		writer = mocks.NewMockWriter()
		reader = mocks.NewMockReader()
		scheme = &simple.Scheme{}
		config = jsonstruct.New()
		config.SetInt(simple.BytesPerMessage, 1000)
		config.SetInt(simple.MessagesPerRun, 100)
		config.SetString(simple.WaitForLastMessage, "100ms")
	})

	Context("with a short wait time", func() {
		JustBeforeEach(func() {
			config.SetString(simple.WaitForLastMessage, "100ms")
			err := scheme.Init(config)
			Expect(err).NotTo(HaveOccurred())
		})

		It("writes messages to a writer", func() {
			wg := sync.WaitGroup{}
			wg.Add(1)
			go func() {
				defer wg.Done()
				scheme.RunWriter(writer)
开发者ID:myshkin5,项目名称:netspel,代码行数:31,代码来源:scheme_test.go


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