Exemplo n.º 1
0
func getStyle(context *web.Context) {
	b, err := ioutil.ReadFile("style.css")
	context.SetHeader("Content-Type", "text/css", true)
	if err != nil {
		context.WriteString(err.String())
	}

	context.Write(b)
}
Exemplo n.º 2
0
func pageRouter(ctx *web.Context, route string) {
	switch route {
	case "search":
		json, e := Search(ctx)
		if e != nil {
			ctx.WriteString(e.String())
		}
		ctx.Write(json)
	default:

	}
}
Exemplo n.º 3
0
// function to display the info about a KurzUrl given by it's Key
func info(ctx *web.Context, short string) {

	if strings.HasSuffix(short, "+") {
		short = strings.Replace(short, "+", "", 1)
	}
	kurl, err := load(short)
	if err == nil {
		ctx.SetHeader("Content-Type", "application/json", true)
		ctx.Write(kurl.Json())
		ctx.WriteString("\n")
	} else {
		ctx.Redirect(http.StatusNotFound, ROLL)
	}
}
Exemplo n.º 4
0
//Returns a json array with information about the last shortened urls. If data
// is a valid integer, that's the amount of data it will return, otherwise
// a maximum of 10 entries will be returned.
func latest(ctx *web.Context, data string) {
	howmany, err := strconv.Atoi64(data)
	if err != nil {
		howmany = 10
	}
	c, _ := redis.Get(COUNTER)

	last := c.Int64()
	upTo := (last - howmany)

	ctx.SetHeader("Content-Type", "application/json", true)
	ctx.WriteString("{ \"urls\" : [")
	for i := last; i > upTo && i > 0; i -= 1 {
		kurl, err := load(Encode(i))
		if err == nil {
			ctx.Write(kurl.Json())
			if i != upTo+1 {
				ctx.WriteString(",")
			}
		}
	}
	ctx.WriteString("] }")
	ctx.WriteString("\n")
}