2020-09-27 19:50:21 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2020-10-01 22:49:14 +08:00
|
|
|
"github.com/nadoo/glider/log"
|
2020-09-27 19:50:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Service is a server that can be run.
|
|
|
|
type Service interface {
|
|
|
|
Run(args ...string)
|
|
|
|
}
|
|
|
|
|
|
|
|
var services = make(map[string]Service)
|
|
|
|
|
|
|
|
// Register is used to register a service.
|
|
|
|
func Register(name string, s Service) {
|
|
|
|
services[strings.ToLower(name)] = s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs a service.
|
|
|
|
func Run(name string, args ...string) {
|
|
|
|
svc, ok := services[strings.ToLower(name)]
|
|
|
|
if !ok {
|
|
|
|
log.F("[service] unknown service name: %s", name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
svc.Run(args...)
|
|
|
|
}
|