Skip to content

wrfly/yasuser

Repository files navigation

Yasuser

Yet another self-hosted URL shortener.

Short or Restore your URL, like https://git.io/ or https://goo.gl/ but under YOUR control.

Master Build Status Go Report Card license Docker Pulls

Run

docker run --name yasuser -dti \
    -p 8084:8084 \
    -e YASUSER_SHORTENER_STORE_DBPATH=/data/yasuser.db \
    -e YASUSER_SERVER_DOMAIN=http://localhost:8084 \
    -v `pwd`:/data \
    wrfly/yasuser

Or use the docker-compose.yml.

Configuration example (./yasuser -e):

debug: false
store:
  dbpath: ./yasuser.db
  dbtype: bolt  # bolt or redis
  redis: redis://localhost:6379
server:
  domain: https://u.kfd.me
  port: 8084    # port to listen
  limit: 10     # go tool pprof http://localhost:8084/debug/pprof/heap
  pprof: false  # go tool pprof http://localhost:8084/debug/pprof/heap
  gaid: 62244864-8  # google analytics ID
filter:
  domain:
    whitelist: []
    blacklist: []
  keyword:
    whitelist: []
    blacklist: []

All the configuration can be set via environment:

YASUSER_DEBUG=false
YASUSER_STORE_DBPATH=./yasuser.db
YASUSER_STORE_DBTYPE=bolt
YASUSER_STORE_REDIS=redis://localhost:6379
YASUSER_SERVER_DOMAIN=https://u.kfd.me
YASUSER_SERVER_PORT=8084
YASUSER_SERVER_LIMIT=10
YASUSER_SERVER_PPROF=false
YASUSER_SERVER_GAID=62244864-8
YASUSER_FILTER_DOMAIN_WHITELIST=
YASUSER_FILTER_DOMAIN_BLACKLIST=
YASUSER_FILTER_KEYWORD_WHITELIST=
YASUSER_FILTER_KEYWORD_BLACKLIST=

Usage

# short your URL~ curl https://u.kfd.me -d "https://kfd.me"
https://u.kfd.me/1C
➜  ~

# restore it~ curl https://u.kfd.me/1C
<a href="https://kfd.me">Found</a>.

# customize the short URL~ curl https://u.kfd.me/ -d "https://kfd.me/hello" -H "custom: kfd"  
https://u.kfd.me/kfd

# conflict~ curl https://u.kfd.me/ -d "https://kfd.me/world" -H "custom: kfd"
custom URL already exist

# restore the customized URL~ curl https://u.kfd.me/kfd
<a href="https://kfd.me/hello">Found</a>.

# set TTL for a URL; bolt db will tell you the URL is expired while
# the redis will just delete it~ curl https://u.kfd.me/ -d "https://kfd.me/kfd" -H "ttl: 1s"
https://u.kfd.me/1B
➜  ~ sleep 1 && curl https://u.kfd.me/1B
url expired

# set TTL for a customized URL~ curl https://u.kfd.me/ -d "https://kfd.me/kfd" -H "ttl: 1s" -H "custom: 666"
https://u.kfd.me/666
➜  ~ sleep 1 && curl https://u.kfd.me/666
url expired

Or just visit the web page:

index

Benckmark

See benchmark

Features

  • it works
  • blob database
  • length and validate
  • memory cache
  • redis database
  • customization
  • TTL of URL
  • rate limit
  • [ ] management(auth)
    • domain filter
    • keyword filter
  • statistic
    • URL status - [ ] runtime metrics
    • status badge
  • UI index
    • google analytics
    • prettify the index
  • pprof