Teeny.go, a route system for Go (Golang)

using teeny routing system with golang

Teeny.go (or teenygo or only teeny) is a micro-module for create a micro-webserver with support for routes and routes with patterns similar to PHP and JavaScript web-frameworks

For install use

go get -u github.com/inphinit/teeny.go

Then create a file with any name and extension .go, example foo.go and put this content:

package mainimport (
"fmt"
"net/http"
"github.com/inphinit/teenygo"
)
func main() {
app := teeny.Serve("localhost", 7000)
app.Action("GET", "/", func (response http.ResponseWriter, request *http.Request) {
fmt.Fprint(response, "Homepage")
})
app.Action("GET", "/about", func (response http.ResponseWriter, request *http.Request) {
fmt.Fprint(response, "About page")
})
app.Exec()
}

For execute local serve run this command:

go run foo.go

For build executes:

go build foo.go
foo

This is a very simple example, for access and

Handling Http errors (like )

For handling errors for not defined routes (404 Not Found) and when try access a route with invalid (not defined) method uses , example:

func main() {
app := teeny.Serve("localhost", 7000)
var codes = []int {404, 405} app.HandlerCodes(codes, func (response http.ResponseWriter, request *http.Request, code int) {
fmt.Fprintf(response, "Error %d", code)
})
...
}

Route patterns

For use patterns in router uses , example with and pattern:

app.Params("GET", "/users/<id:num>/<name:alnum>", func (response http.ResponseWriter, request *http.Request, params map[string]string) {
fmt.Fprint(response, "Params:\n")
for key, value := range params {
fmt.Fprintf(response, "%s = %s\n", key, value)
}
})

Supported patterns: https://github.com/inphinit/teeny.go#patterns-supported-by-param-routes-appparams

php, javascript, mysql, python, html5, css3, html, css, jquery / https://inphinit.github.io