Skip to content

SahajR/go-url-shortner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang URL shortener

My hello world project for Golang.

Getting started

Install the following dependencies:

This project uses MongoDB. You can get a free hosted one at mLab. Get the connection string and database name and put them in example.db.json. Rename it to db.json . The default port the server runs is 3000. You can change it in the config if you wish to.

Then you can start the server by running:

go run main.go
 
// OR
 
go build main.go
./main

The server will be running on localhost listening on the port in the config.

With a GET request to localhost:3000/shorten?url={LONG_URL}, you get the short code as result:

{
  "ShortURL": "https://localhost:3000/5h0r1"
}

Navigating to https://localhost:3000/5h0r1 will redirect back to {LONG_URL}.

Releases

No releases published

Packages

No packages published

Languages