Example #1
0
File: qr.go Project: jango2015/wk
// Execute write qrcode image to response
func (qrcode *QrCodeResult) Execute(ctx *wk.HttpContext) error {

	c, err := qr.Encode(qrcode.Text, qr.M)
	if err != nil {
		log.Println("QrCodeResult Execute Error", err)
		return err
	}
	png := c.PNG()
	//ioutil.WriteFile(qrcode.Text+"_demo.png", png, 0666)
	ctx.ContentType("image/png")
	ctx.Write(png)

	return nil
}
Example #2
0
func printTrace(ctx *wk.HttpContext, trace []EventTrace) {

	if len(trace) == 0 {
		return
	}

	var buffer bytes.Buffer
	indent := 0
	s := "    "
	offset := trace[0].Timestamp

	buffer.WriteString("\n")
	//buffer.WriteString(fmt.Sprintf("url:%v \n", ctx.Request.URL))
	//buffer.WriteString(strings.Repeat("-", 10))
	//buffer.WriteString("\n")

	buffer.WriteString("<script>\n")
	buffer.WriteString("var pageProfiler = \"")
	for _, t := range trace {
		if strings.HasPrefix(t.Name, "end_") && indent > 0 {
			indent--
		}

		buffer.WriteString(strings.Repeat(s, indent))
		//buffer.WriteString(fmt.Sprintf("%s\t %s\t %d \n", t.Module, t.Name, t.Timestamp-offset))
		buffer.WriteString(fmt.Sprintf("%s\t %s\t %d ns \\n", t.Module, t.Name, t.Timestamp-offset))

		if strings.HasPrefix(t.Name, "start_") {
			indent++
		}
	}
	//buffer.WriteString(strings.Repeat("-", 10))
	//buffer.WriteString("\n")
	buffer.WriteString("\";")
	buffer.WriteString("\n</script>\n")
	ctx.Write(buffer.Bytes())
}