Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lunarwhite/url-shortener
Try to design a simple demo to shorten URL and redirect.
https://github.com/lunarwhite/url-shortener
demo golang url-shortener
Last synced: 12 days ago
JSON representation
Try to design a simple demo to shorten URL and redirect.
- Host: GitHub
- URL: https://github.com/lunarwhite/url-shortener
- Owner: lunarwhite
- License: mit
- Created: 2021-11-01T02:31:27.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-19T14:38:34.000Z (7 months ago)
- Last Synced: 2024-06-21T19:50:23.000Z (5 months ago)
- Topics: demo, golang, url-shortener
- Language: Go
- Homepage:
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# url-shortener
A simple demo written in Golang to shorten URL and redirect```
.
├── go.mod
├── go.sum
├── handler
│ └── handlers.go
├── main.go
├── shortener
│ ├── shorturl_generator.go
│ └── shorturl_generator_test.go
└── store
├── store_service.go
└── store_service_test.go
```
## background
These small utilities services are quite helpful in reducing noise when sharing links. You can input a very long URL address and it can output a much shorter version of it much easier to share around.## setup envs
- go 1.17
- redis 3.2## how it works
- storage layer
- short link generator
- using SHA256 to hash the initial inputs
- using BASE58 binary to text encoding
- forwarding
- get the creation request body, parse it and extract the initial long url and userId
- generate our shortened hash using `shortener.GenerateShortLink()`
- store the mapping of output `hash/shortUrl` with the initial long url using `store.SaveUrlMapping()`## reference
[Let's build a URL shortener in Go - EDDY WANNY M](https://www.eddywm.com/lets-build-a-url-shortener-in-go/)