mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
service: add service module
This commit is contained in:
1 parent
9ca06ee32f
commit
4e966cc319
8 files changed
+69
-28
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/nadoo/glider/common/log"
|
||||
)
|
||||
|
||||
// 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...)
|
||||
}
|
||||
Reference in new issue
Block a user