Documentation ¶
Overview ¶
Package short is a simple web based api. It will produce shortest hash possible for a url. It will use longer hashes only in case of collision.
For example for https://example.org is redis is empty it will return /5
short has has two entries:
/post which accepts a url and returns a short version of it.
{"url": "https://example.org"}
/TOKEN which based on request headers will return a json reply or will redirect the agent to the original url.
short uses redis for its backned storage. You can set the redis url in command or in code.
$ REDISURL="redis://:PASSWORD@pub-zone.redislabs.com:12919/0"
Example of using this package is available in example directory.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Site ¶
type Site struct { // Host will define the prefix to be used for generated short token for redirects. Host string // RedisURL defines the redis instance to use. If it is empty REDISURL environment variable will be used. RedisURL string }
Site defines main attributes of shortener service.
func (Site) Post ¶
func (site Site) Post(w http.ResponseWriter, r *http.Request)
Post Only accepts json data in the following format
{"url": "https://example.org"}
return results is always in the following format:
{"short":"https://short.me/ab", "error":""}
If there was any error short will be empty and error message will show.