Routing

Overview

Contrary to most Go-Mojito interfaces, this one is not one you inject into a handler. Instead, this interface allows you to register your routes in a consistent way across all router implementations. You can even supply your own router implementation, as long as it has the required feature-set.

  • Built-in Implementation available
  • Can be replaced
  • Multi-Implementation possible
  • Consistent across Implementations

If you want to have multiple routers at the same time, you will need them to listen on different ports.

Quick Start

  1. Create a main.go file which uses the Go-Mojito shortcut functions to register a route on the default router.

    func main() {
        mojito.GET("/", func(ctx mojito.Context) {
            ctx.String("Hello World")
        })
    }
  2. Use the Go-Mojito shortcut function to start the router on 127.0.0.1:8123.

    func main() {
        mojito.GET("/", func(ctx mojito.Context) {
            ctx.String("Hello World")
        })
    
        mojito.ListenAndServe("127.0.0.1:8123")
    }

    You can now visit that address in your browser and you should see "Hello World" on your screen.

FAQ

No frequently asked questions yet!