Go QR코드 라이브러리
Go로 QR코드 생성
Go는 마이크로서비스와 CLI 도구에서 고성능 QR코드 생성에 이상적입니다. go-qrcode 라이브러리로 로컬 생성하거나 QRCode.fun API로 스타일 출력을 받으세요.
설치
go get을 사용하여 Go QR코드 라이브러리를 설치하세요.
go get
go get github.com/skip2/go-qrcodeGo로 QR코드 생성
go-qrcode 라이브러리를 사용한 코드 예제.
Basic QR Code Generation
package main
import "github.com/skip2/go-qrcode"
func main() {
err := qrcode.WriteFile("https://qrcode.fun", qrcode.Medium, 256, "qrcode.png")
if err != nil {
panic(err)
}
}QR Code as Bytes (HTTP Handler)
package main
import (
"net/http"
"github.com/skip2/go-qrcode"
)
func qrHandler(w http.ResponseWriter, r *http.Request) {
data := r.URL.Query().Get("data")
if data == "" {
data = "https://qrcode.fun"
}
png, err := qrcode.Encode(data, qrcode.Medium, 256)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.Header().Set("Content-Type", "image/png")
w.Write(png)
}
func main() {
http.HandleFunc("/qr", qrHandler)
http.ListenAndServe(":8080", nil)
}QRCode.fun API
Go에서 API로 QR코드 생성
Go에서 QRCode.fun API를 호출하여 스타일 QR코드를 생성하세요.
Go API 통합
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := map[string]interface{}{
"data": "https://qrcode.fun",
"width": 300,
"height": 300,
"type": "png",
"margin": 10,
"dotsOptions": map[string]string{
"color": "#1A2B3C",
"type": "rounded",
},
"cornersSquareOptions": map[string]string{
"color": "#8564C3",
"type": "extra-rounded",
},
"backgroundOptions": map[string]string{
"color": "#FFFFFF",
},
}
body, _ := json.Marshal(payload)
resp, err := http.Post(
"https://qrcode.fun/api/generate-qr-styled",
"application/json",
bytes.NewBuffer(body),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data[:100]))
}QR코드 라이브 미리보기
지금 바로 Go로 QR코드를 생성해 보세요.
QR 미리보기
네이티브 라이브러리 vs API
Go QR코드 라이브러리와 QRCode.fun API 비교.
| 기능 | 네이티브 라이브러리 | QRCode.fun API |
|---|---|---|
| 설정 복잡도 | go get + import | 단일 HTTP 요청 |
| 커스터마이징 | 크기, 오류 정정 레벨 | 전체 스타일링: 색상, 모양, 로고 |
| 오프라인 지원 | 예 | 인터넷 필요 |
| 유지보수 | go.mod 업데이트 | 항상 최신 상태 |
| 출력 형식 | PNG | PNG, SVG |
Go QR코드 사용 사례
Go 애플리케이션에서 QR코드의 일반적인 시나리오.
마이크로서비스
Go 마이크로서비스에서 API 응답, 웹훅, 이벤트 기반 아키텍처를 위한 QR코드를 생성합니다.
CLI 도구
Wi-Fi 공유, URL 단축, 터미널 표시를 위한 QR코드를 생성하는 커맨드라인 유틸리티를 구축합니다.
클라우드 함수
Go를 사용하여 AWS Lambda나 Google Cloud Functions에서 서버리스 함수로 QR 생성을 배포합니다.
DevOps 및 인프라
배포 URL, 모니터링 대시보드, 설정 엔드포인트를 위한 QR코드를 생성합니다.
자주 묻는 질문
Go로 QR코드 생성에 관한 일반적인 질문.
skip2/go-qrcode가 가장 인기 있는 Go QR코드 라이브러리입니다. PNG 이미지를 생성하며 설정 가능한 크기와 오류 정정 레벨을 지원합니다.