<commit_before># Fast Shortener
[![CircleCI](https://circleci.com/gh/DavidLu1997/fast-shortener/tree/master.svg?style=svg&circle-token=913bd3241b1007590e4c743144cd8c598ce59220)](https://circleci.com/gh/DavidLu1997/fast-shortener/tree/master)
[![codecov](https://codecov.io/gh/DavidLu1997/fast-shortener/branch/master/graph/badge.svg?token=DN5spsSZGE)](https://codecov.io/gh/DavidLu1997/fast-shortener)

A non-persistent fast URL-shortening service in Golang using [valaya/fasthttp](https://github.com/valyala/fasthttp) and [patrickmn/go-cache](https://github.com/patrickmn/go-cache).

## Why use this?

- Links only persist as long as needed
- Speed is good
- You don't like databases

## Usage

### PUT Link

To shorten https://google.com to `hostname/google` for 60 seconds, make a request to `hostname/put`
```json
{
  "url": "https://google.com",
  "key": "google",
  "seconds": 60
}
```

Prohibited keys:
- `put`
- `ok`

### GET Link

To be redirected to https://google.com after PUT-ing the above, make a request to `hostname/google`

### Configuration

See [config.json](https://github.com/DavidLu1997/fast-shortener/blob/master/config/config.json)

## Documentations

Godocs TBA

## Benchmarks

- TBA, currently 300 rps PUT, 1000 rps GET on a 15" MBP

## Development

Clone the repo: `go get github.com/davidlu1997/fast-shortener`

### Tests
<commit_msg>Add benchmarks to readme<commit_after># Fast Shortener
[![CircleCI](https://circleci.com/gh/DavidLu1997/fast-shortener/tree/master.svg?style=svg&circle-token=913bd3241b1007590e4c743144cd8c598ce59220)](https://circleci.com/gh/DavidLu1997/fast-shortener/tree/master)
[![codecov](https://codecov.io/gh/DavidLu1997/fast-shortener/branch/master/graph/badge.svg?token=DN5spsSZGE)](https://codecov.io/gh/DavidLu1997/fast-shortener)

A non-persistent fast URL-shortening service in Golang using [valaya/fasthttp](https://github.com/valyala/fasthttp) and [patrickmn/go-cache](https://github.com/patrickmn/go-cache).

## Why use this?

- Links only persist as long as needed
- Speed is good
- You don't like databases

## Usage

### PUT Link

To shorten https://google.com to `hostname/google` for 60 seconds, make a request to `hostname/put`
```json
{
  "url": "https://google.com",
  "key": "google",
  "seconds": 60
}
```

Prohibited keys:
- `put`
- `ok`

### GET Link

To be redirected to https://google.com after PUT-ing the above, make a request to `hostname/google`

### Configuration

See [config.json](https://github.com/DavidLu1997/fast-shortener/blob/master/config/config.json)

## Documentation

Godocs TBA

## Benchmarks

Ran locally on a mid-2015 15" MBP

```
BenchmarkPutLink-8   	  500000	      2912 ns/op
BenchmarkGetLink-8   	 2000000	       848 ns/op
BenchmarkCacheShortenerPut-8   	 2000000	       727 ns/op
BenchmarkCacheShortenerGet-8   	10000000	       230 ns/op
```

## Development

Clone the repo: `go get github.com/davidlu1997/fast-shortener`

### Tests

{'fraction_non_alphanumeric': 0.1452437777020116, 'fraction_numerical': 0.06068871462666212, 'mean_word_length': 4.433333333333334, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1131471', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1043, 'n_words': 220}