Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/prashantrahul141/taurl

Fast url shortner written entirely in go.
https://github.com/prashantrahul141/taurl

gin golang url-shortener

Last synced: about 1 month ago
JSON representation

Fast url shortner written entirely in go.

Awesome Lists containing this project

README

        

## Taurl

Fast url shortner written entirely in Go using the gin framework.

### Provided routes:

#### Retrives an existing shortend url.

GET /api/get (first reads the cache, then the db.)

##### Parameters

> | name | type | data type | description |
> | ---- | -------- | --------- | ------------ |
> | Url | required | String | shortend url |

##### Responses

> | http code | content-type | response |
> | --------- | ------------------ | ---------------------------------- |
> | `200` | `application/json` | `Url body` |
> | `400` | `application/json` | `{"message":"Reason"}` |
> | `404` | `application/json` | `{"message":"Url was not found."}` |

##### Example cURL

> ```javascript
> curl -X GET -H "Content-Type: application/json" http://localhost:3000/api/get?Url=http://localhost:3000/hash
> ```

GET /api/get_from_id (first reads the cache, then the db, but uses unique id of a shortend url.)

##### Parameters

> | name | type | data type | description |
> | --------- | -------- | --------- | ----------------- |
> | unique_id | required | String | shortend url's id |

##### Responses

> | http code | content-type | response |
> | --------- | ------------------ | ---------------------------------- |
> | `200` | `application/json` | `Url body` |
> | `400` | `application/json` | `{"message":"Reason"}` |
> | `404` | `application/json` | `{"message":"Url was not found."}` |

##### Example cURL

> ```javascript
> curl -X GET -H "Content-Type: application/json" http://localhost:3000/api/get_from_id?Url=http://localhost:3000/hash
> ```

#### Sets a new shortend url and returns it.

POST /api/set (Creates and stores a new shortend url.)

##### Parameters

> | name | type | data type | description |
> | ---- | -------- | --------- | ------------ |
> | Url | required | String | Original url |

##### Responses

> | http code | content-type | response |
> | --------- | ------------------ | --------------------------------- |
> | `201` | `application/json` | `Url body` |
> | `400` | `application/json` | `{"message":"Reason"}` |
> | `500` | `application/json` | `{"message":"Failed to set db."}` |

##### Example cURL

> ```javascript
> curl -X POST -H "Content-Type: application/json" --data '{"Url":"https://example.com"}' http://localhost:3000/api/set
> ```

### Building

The program expects these environment variables :

```sh
# defaults to 3000
PORT=3000

# defaults to http://localhost:3000
# this is what you would set as your base domain.
BASE_URL="http://localhost:3000"

# optionally you can provide GIN_MODE to get or remove log messages
# from the gin framework.
# defaults to debug
GIN_MODE="debug" # release, debug
```

clone and run using go cli.

```sh
git clone --depth 1 https://github.com/prashantrahul141/taurl && cd taurl && go run .
```

![One](https://raw.githubusercontent.com/prashantrahul141/taurl/main/assets/meta/01.png)
![Two](https://raw.githubusercontent.com/prashantrahul141/taurl/main/assets/meta/02.png)