Skip to content

Commit

Permalink
update README (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
abahmed authored Jul 26, 2020
1 parent fc388d2 commit 334279a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</p>


**gearbox** :gear: is a web framework for building micro services written in Go with a focus on high performance and memory optimization. It's built on [fasthttp](https://github.com/valyala/fasthttp) which is **up to 10x faster** than net/http
**gearbox** :gear: is a web framework for building micro services written in Go with a focus on high performance. It's built on [fasthttp](https://github.com/valyala/fasthttp) which is **up to 10x faster** than net/http


### gearbox seeks to be
Expand Down Expand Up @@ -90,8 +90,9 @@ func main() {
package main

import (
"github.com/gogearbox/gearbox"
"log"

"github.com/gogearbox/gearbox"
)

func main() {
Expand All @@ -101,12 +102,16 @@ func main() {
// create a logger middleware
logMiddleware := func(ctx gearbox.Context) {
log.Printf("log message!")
ctx.Next() // Next is what allows the request to continue to the next middleware/handler

// 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!")
ctx.Status(gearbox.StatusUnauthorized)
.SendString("You are unauthorized to access this page!")
}

// Register the log middleware for all requests
Expand Down Expand Up @@ -134,7 +139,8 @@ func main() {
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
// 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")
})
Expand Down Expand Up @@ -179,7 +185,7 @@ Check [Our Docs](https://gogearbox.com/docs) for more information about **gearbo
### Sponsors
Organizations that are helping to manage, promote, and support **Gearbox** :gear:

| <img src="https://raw.githubusercontent.com/gogearbox/gearbox/master/assets/trella-sponsor.png"/> |
| [<img src="https://raw.githubusercontent.com/gogearbox/gearbox/master/assets/trella-sponsor.png"/>](https://www.trella.app) |
|:-: |
| [trella](https://www.trella.app): *A B2B technology platform and trucking <br/>marketplace that connects shippers with carriers* |

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (ctx *context) Context() *fasthttp.RequestCtx {
return ctx.requestCtx
}

// SendString sends body of response as a string
// SendString sets body of response as a string
func (ctx *context) SendString(value string) Context {
ctx.requestCtx.SetBodyString(value)
return ctx
Expand All @@ -77,7 +77,7 @@ func (ctx *context) Query(key string) string {
return GetString(ctx.requestCtx.QueryArgs().Peek(key))
}

// Body contains the raw body submitted in a POST request
// Body returns the raw body submitted in a POST request
func (ctx *context) Body() string {
return GetString(ctx.requestCtx.Request.Body())
}
4 changes: 2 additions & 2 deletions gearbox.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package gearbox is a web framework with a focus on high performance and memory optimization
// Package gearbox is a web framework with a focus on high performance
package gearbox

import (
Expand Down Expand Up @@ -328,7 +328,6 @@ func (gb *gearbox) Start(address string) error {
type customLogger struct{}

func (dl *customLogger) Printf(format string, args ...interface{}) {
//log.Printf(format)
}

// newHTTPServer returns a new instance of fasthttp server
Expand Down Expand Up @@ -444,6 +443,7 @@ func (gb *gearbox) Group(prefix string, routes []*Route) []*Route {
return routes
}

// Static serves files in root directory under specific prefix
func (gb *gearbox) Static(prefix, root string) {
if gb.settings.CaseInSensitive {
prefix = strings.ToLower(prefix)
Expand Down
4 changes: 2 additions & 2 deletions gearbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ func TestStart(t *testing.T) {
// TestStartWithTLS tests start service method
func TestStartWithTLS(t *testing.T) {
gb := New(&Settings{
TLSKeyPath: "ssl-cert-snakeoil.key",
TLSCertPath: "ssl-cert-snakeoil.crt",
TLSKeyPath: "./assets/ssl-cert-snakeoil.key",
TLSCertPath: "./assets/ssl-cert-snakeoil.crt",
TLSEnabled: true,
})

Expand Down
2 changes: 2 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (r *router) allowed(reqMethod, path string, ctx *context) string {
var allow string

pathLen := len(path)

// handle * and /* requests
if (pathLen == 1 && path[0] == '*') || (pathLen > 1 && path[1] == '*') {
for method := range r.trees {
if method == MethodOptions {
Expand Down
6 changes: 4 additions & 2 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type nodeType uint8
const (
static nodeType = iota
root
parama
param
catchAll
)

Expand All @@ -21,6 +21,7 @@ type node struct {
handlers handlersChain
}

// addRoute adds a node with the provided handlers to the path
func (n *node) addRoute(path string, handlers handlersChain) {
currentNode := n
originalPath := path
Expand Down Expand Up @@ -74,7 +75,7 @@ func (n *node) addRoute(path string, handlers handlersChain) {
originalPath + "'")
}
} else {
nType = parama
nType = param
if _, ok := paramNames[pathSegment]; ok {
panic("parameter " + pathSegment +
" must be unique in path '" + originalPath + "'")
Expand Down Expand Up @@ -117,6 +118,7 @@ func (n *node) addRoute(path string, handlers handlersChain) {
}
}

// matchRoute returns handlers registered with the given path
func (n *node) matchRoute(path string, ctx *context) handlersChain {
pathLen := len(path)
if pathLen > 0 && path[0] != '/' {
Expand Down

0 comments on commit 334279a

Please sign in to comment.