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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Hanji Chung
December 18, 2023
Technology
0
270
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
230
Other Decks in Technology
See All in Technology
SREのプラクティスを用いた3領域同時 マネジメントへの挑戦 〜SRE・情シス・セキュリティを統合した チーム運営術〜
coconala_engineer
2
650
プロポーザルに込める段取り八分
shoheimitani
1
250
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
270
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
190
CDK対応したAWS DevOps Agentを試そう_20260201
masakiokuda
1
280
顧客との商談議事録をみんなで読んで顧客解像度を上げよう
shibayu36
0
230
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
68k
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
190
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
3.8k
20260204_Midosuji_Tech
takuyay0ne
1
150
量子クラウドサービスの裏側 〜Deep Dive into OQTOPUS〜
oqtopus
0
110
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1k
Featured
See All Featured
Thoughts on Productivity
jonyablonski
74
5k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
How to Talk to Developers About Accessibility
jct
2
130
Exploring anti-patterns in Rails
aemeredith
2
250
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Producing Creativity
orderedlist
PRO
348
40k
Everyday Curiosity
cassininazir
0
130
Building Applications with DynamoDB
mza
96
6.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
110
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Mobile First: as difficult as doing things right
swwweet
225
10k
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/