Esempio n. 1
0
func relay() {
	app := core.NewApp("sarif", "tars")
	app.Init()

	info := Cache{FilePath: app.Config.Dir() + "/soji.json"}
	info.Bars = make(map[string]Bar)
	info.Read()

	info.PID = os.Getpid()
	app.Must(info.Write())

	c, err := app.ClientDial(sarif.ClientInfo{
		Name: "soji/" + sarif.GenerateId(),
	})
	c.HandleConcurrent = false
	app.Must(err)

	c.Subscribe("status", "", func(msg sarif.Message) {
		key := msg.Action
		if strings.HasPrefix(key, "status/") {
			key = strings.TrimPrefix(key, "status/")
		} else {
			key = "default"
		}

		bar := Bar{Key: key, Label: key, Text: msg.Text}
		if err := msg.DecodePayload(&bar); err != nil {
			msg.DecodePayload(&bar.Text)
			msg.DecodePayload(&bar.Value)
		}

		info.Bars[bar.Key] = bar
		app.Must(info.Write())
	})

	fmt.Println(os.Getpid())
	core.WaitUntilInterrupt()

	info.PID = 0
	app.Must(info.Write())

	c.Publish(sarif.CreateMessage("soji/down", nil))
}
Esempio n. 2
0
func (s *Server) Run() {
	s.Init()
	core.WaitUntilInterrupt()
	defer s.Close()
}