A microbiota where to deploy observable Go services. A service can receive and execute commands from the Microb terminal client. Features:
- Remote commands: all services can have remote commands to talk to the Microb server
- Logs: all logs are stored in an sqlite database
- Centrifugo: the websockets server
- Redis: the famous in memory key/value store
A terminal client is used to control Microb instances
go get github.com/synw/microb
Install Centrifugo and Redis
Let's do a hello world service. Create a hello_world
Go package for your service and
a manifest
folder in it.
Create an init.go
file in the manifest folder:
package hello_world
import (
"github.com/synw/microb/libmicrob/types"
)
var Service *types.Service = &types.Service{
"hello_world", // service name
getCmds(), // function to get the service commands
initService, // function to initialize the service
}
func initService(dev bool, start bool) error {
// this service does not need anything
// special for its initialization
return nil
}
Create a cmds.go
file in the manifest folder to define your service commands:
package hello_world
import (
"github.com/synw/microb/libmicrob/types"
)
func getCmds() map[string]*types.Cmd {
cmds := make(map[string]*types.Cmd)
cmds["hello"] = hello()
return cmds
}
func hello() *types.Cmd {
// define the command and attach its running function
cmd := &types.Cmd{Name: "hello", Exec: runHello}
return cmd
}
func runHello(cmd *types.Cmd, c chan *types.Cmd) {
// this function will be run on command call
var resp []interface{}
resp = append(resp, "Hello world")
// the command will return "Hello world"
cmd.ReturnValues = resp
cmd.Status = "success"
c <- cmd
}
Declare the service in Microb: open services/manifest.go
in the Microb package and
add your service:
package services
import (
"github.com/synw/microb/libmicrob/types"
http "github.com/synw/microb-http/manifest"
infos "github.com/synw/microb/services/infos"
hello_world "github.com/me/hello_world/manifest"
)
var Services = map[string]*types.Service{
"infos": infos.Service,
"http": http.Service,
"hello_world": hello_world.Service,
}
Now declare the service client-side: go get github.com/synw/microb-cli
and open
services/manifest.go
to add your service in the same way:
package services
import (
"github.com/synw/microb/libmicrob/types"
http "github.com/synw/microb-http/manifest"
infos "github.com/synw/microb/services/infos"
hello_world "github.com/me/hello_world/manifest"
)
var services = map[string]*types.Service{
// other services
"infos": infos.Service,
"http": http.Service,
// declare my service
"hello_world": hello_world.Service,
}
Update the client and server config.json
to enable your service:
{
...
"services":["infos", "http", "hello_world"]
}
Compile the client and the server and it's ready to use: sending the command hello
from
the client will return "Hello world"
- get: get the last logs
- errors: get the last errors
- warnings: get the last warnings
- cmds: get the last commands
- state: get the last state changes
Example of the http service:
The upper terminal shows the server output and the lower one shows the client output:
- Viper: configuration management
- Centrifuge-go: Centrifugo server side drivers
- Redigo: drivers for Redis
- Gocent: Centrifugo client side drivers
- Fsm: finite state machine lib
- Go-short-id: unique ids generation
- Skittles: terminal colors