HomeArtTechHackBlockchain
ONLINE ·
Index
/
Technology
/
Article

บันทึก การทำ Swaggo บน go fiber จ่ะ

Operator
Khomkrid Lerdprasert
Filed
November 25, 2021
Channel
Technology
Read
~1 min
บันทึก การทำ Swaggo บน go fiber จ่ะ

โว้ยยยยยย
ทำงานดิ

มาทำ swaggo ให้กับ go fiber กันดีกว่า

เราจะไปสร้าง swagger ui ใน main.go กันเว้ยยยยย อีดอกกก โดยเราจะ import

import (
"github.com/swaggo/swag/cmd/swag"
"github.com/arsmn/fiber-swagger/v2"
)
// @title APIs
// @version 1.0
// @description This is a sample server server.
// @termsOfService https://www.twinsynergy.co.th/
// @contact.name API Support
// @contact.url https://www.twinsynergy.co.th/
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host api.twinsynergy.co.th
// @BasePath /
// @schemes https

และไปสร้าง endpoint ไว้ว่า

app.Get("/swagger/*", swagger.Handler) // default

แล้วไป generate file ด้วยคำสั่ง ด้านล่างไปที่ apidocs

swag init -g cmd/main.go --output apidocs

แล้วเราก้อเขียน code ใน endpoint ของเราได้เลยด้วย syntax ของ swagger

// GetMusicChartByDate godoc
// @Summary ดึงข้อมูล Music Chart by params
// @Description ดึงข้อมูล Music Chart by params
// @Tags Music Chart
// @Accept application/json
// @Produce json
// @Success 200 {object} map[string]interface{}
// @param date query string false "YYYY-MM-DD"
// @Router /music/chart [get]
// @param Authorization header string true "Bearer token"

โว้ย
ทำงาน

ซึงหาอ่านได้ที่

https://github.com/arsmn/fiber-swagger

ทำไม่เป็น ทำไม่ได้ เอ้ยยย จ้างได้นะ

◎ Tags

##Go lang
Khomkrid Lerdprasert
Operator

Khomkrid Lerdprasert

Technical Lead — building AI-powered platforms, omni-channel chat systems, and telemedicine solutions with Go, Next.js & clean architecture. 20+ years shipping software from crypto wallets to e-learning systems. Bangkok-based. Writes code late at night, brews beer on weekends.

GithubInstagram
Previous · transmission
บันทึก การทำ Cronjob ง่ายๆ บน go fiber
Next · transmission
บันทึก การทำ Firebase Messaging ด้วย Golang และ Config ให้ใช้งานบน iOS
Metadata
Channel
Technology
Filed
November 25, 2021
Read
~1 min
Language
TH / EN
Transmit

Related

สร้าง Key pair เพื่อทำการ signing document signature ด้วย Go lang
Khomkrid Lerdprasert
March 13, 2024
1 min
aofiee.dev
signal / noise / code · craft
© 2019 – 2026, Khomkrid Lerdprasert.
All transmissions logged.
No newsletter. No profiling. Cookies require consent.
PGP · 7F3D 2024 A21E B584 · 0x7F3D
Channels
  • Art & Culture
  • Technology
  • Hack 101
  • Blockchain 101
  • Archive / All posts
— END OF TRANSMISSION —
// powered by curiosity, coffee, & wuxia
BKK · 13°45′N · 100°30′E