Example #1
0
func getMessage(c *iris.Context) {
	t := sb.NewTable(
		"chats",
		sb.StrColumn("roomid", sb.UTF8, sb.UTF8CaseSensitive, false),
		sb.StrColumn("text", sb.UTF8, sb.UTF8CaseSensitive, false),
	)
	query, _ := t.Select(t.C("roomid"), t.C("text")).String("chat")
	rows, err := db.Query(query)
	if err != nil {
		log.Fatal(err)
	}
	var messages []string
	for rows.Next() {
		var roomid string
		var text string
		if err := rows.Scan(&roomid, &text); err != nil {
			log.Fatal(err)
		}
		messages = append(messages, text)
	}
	c.JSON(iris.StatusOK, map[string][]string{"messages": messages})
}
Example #2
0
func (m *myTestCustomHandler) Serve(ctx *iris.Context) {
	data := &m.data
	data.DynamicPathParameter = ctx.Param("myparam")
	ctx.JSON(iris.StatusOK, data)
}