Fiber는 Go언어로 작성된 웹 프레임워크로 성능과 유연성을 최우선으로 설계되었습니다. Fiber는 Nods.js의 Express.js 프레임워크에서 영감을 받아, 익숙한 인터페이스를 제공하면서도 Go언어의 고성능 특성을 최대한 활용하였습니다.
Go의 주요 특징인 고루틴(Go Routine)을 효율적으로 사용하여 높은 동시성을 지원하고, 빠른 요청/응답 처리를 제공합니다.
최소한의 메모리 사용량과 작은 바이너리 크기를 지향하며, 배포와 실행 환경에서 매우 효율적입니다.
Express.js와 유사한 API를 제공해서 JavaScript, Node.js 개발자들에게 익숙한 개발 경험을 제공하기에 빠르게 학습하고 생산성을 높일 수 있습니다.
다양한 내장 미들웨어를 제공하며, 사용자 정의 미들웨어도 쉽게 추가할 수 있습니다. 미들웨어를 통해 요청 처리 파이프라인을 유연하게 구성할 수 있습니다.
동적 및 정적 라우팅을 지원하며, URL 파라미터, 쿼리 파라미터 등을 쉽게 처리할 수 있습니다. 라우트 그룹 기능을 통해 코드 구조를 체계적으로 관리할 수 있다는 장점도 있습니다.
실시간 통신을 위한 웹소켓(WebSocket) 및 서버 이벤트(Server-Sent Events)를 지원하여, 실시간 애플리케이션 개발에 유리합니다.
다양한 템플릿 엔진(e.g, Pug, Handlebars)을 통합하여 서버 사이드 렌더링(SSR)을 지원합니다.
package main
import (
"github.com/gofiber/fiber/v2"
)
func main() {
app := fiber.New()
// 기본 라우트
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
// 사용자 라우트
app.Get("/user/:name", func(c *fiber.Ctx) error {
name := c.Params("name")
return c.SendString("Hello, " + name)
})
// 서버 시작
app.Listen(":3000")
}
func main() {
engine := html.New(os.Getenv("VPATH"), ".html")
app := fiber.New(fiber.Config{
AppName: "big_money",
CaseSensitive: true,
StrictRouting: true,
ServerHeader: "Fiber",
ProxyHeader: "X-Forwarded-For",
EnableTrustedProxyCheck: true,
BodyLimit: 1024 * 1024 * 1000,
Views: engine,
EnableSplittingOnParsers: true,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 5 * time.Second,
Concurrency: 256 * 1024,
Prefork: true,
ErrorHandler: func(c *fiber.Ctx, err error) error {
return c.Status(500).SendString(err.Error())
},
Immutable: true,
CompressedFileSuffix: ".gz",
ETag: true,
})
app.Listen(":8090")
}
engine := html.New(os.Getenv("VPATH"), ".html")
이 라인은 HTML 템플릿 엔진을 초기화합니다. os.Getenv("VPATH")는 템플릿 파일들이 위치한 경로를 환경 변수에서 가져옵니다. 템플릿 파일의 확장자는 .html로 설정됩니다.
app := fiber.New(fiber.Config{
AppName: "big_money",
CaseSensitive: true,
StrictRouting: true,
ServerHeader: "Fiber",
ProxyHeader: "X-Forwarded-For",
EnableTrustedProxyCheck: true,
BodyLimit: 1024 * 1024 * 1000,
Views: engine,
EnableSplittingOnParsers: true,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 5 * time.Second,
Concurrency: 256 * 1024,
Prefork: true,
ErrorHandler: func(c *fiber.Ctx, err error) error {
return c.Status(500).SendString(err.Error())
},
Immutable: true,
CompressedFileSuffix: ".gz",
ETag: true,
})
이 부분에서는 Fiber 앱을 초기화하며 여러 옵션이 설정됩니다.
정리해보면 Fiber는 고성능, 경량화, 간단한 API, 유연한 라우팅 및 미들웨어 시스템을 통해 Go언어 기반의 웹 애플리케이션 개발을 효과적으로 지원하기에 생산성과 효율성을 모두 만족시키는 프레임워크라고 할 수 있습니다.