O GearBox é uma estrutura da web para criar micro serviços escritos em Go com foco no alto desempenho. É construído no Fasthttp, que é até 10x mais rápido que a rede/http
A caixa de engrenagens requer versão 1.14 ou superior do GO (download go)
Basta usar, vá para baixar e instalar a caixa de engrenagens
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" )
}Para mais resultados, verifique nossos documentos
Verifique nossos documentos para obter mais informações sobre a caixa de câmbio e como contribuir
Organizações que estão ajudando a gerenciar, promover e apoiar a caixa de engrenagens
| Trella: uma plataforma de tecnologia B2B e caminhões Marketplace que conecta remetentes com transportadoras |
A caixa de câmbio está sendo usada por várias organizações, incluindo, entre
Sinta -se à vontade para conversar conosco sobre a discórdia ou envie um e -mail para [email protected] se você tiver dúvidas ou sugestões
A caixa de câmbio é licenciada sob licença do MIT
O logotipo é criado por Mahmoud Sayed e distribuído sob licença Creative Commons