示例#1
0
func getPaste(ctx *web.Context, uri string) string {
	c, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		Log(err)
		return mustache.Render("Cannot connect to DB \r\n")
	}
	defer c.Close()
	y := "PASTE_DOES_NOT_EXIST"
	if matched, _ := regexp.MatchString("[a-zA-Z0-9]+", uri); matched {
		y = "paste_" + uri
	}
	x, err := redis.String(c.Do("GET", y))
	ctx.SetHeader("Content-Type", "text/plain", true)
	ctx.SetHeader("X-Powered-By", "web.go", true)
	ctx.SetHeader("Connection", "close", true)
	return mustache.Render(x)
}
示例#2
0
func paste(ctx *web.Context) string {
	c, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		Log(err)
		return mustache.Render("Cannot connect to DB \r\n")
	}
	defer c.Close()
	rstr := rands(5)
	if val, ok := ctx.Params["name"]; ok {
		if matched, _ := regexp.MatchString("[a-zA-Z0-9]+", val); matched {
			rstr = val
		}
	}
	y := "paste_" + rstr
	c.Do("SET", y, ctx.Params["paste"])
	sname := "/" //"http://" + ctx.Server.Config.Addr + ":" + string(ctx.Server.Config.Port) + "/"
	return mustache.Render(sname + rstr + "\n")
}