Mu is a microservice framework written in Go. Built on ideas and learnings from real-world microservice development, Mu is designed to be simple, fast, and easy to use.
Mu is highly modular, with functionality divided into small, independent packages. This allows you to pick and choose the features you need, and avoid the bloat of unnecessary dependencies.
The following program is a HTTP microservice that listens on port 8080 and
returns a response when you visit /hello
.
package main
import (
ht "net/http"
"os"
"github.com/neuralnorthwest/mu/config"
"github.com/neuralnorthwest/mu/http"
"github.com/neuralnorthwest/mu/service"
"github.com/neuralnorthwest/mu/worker"
)
func main() {
s, _ := service.New("hello-service")
s.SetupConfig(func(c config.Config) error {
return c.NewString("MESSAGE", "Hello world!", "The message to print")
})
s.SetupWorkers(func(g worker.Group) error {
httpServer, err := http.NewServer()
if err != nil {
return err
}
httpServer.HandleFunc("/hello", func(w ht.ResponseWriter, r *ht.Request) {
s.Logger().Infow("Received request", "method", r.Method, "url", r.URL)
_, _ = w.Write([]byte(s.Config().String("MESSAGE")))
})
return g.Add("http_server", httpServer)
})
if err := s.Main(); err != nil {
os.Exit(1)
}
}
- Hooks - Mu uses hooks to allow you to easily extend the functionality of
the framework. Hooks are called at specific points in the lifecycle of a
microservice. You can use hooks to add custom functionality to your
microservice. The example above uses two hooks,
SetupConfig
andSetupWorkers
. - Configuration - Mu is designed to be configured using environment variables. This allows you to easily configure your microservice using Docker, Kubernetes, or any other container orchestration system.
- Logging - Mu uses the zap logging library. Zap is fast, structured, and easy to use. Mu also provides a mock logger that can be used in tests.
- Workers - Mu is based on the idea of workers. A worker is an independent process that performs a specific task. There are pre-built workers for HTTP servers, gRPC servers, and more. You can also create your own workers to perform any task you need.
- Graceful shutdown - Mu provides a hook for registering cleanup functions that are called when the microservice is shutting down. This allows you to perform any cleanup tasks you need, such as closing database connections, before the microservice exits. Mu automatically handles SIGTERM and SIGINT correctly, and will wait for all workers to finish before exiting.
The following packages have their own README.md
documentation:
The sample microservices in the samples directory also provide examples of how to use Mu.
If you want work on Mu, you can use the following commands to get started:
git clone https://github.com/neuralnorthwest/mu.git
cd mu
make setup-dev
See CONTRIBUTING.md for more information.
See CODE_OF_CONDUCT.md for more information.