gearbox
v1.2.4
Gearbox는 고성능에 중점을 둔 Go에 작성된 마이크로 서비스를 구축하기위한 웹 프레임 워크입니다. 그것은 net/http보다 최대 10 배 더 빠른 fasthttp를 기반으로합니다.
기어 박스는 GO의 1.14 개 이상이 필요합니다 (다운로드 GO)
다운로드하고 기어 박스를 설치하십시오
go get -u github.com/gogearbox/gearbox package main
import (
"github.com/gogearbox/gearbox"
)
func main () {
// Setup gearbox
gb := gearbox . New ()
// Define your handlers
gb . Get ( "/hello" , func ( ctx gearbox. Context ) {
ctx . SendString ( "Hello World!" )
})
// Start service
gb . Start ( ":3000" )
} package main
import (
"github.com/gogearbox/gearbox"
)
func main () {
// Setup gearbox
gb := gearbox . New ()
// Handler with parameter
gb . Get ( "/users/:user" , func ( ctx gearbox. Context ) {
ctx . SendString ( ctx . Param ( "user" ))
})
// Start service
gb . Start ( ":3000" )
} package main
import (
"log"
"github.com/gogearbox/gearbox"
)
func main () {
// Setup gearbox
gb := gearbox . New ()
// create a logger middleware
logMiddleware := func ( ctx gearbox. Context ) {
log . Printf ( "log message!" )
// Next is what allows the request to continue to the next
// middleware/handler
ctx . Next ()
}
// create an unauthorized middleware
unAuthorizedMiddleware := func ( ctx gearbox. Context ) {
ctx . Status ( gearbox . StatusUnauthorized )
. SendString ( "You are unauthorized to access this page!" )
}
// Register the log middleware for all requests
gb . Use ( logMiddleware )
// Define your handlers
gb . Get ( "/hello" , func ( ctx gearbox. Context ) {
ctx . SendString ( "Hello World!" )
})
// Register the routes to be used when grouping routes
routes := [] * gearbox. Route {
gb . Get ( "/id" , func ( ctx gearbox. Context ) {
ctx . SendString ( "User X" )
}),
gb . Delete ( "/id" , func ( ctx gearbox. Context ) {
ctx . SendString ( "Deleted" )
}),
}
// Group account routes
accountRoutes := gb . Group ( "/account" , routes )
// Group account routes to be under api
gb . Group ( "/api" , accountRoutes )
// Define a route with unAuthorizedMiddleware as the middleware
// you can define as many middlewares as you want and have
// the handler as the last argument
gb . Get ( "/protected" , unAuthorizedMiddleware , func ( ctx gearbox. Context ) {
ctx . SendString ( "You accessed a protected page" )
})
// Start service
gb . Start ( ":3000" )
} package main
import (
"github.com/gogearbox/gearbox"
)
func main () {
// Setup gearbox
gb := gearbox . New ()
// Serve files in assets directory for prefix static
// for example /static/gearbox.png, etc.
gb . Static ( "/static" , "./assets" )
// Start service
gb . Start ( ":3000" )
}더 많은 결과를 얻으려면 문서를 확인하십시오
기어 박스 및 기여 방법에 대한 자세한 내용은 문서를 확인하십시오.
기어 박스 관리, 홍보 및 지원을 돕는 조직
| TRELLA : B2B 기술 플랫폼 및 트럭 운송 운송 업체와 배송 업체를 연결하는 시장 |
기어 박스 는
질문이나 제안이 있으면 discord에서 저희와 자유롭게 채팅하거나 [email protected]으로 이메일을 보내주십시오.
기어 박스는 MIT 라이센스에 따라 라이센스가 부여됩니다
로고는 Mahmoud Sayed가 작성하고 Creative Commons 라이센스에 따라 배포됩니다.