本文整理汇总了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())
示例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)
示例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)