diff --git a/gateway/service_test.go b/gateway/service_test.go index b40102d..2dd4d58 100644 --- a/gateway/service_test.go +++ b/gateway/service_test.go @@ -67,35 +67,34 @@ func TestServiceParam(t *testing.T) { // Param *Member `json:"param"` //} -func TestComvertJson(t *testing.T) { +func TestExecServices(t *testing.T) { //res := `{"serviceName":"Member","methodName":"Regist","param":{"email":"geek@loafle.com","password":"qwer5795"}}` + res := `{"email":"geekloafle@loafle.com","pwSalt":"dssdft","company":"loafle"}` + + m := make(map[string]string) + m["model"] = res InitServices() meb, _ := g_services["Member"] - mem := meb.GetModel() - m := make(map[string]string) - - m["email"] = "geek@loafle.com" - m["password"] = "qwer5795" - - //ss := member.NewMemberService() - - - convertParam(mem, m) methodName := reflect.ValueOf(meb).MethodByName("Regist") - in := make([]reflect.Value, methodName.Type().NumIn()) + params := make([]reflect.Value, methodName.Type().NumIn()) + var NewObj reflect.Value for i := 0; i < methodName.Type().NumIn(); i++{ temp := methodName.Type().In(i) - in[i] = reflect.ValueOf(mem) - fmt.Println(temp) + switch temp.Kind() { + case reflect.Ptr: + NewObj = reflect.New(temp.Elem()) + convertParam(NewObj.Interface(), m) + params[i] = NewObj + } } - va := methodName.Call(in)[0].String() - fmt.Println(va) + result := methodName.Call(params)[0].String() + fmt.Println(result) } //func TestReflectType(t *testing.T) { diff --git a/gateway/services.go b/gateway/services.go index 5423aa1..208713c 100644 --- a/gateway/services.go +++ b/gateway/services.go @@ -7,7 +7,6 @@ import ( "github.com/golang/glog" "encoding/json" "reflect" - "fmt" "git.loafle.net/overflow/overflow_proxy_service/proxy/noauthagent" "git.loafle.net/overflow/overflow_proxy_service/proxy/target" //"git.loafle.net/overflow/overflow_proxy_service/proxy/agent" @@ -15,11 +14,11 @@ import ( ) -var g_services map[string]Services +var g_services map[string]interface{} func AddServices(name string, s Services) { if g_services == nil { - g_services = make(map[string]Services,0) + g_services = make(map[string]interface{},0) } g_services[name] = s @@ -30,7 +29,7 @@ type Services interface { } func InitServices() { - g_services = make(map[string]Services,0) + g_services = make(map[string]interface{},0) // proxy services save //AddServices("Agent", agent.NewAgentService()) @@ -51,21 +50,20 @@ func (s *ServiceImpl) ExecServices(c context.Context, in *pb.ServiceInput) (*pb. return nil, errors.New("Not Exist Service Name") } - - glog.Infoln(serviceName.GetModel()) - - model := serviceName.GetModel() - convertParam(model, in.Param) - pbs := &pb.ServiceOutput{} methodName := reflect.ValueOf(serviceName).MethodByName(in.MethodName) params := make([]reflect.Value, methodName.Type().NumIn()) + var NewObj reflect.Value for i := 0; i < methodName.Type().NumIn(); i++{ temp := methodName.Type().In(i) - params[i] = reflect.ValueOf(model) - fmt.Println(temp) + switch temp.Kind() { + case reflect.Ptr: + NewObj = reflect.New(temp.Elem()) + convertParam(NewObj, in.Param) + params[i] = NewObj + } } // Todo Call Service Method