gearbox
v1.2.4
GearBoxは、Goで書かれたマイクロサービスを構築するためのWebフレームワークであり、高性能に焦点を当てています。 net/httpよりも最大10倍高速なfastthttp上に構築されています
ギアボックスにはバージョン1.14以降が必要です(ダウンロードGO)
GOを使用してGearBoxをダウンロードしてインストールしてください
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テクノロジープラットフォームとトラック輸送 荷送人とキャリアをつなぐ市場 |
ギアボックスは、複数の組織で使用されていますが、
お気軽にお問い合わせください。質問がある場合は、[email protected]にメールでお問い合わせください。
GearboxはMITライセンスに基づいてライセンスされています
ロゴはMahmoud Sayedによって作成され、Creative Commonsライセンスの下で配布されます