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


Golang jsonstruct.JSONStruct类代码示例

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


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

示例1: Init

func (r *Reader) Init(config jsonstruct.JSONStruct) error {
	port := config.IntWithDefault(Port, DefaultPort)
	remoteAddr := config.StringWithDefault(RemoteWriterAddr, DefaultRemoteWriterAddr)
	resp, err := http.DefaultClient.Get(fmt.Sprintf("http://%s:%d/", remoteAddr, port))
	if err != nil {
		return err
	}

	r.sseReader = vitosse.NewReadCloser(resp.Body)

	return nil
}
开发者ID:myshkin5,项目名称:netspel,代码行数:12,代码来源:reader.go

示例2: Init

func (s *Scheme) Init(config jsonstruct.JSONStruct) error {
	s.messagesPerSecond = config.IntWithDefault(MessagesPerSecond, DefaultMessagesPerSecond)
	expectedMessagesPerSecond := config.IntWithDefault(ExpectedMessagesPerSecond, DefaultExpectedMessagesPerSecond)
	s.bytesPerMessage = config.IntWithDefault(BytesPerMessage, DefaultBytesPerMessage)

	var err error
	s.reportCycle, err = config.DurationWithDefault(ReportCycle, DefaultReportCycle)
	if err != nil {
		return err
	}

	if expectedMessagesPerSecond == 0 {
		expectedMessagesPerSecond = s.messagesPerSecond
	}

	s.buffer = make([]byte, s.bytesPerMessage)
	if s.messagesPerSecond > 0 {
		s.tickerTime = time.Second / time.Duration(s.messagesPerSecond)
	}

	s.done.Add(1)

	if s.reporter == nil {
		s.reporter = &ReporterImpl{}
	}
	s.reporter.Init(expectedMessagesPerSecond, s.reportCycle)

	return nil
}
开发者ID:myshkin5,项目名称:netspel,代码行数:29,代码来源:scheme.go

示例3: Init

func (w *Writer) Init(config jsonstruct.JSONStruct) error {
	port := config.IntWithDefault(Port, DefaultPort)
	remoteAddr := config.StringWithDefault(RemoteReaderAddr, DefaultRemoteReaderAddr)
	raddr, err := net.ResolveUDPAddr("udp4", net.JoinHostPort(remoteAddr, strconv.Itoa(port)))
	if err != nil {
		return err
	}

	w.connection, err = net.DialUDP("udp4", nil, raddr)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:myshkin5,项目名称:netspel,代码行数:15,代码来源:writer.go

示例4:

	"net/http"
	"time"

	"github.com/myshkin5/jsonstruct"
	"github.com/myshkin5/netspel/adapters/sse"
	vitosse "github.com/vito/go-sse/sse"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Reader", func() {
	var (
		port            int
		sleepBeforeSend time.Duration
		events          []*vitosse.Event
		config          jsonstruct.JSONStruct
		reader          sse.Reader
	)

	handle := func(w http.ResponseWriter, r *http.Request) {
		defer GinkgoRecover()

		w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")
		w.Header().Set("Cache-Control", "no-cache")
		w.Header().Set("Connection", "keep-alive")
		w.WriteHeader(http.StatusOK)
		w.Write([]byte("\n"))
		flusher := w.(http.Flusher)
		flusher.Flush()
开发者ID:myshkin5,项目名称:netspel,代码行数:30,代码来源:reader_test.go

示例5:

package jsonstruct_test

import (
	"encoding/json"
	"time"

	"github.com/myshkin5/jsonstruct"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Setters", func() {
	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")
开发者ID:myshkin5,项目名称:jsonstruct,代码行数:31,代码来源:setters_test.go

示例6:

	"github.com/myshkin5/jsonstruct"
	"github.com/myshkin5/netspel/schemes/internal/mocks"
	"github.com/myshkin5/netspel/schemes/streaming"

	"sync"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

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

	BeforeEach(func() {
		writer = mocks.NewMockWriter()
		reader = mocks.NewMockReader()
		scheme = &streaming.Scheme{}
		config = jsonstruct.New()
		reporter = &mockReporter{
			reports: make(chan streaming.Report, 100),
		}
		scheme.SetReporter(reporter)
	})
开发者ID:myshkin5,项目名称:netspel,代码行数:30,代码来源:scheme_test.go


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