package service import ( "reflect" cda "git.loafle.net/commons_go/di/annotation" cdr "git.loafle.net/commons_go/di/registry" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" ) func init() { cdr.RegisterType(reflect.TypeOf((*CentralService)(nil)), &cda.ComponentAnnotation{}) } type CentralService struct { CentralClients map[string]oogwc.Client } func (cs *CentralService) PutClient(entryPath string, c oogwc.Client) { cs.CentralClients[entryPath] = c } func (cs *CentralService) Call(entryPath string, result interface{}, method string, params ...interface{}) error { c := cs.GetClient(entryPath) return c.Call(result, method, params...) } func (cs *CentralService) Send(entryPath string, method string, params ...interface{}) error { c := cs.GetClient(entryPath) return c.Send(method, params...) } func (cs *CentralService) GetClient(entryPath string) oogwc.Client { return cs.CentralClients[entryPath] } func (cs *CentralService) CheckClient(entryPath string) bool { c, ok := cs.CentralClients[entryPath] if !ok || nil == c { return false } return true } func (cs *CentralService) Connect(entryPath string) error { // var c oogwc.Client // switch entryPath { // case oocmp.HTTPEntry_Probe: // c = oopccp.NewClient() // case oocmp.HTTPEntry_Data: // c = oopccd.NewClient() // case oocmp.HTTPEntry_File: // c = oopccf.NewClient() // default: // return fmt.Errorf("Gateway entry[%s] is not exist", entryPath) // } // cs.clients[entryPath] = c return nil }