Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/viveksahu26/url_shortner
It primarily used for converting long URL into short
https://github.com/viveksahu26/url_shortner
Last synced: 1 day ago
JSON representation
It primarily used for converting long URL into short
- Host: GitHub
- URL: https://github.com/viveksahu26/url_shortner
- Owner: viveksahu26
- License: apache-2.0
- Created: 2022-09-14T06:22:36.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-13T08:39:44.000Z (9 months ago)
- Last Synced: 2024-06-21T06:17:45.827Z (5 months ago)
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# URL SHORTNER
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/viveksahu26/url_shortner/badge)](https://securityscorecards.dev/viewer/?uri=github.com/viveksahu26/url_shortner)
## How to use url_shortner cli
- `go run ./cmd/url_shortner/main.go short --url="http://google.com/1346461234567890123456789/get/viveksahu266"`
The command means, return the `short` url of provided `long` url
**URL shortner endpoint - returns a short URL**
It is a service which takes long URL from the user and returns Short URL.
It provides 3 service.0) Start the server
`$ go run ./cmd/url_shortner/main.go server --port="8080"`1) health checks: it ensures that app is running.
Example: `http://localhost:8080/health`2) short url : it takes long url and returns short url
Example: `http://localhost:8080/short-url?longURL=http://google.com/1346461234567890123456789/get/viveksahu26`3) long url : it takes short url and returns long url
Example: `http://localhost:8080/long-url?sortURL=xtNFxaBwCG`## How URL Shortner Works
It replaces long URL by randomly generated characters of size 10.
It stores both Short and Long URL in the local file, `url.properties`.
If `url.properties` file is not present then creates new, otherwise write to the existing ones.
The advantage of saving Short URL and Long URL in the file is to retrieved that same Short URL correspondiing to Long URL.## Steps to reproduce it
1) Clone the repo:
`git clone https://github.com/viveksahu26/url_shortner.git`
2) Jump to the directory.
`cd url_shortner`
3) Execute main program.
`go run main.go`
You can provide your custom port
`go run main.go 5000`
*NOTE:*: Make sure that Port 8080 is free. By defaul Port is 8080. But you can customize accordingly by passing port number after command(go run main.go).
4) Check the health of program
5) Convert longURL into ShortURL:
Enter your URL after **
And let's say your Long URL: **
Finally you complete URL in the browser will look like:
You will get output
```
{"originalURL":"http://google.com/1346461234567890123456789/get/viveksahu26","shortURL":"http://localhost:8080/xtNFxaBwCG"}
```6) Convert ShortURL into LongURL:
Let's say shortURL=xtNFxaBwCG
To get it's longURL enter below URL in the browser
http://localhost:8080/long-url?sortURL=xtNFxaBwCG
It will return longURL to you as:
http://google.com/1346461234567890123456789/get/viveksahu26
## Steps to reproduce Using Docker Image
### Step:1
Docker Image: viveksahu26/urlshortner:stable
Link: https://hub.docker.com/repository/docker/viveksahu26/urlshortnerPull docker image:
docker pull viveksahu26/urlshortner:stable
### Step:2
Run container in non-interactive mode
docker run -d --name vivek -p 3000:8080 viveksahu26/urlshortner:stable
Run container in interactive mode
docker run --name vivek -p 3000:8080 viveksahu26/urlshortner:stable
### Step:3
Search on browser
http://localhost:3000/short-url?longURL=http://google.com/1346461234567890123456789/get/viveksahu26
Where, longURL=http://google.com/1346461234567890123456789/get/viveksahu26
And port: 3000To check health of app:
http://localhost:3000/health