Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/prashantrahul141/taurl
- Owner: prashantrahul141
- License: mit
- Created: 2024-05-30T13:53:29.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-05-31T09:19:33.000Z (7 months ago)
- Last Synced: 2024-06-01T09:27:29.750Z (7 months ago)
- Topics: gin, golang, url-shortener
- Language: Go
- Homepage:
- Size: 182 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)