shrtie

package module
v0.0.0-...-b5f5611 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2016 License: MIT Imports: 9 Imported by: 0

README

shrtie Build Status GoDoc

What is this ?

This projects aims to provide a small and flexible url shortner

Features

Flexible: Supports several routers such as gorilla/mux, julienschmidt/httprouter and the default http.ServeMux server.

How to get it ?

go get github.com/realfake/shrtie

How to use it ?

Have a look in the examples/ folder.

package main

import (
	"log"
	"net/http"

	"github.com/julienschmidt/httprouter"
	"github.com/realfake/shrtie"
	backend "github.com/realfake/shrtie/backend/redis"
	redis "gopkg.in/redis.v4"
)

func main() {

	b, err := backend.New(&redis.Options{
		Addr:     "localhost:6379",
		Password: "",
		DB:       0,
	})

	if err != nil {
		log.Fatal(err)
	}

	s := shrtie.New(b)
	server := httprouter.New()

	// Get RedirectHandler and warp it
	// into a julienschmidt/httprouter compatible handler function
	server.GET("/s/:id", s.RedirectHandler().Httprouter())
	server.POST("/s", s.SaveHandler().Httprouter())

	server.GET("/info/:id", s.InfoHandler().Httprouter())

	// Start server
	log.Print(http.ListenAndServe(":9999", server))

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ack

type Ack struct {
	URL string `json:"url"` // The shortened URL
}

type Entry

type Entry struct {
	URL     string    `json:"url"`               // The URL to shorten
	TTL     int64     `json:"ttl,omitempty"`     // Time in seconds to life. Overwrites Expires
	Expires time.Time `json:"expires,omitempty"` // Sets the expiration date. Format is specified in RFC 3339
}

type GetSaver

type GetSaver interface {
	Get(string) (string, error)
	Save(string, time.Duration) string
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func (Handler) Httprouter

func (h Handler) Httprouter() httprouter.Handle

func (Handler) Mux

func (h Handler) Mux() http.HandlerFunc

func (Handler) ServerMux

func (h Handler) ServerMux() http.HandlerFunc

type Infoer

type Infoer interface {
	Info(string) (*Metadata, error)
}

type Metadata

type Metadata struct {
	URL     string    `json:"url"`           // The shortened URL
	TTL     int64     `json:"ttl,omitempty"` // Time to life in seconds
	Clicked int64     `json:"click_count"`   // Click count
	Created time.Time `json:"created"`       // Created time the format is specified in RFC 3339
}

type Shrtie

type Shrtie struct {
	// contains filtered or unexported fields
}

func New

func New(backend GetSaver) Shrtie

func (Shrtie) InfoHandler

func (s Shrtie) InfoHandler() Handler

func (Shrtie) RedirectHandler

func (s Shrtie) RedirectHandler() Handler

func (Shrtie) SaveHandler

func (s Shrtie) SaveHandler() Handler

Directories

Path Synopsis
backend
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL