This project is a URL shortener service written in Go. It allows users to shorten URLs and retrieve the original URLs using the shortened keys.
- Shorten URLs and generate unique keys.
- Retrieve original URLs using the shortened keys.
- Save and load URLs from a JSON file.
- Optionally enable an RPC server for remote procedure calls. (Yet to work on this)
- Go 1.16 or later
-
Clone the repository:
git clone https://github.com/virgoaugustine/url-shortener.git cd url-shortener
-
Build the project:
go build
-
Run the server:
./url-shortener -port=4000 -file=urls.json -rpc=false
-
Add a URL:
- Open a browser and go to
http://localhost:4000/add
- Enter the URL you want to shorten and submit the form.
- Open a browser and go to
-
Redirect to the original URL:
- Use the shortened URL key in the browser, e.g.,
http://localhost:4000/u0hleB
- Use the shortened URL key in the browser, e.g.,
-port
: Port to run the server (default:4000
)-file
: File to store the saved URLs (default:urls.json
)-rpc
: Enable RPC server (default:false
)
main.go
: Entry point of the application.store.go
: Contains theURLStore
struct and methods for managing URLs.key.go
: Contains the method for generating unique keys.