Пример #1
0
func (mod *WebBee) GetRequest(ctx *web.Context) {
	ev := bees.Event{
		Bee:  mod.Name(),
		Name: "get",
		Options: []bees.Placeholder{
			bees.Placeholder{
				Name:  "ip",
				Type:  "string",
				Value: "tbd",
			},
		},
	}

	for k, v := range ctx.Params {
		log.Println("GET param:", k, "=", v)

		ph := bees.Placeholder{
			Name:  k,
			Type:  "string",
			Value: v,
		}
		ev.Options = append(ev.Options, ph)
	}

	mod.eventChan <- ev
}
Пример #2
0
func (mod *WebBee) triggerJsonEvent(resp *[]byte) {
	var payload interface{}
	err := json.Unmarshal(*resp, &payload)
	if err != nil {
		log.Println("Error:", err)
		return
	}

	ev := bees.Event{
		Bee:  mod.Name(),
		Name: "post",
		Options: []bees.Placeholder{
			bees.Placeholder{
				Name:  "json",
				Type:  "map",
				Value: payload,
			},
			bees.Placeholder{
				Name:  "ip",
				Type:  "string",
				Value: "tbd",
			},
		},
	}

	j := make(map[string]interface{})
	err = json.Unmarshal(*resp, &j)
	if err != nil {
		log.Println("Error:", err)
		return
	}

	for k, v := range j {
		log.Printf("POST JSON param: %s = %+v\n", k, v)

		ph := bees.Placeholder{
			Name:  k,
			Type:  "string",
			Value: v,
		}
		ev.Options = append(ev.Options, ph)
	}

	mod.eventChan <- ev
}