Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Let's build a URL shortener in Go
Search
Hanji Chung
December 18, 2023
Technology
0
260
Let's build a URL shortener in Go
Hanji_DevFest2023
Hanji Chung
December 18, 2023
Tweet
Share
More Decks by Hanji Chung
See All by Hanji Chung
PGO (Profile-Guided Optimization)_ The Secret Weapon for Accelerating Golang Programs
msc7wc91w
0
220
Other Decks in Technology
See All in Technology
GA technologiesでのAI-Readyの取り組み@DataOps Night
yuto16
0
270
"複雑なデータ処理 × 静的サイト" を両立させる、楽をするRails運用 / A low-effort Rails workflow that combines “Complex Data Processing × Static Sites”
hogelog
3
1.9k
データエンジニアがこの先生きのこるには...?
10xinc
0
440
神回のメカニズムと再現方法/Mechanisms and Playbook for Kamikai scrumat2025
moriyuya
4
520
about #74462 go/token#FileSet
tomtwinkle
1
290
BtoBプロダクト開発の深層
16bitidol
0
270
AIが書いたコードをAIが検証する!自律的なモバイルアプリ開発の実現
henteko
1
340
GopherCon Tour 概略
logica0419
2
190
Green Tea Garbage Collector の今
zchee
PRO
2
390
SoccerNet GSRの紹介と技術応用:選手視点映像を提供するサッカー作戦盤ツール
mixi_engineers
PRO
1
170
生成AI_その前_に_マルチクラウド時代の信頼できるデータを支えるSnowflakeメタデータ活用術.pdf
cm_mikami
0
110
AI ReadyなData PlatformとしてのAutonomous Databaseアップデート
oracle4engineer
PRO
0
170
Featured
See All Featured
Building an army of robots
kneath
306
46k
Gamification - CAS2011
davidbonilla
81
5.5k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
Visualization
eitanlees
148
16k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
580
Agile that works and the tools we love
rasmusluckow
331
21k
Side Projects
sachag
455
43k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
The Cult of Friendly URLs
andyhume
79
6.6k
The Invisible Side of Design
smashingmag
301
51k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Transcript
Let's build a URL shortener in Go 韓吉 (Hanji)
About me • Freelancer, but open to work • 3+
backend work experience • Only using Golang in toy projects My LinkedIn
Slides
Github repo
Summary • Project Setup 🛠 • Igniting The Web Server
☄ • Store Service Setup 🛠 • Storage API Design • Shortener Generator Algorithm • Handlers & Endpoints
Project Setup 🛠 • Initialize the go project, using go
mod $ go mod init your-projectname • Create main.go file and add the code • Installing project dependencies $ go get github.com/go-redis/redis/v8 $ go get -u github.com/gin-gonic/gin
Download Redis • https://redis.io/docs/install/install-redis/
Igniting The Web Server ☄
Igniting The Web Server ☄ • Launching the web server
for first time • Run again the main.go file and go to http://localhost:9808/ in the browser or any rest client tool
Store Service Setup 🛠
Create a sub-directory
Setting up our wrappers around Redis
Storage API design and Implementation
func SaveUrlMapping
func RetrieveInitialUrl
Testing 🧪
Install the testing tools $ go get github.com/stretchr/testify
Setting up the the tests shell
Test the store service initialization
Test the storage APIs
Shortener Generator Algorithm
Create a sub-directory
SHA256
Base58 Encoded
Generate algorithm
Testing
Handlers & Endpoints
Create a sub-directory
Define handlers stubs
Setting endpoints
Request model definition
func CreateShortUrl
func HandleShortUrlRedirect
Demo time!!!
Demo curl --request POST --data '{ "long_url": "https://www.google.com/", "user_id" :
"123456789" }' http://localhost:9808/create-short-url
Reference • https://www.eddywm.com/lets-build-a-url-shortener-in-go/