Beispiel #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)
}
Beispiel #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")
}
Beispiel #3
0
func Start() {

	Log("Initializing Routes...")
	routes() //defined in routes.go

	Log("Connecting to Redis Store")
	c, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		Log("Couldn't connect to Redis Store...")
		return
	}
	defer c.Close()

	Log("Starting server...")
	var port int
	flag.IntVar(&port, "p", 8080, "Port number")
	flag.Parse()
	web.Run("0.0.0.0:" + strconv.Itoa(port))
}