A lightweight, zero-codegen library that lets you compose modular HTTP applications in Go.
Define repositories, services, middleware and routes in plain Go code and have them autowired at start-up—no reflection on the hot path, no generated files to commit.
init()
functions—imports are enough.SkipAutoWire
when you prefer to build
instances yourself.http.Engine
interface.go get github.com/mirkobrombin/go-module-router/v1
package main
import (
"time"
"github.com/mirkobrombin/go-module-router/v1/http"
"github.com/mirkobrombin/go-module-router/v1/logger"
"github.com/mirkobrombin/go-module-router/v1/registry"
"github.com/mirkobrombin/go-module-router/v1/router"
_ "example.com/project/core/modules/ping" // ⚙ self-registering module
"go.uber.org/zap"
)
func main() {
zapL, _ := zap.NewDevelopment()
defer zapL.Sync()
eng := http.NewFastHTTP()
lg := &logger.Zap{L: zapL}
router.New(
registry.Global(), // collected during imports
nil, // extra services you built manually
eng, // chosen HTTP engine
router.Options{
SessionDuration: 24 * time.Hour,
Logger: lg,
},
)
if err := eng.Serve(":8080"); err != nil {
lg.Fatal("server terminated", "err", err)
}
}
Note: Importing the package
.../modules/ping
is all that’s required; itsinit()
registers a service, handler and route which the router wires up automatically.
For more detailed information, please refer to the documentation files in the docs/ directory.
Go Module Router is released under the MIT license. See the LICENSE file for the full text.