Exemple #1
0
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
}
Exemple #2
0
func (r *Reader) Init(config jsonstruct.JSONStruct) error {
	port := config.IntWithDefault(Port, DefaultPort)
	laddr, err := net.ResolveUDPAddr("udp4", fmt.Sprintf(":%d", port))
	if err != nil {
		return err
	}

	r.connection, err = net.ListenUDP("udp4", laddr)
	if err != nil {
		return err
	}

	return nil
}
Exemple #3
0
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
}
Exemple #4
0
func (w *Writer) Init(config jsonstruct.JSONStruct) error {
	port := config.IntWithDefault(Port, DefaultPort)
	server := &http.Server{
		Addr:    fmt.Sprintf("localhost:%d", port),
		Handler: http.HandlerFunc(w.handle),
	}

	go func() {
		err := server.ListenAndServe()
		if err != nil {
			logs.Logger.Warning("Error when starting server, %e", err.Error())
		}
	}()

	w.messages = make(chan []byte)
	w.responses = make(chan response, 1)

	return nil
}
Exemple #5
0
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
}
Exemple #6
0
func (s *Scheme) Init(config jsonstruct.JSONStruct) error {
	s.messagesPerRun = config.IntWithDefault(MessagesPerRun, DefaultMessagesPerRun)
	s.bytesPerMessage = config.IntWithDefault(BytesPerMessage, DefaultBytesPerMessage)
	s.buffer = make([]byte, s.bytesPerMessage)

	var err error
	s.waitForLastMessage, err = config.DurationWithDefault(WaitForLastMessage, DefaultWaitForLastMessage)
	if err != nil {
		return err
	}

	s.warmupMessagesPerRun = config.IntWithDefault(WarmupMessagesPerRun, DefaultWarmupMessagesPerRun)
	s.warmupWait, err = config.DurationWithDefault(WarmupWait, DefaultWarmupWait)
	if err != nil {
		return err
	}

	return nil
}