added
createlist
This commit is contained in:
parent
2fa4f2df2e
commit
6f23666d99
@ -74,17 +74,32 @@ func (t *TargetService)Create(tm *Target) string {
|
|||||||
|
|
||||||
func (t *TargetService)CreateList(tmlist *[]*Target) string {
|
func (t *TargetService)CreateList(tmlist *[]*Target) string {
|
||||||
|
|
||||||
bytes, err := json.Marshal(tmlist)
|
//bytes, err := json.Marshal(tmlist)
|
||||||
|
//
|
||||||
|
//if err != nil {
|
||||||
|
// return ""
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//m := make(map[string]string)
|
||||||
|
//m["java.util.List"] = string(bytes)
|
||||||
|
//
|
||||||
|
//out := proxy.InvokeDB("target", "createAll", m)
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//return out;
|
||||||
|
|
||||||
|
outlist := make([]string, 0)
|
||||||
|
for _, ttt := range *tmlist {
|
||||||
|
out := t.Create(ttt)
|
||||||
|
outlist = append(outlist, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes,err := json.Marshal(outlist)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
m := make(map[string]string)
|
return string(bytes)
|
||||||
m["java.util.List"] = string(bytes)
|
|
||||||
|
|
||||||
out := proxy.InvokeDB("target", "createAll", m)
|
|
||||||
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
@ -6,8 +6,7 @@ import (
|
|||||||
|
|
||||||
|
|
||||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
|
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
|
||||||
"reflect"
|
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateTarget(t *testing.T) {
|
func TestCreateTarget(t *testing.T) {
|
||||||
@ -17,9 +16,10 @@ func TestCreateTarget(t *testing.T) {
|
|||||||
Ip:3232235882,
|
Ip:3232235882,
|
||||||
Port:5432,
|
Port:5432,
|
||||||
TargetType:"DATABASE",
|
TargetType:"DATABASE",
|
||||||
Kinds:"PostgreSQL",
|
Kinds:"PostgreSQL0000000",
|
||||||
Version:"9.5.0",
|
Version:"9.5.0",
|
||||||
VendorName:"PostgreSQL 9.5.0",
|
VendorName:"PostgreSQL 9.5.0",
|
||||||
|
PortType:"TCP",
|
||||||
Member:&member.Member{Id:"1"},
|
Member:&member.Member{Id:"1"},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,121 +44,71 @@ func TestFindAll(t *testing.T) {
|
|||||||
t.Log(str)
|
t.Log(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MyInt int
|
|
||||||
func TestRefloect(t *testing.T) {
|
|
||||||
|
|
||||||
f := &Foo{
|
func TestCreateAll(t *testing.T) {
|
||||||
FirstName: "Drew",
|
|
||||||
LastName: "Olson",
|
tl := make([]*Target, 0)
|
||||||
Age: 30,
|
|
||||||
}
|
tl = append(tl, &Target{
|
||||||
|
Ip:3232235882,
|
||||||
|
Port:5432,
|
||||||
|
TargetType:"DATABASE",
|
||||||
|
Kinds:"PostgreSQL2222",
|
||||||
|
Version:"9.5.0",
|
||||||
|
VendorName:"PostgreSQL 9.5.0",
|
||||||
|
PortType:"TCP",
|
||||||
|
Member:&member.Member{Id:"1"},
|
||||||
|
})
|
||||||
|
|
||||||
|
tl = append(tl, &Target{
|
||||||
|
Ip:3232235882,
|
||||||
|
Port:5432,
|
||||||
|
TargetType:"DATABASE",
|
||||||
|
Kinds:"PostgreSQL3333",
|
||||||
|
Version:"9.5.0",
|
||||||
|
VendorName:"PostgreSQL 9.5.0",
|
||||||
|
PortType:"TCP",
|
||||||
|
Member:&member.Member{Id:"1"},
|
||||||
|
})
|
||||||
|
|
||||||
|
tl = append(tl, &Target{
|
||||||
|
Ip:3232235882,
|
||||||
|
Port:5432,
|
||||||
|
TargetType:"DATABASE",
|
||||||
|
Kinds:"PostgreSQL4444",
|
||||||
|
Version:"9.5.0",
|
||||||
|
VendorName:"PostgreSQL 9.5.0",
|
||||||
|
PortType:"TCP",
|
||||||
|
Member:&member.Member{Id:"1"},
|
||||||
|
})
|
||||||
|
|
||||||
|
tl = append(tl, &Target{
|
||||||
|
Ip:3232235882,
|
||||||
|
Port:5432,
|
||||||
|
TargetType:"DATABASE",
|
||||||
|
Kinds:"PostgreSQL5555",
|
||||||
|
Version:"9.5.0",
|
||||||
|
VendorName:"PostgreSQL 9.5.0",
|
||||||
|
PortType:"TCP",
|
||||||
|
Member:&member.Member{Id:"1"},
|
||||||
|
})
|
||||||
|
|
||||||
|
tl = append(tl, &Target{
|
||||||
|
Ip:3232235882,
|
||||||
|
Port:5432,
|
||||||
|
TargetType:"DATABASE",
|
||||||
|
Kinds:"PostgreSQL6666",
|
||||||
|
Version:"9.5.0",
|
||||||
|
VendorName:"PostgreSQL 9.5.0",
|
||||||
|
PortType:"TCP",
|
||||||
|
Member:&member.Member{Id:"1"},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
ts := NewTargetService()
|
||||||
|
|
||||||
|
|
||||||
|
ts.CreateList(&tl)
|
||||||
|
|
||||||
f.reflect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
FirstName string `tag_name:"tag 1"`
|
|
||||||
LastName string `tag_name:"tag 2"`
|
|
||||||
Age int `tag_name:"tag 3"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Foo) reflect() {
|
|
||||||
val := reflect.ValueOf(f).Elem()
|
|
||||||
|
|
||||||
for i := 0; i < val.NumField(); i++ {
|
|
||||||
valueField := val.Field(i)
|
|
||||||
typeField := val.Type().Field(i)
|
|
||||||
tag := typeField.Tag
|
|
||||||
|
|
||||||
fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n", typeField.Name, valueField.Interface(), tag.Get("tag_name"))
|
|
||||||
}
|
|
||||||
|
|
||||||
for j := 0; j < val.NumMethod(); j++ {
|
|
||||||
|
|
||||||
v := val.Method(j)
|
|
||||||
method := val.Type().Method(j)
|
|
||||||
|
|
||||||
fmt.Println(v)
|
|
||||||
fmt.Println(method)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type YourT1 struct {}
|
|
||||||
func (y YourT1) MethodBar() {
|
|
||||||
//do something
|
|
||||||
}
|
|
||||||
|
|
||||||
type YourT2 struct {}
|
|
||||||
func (y YourT2) MethodFoo(i int, oo string) {
|
|
||||||
//do something
|
|
||||||
}
|
|
||||||
|
|
||||||
func Invoke(any interface{}, name string, args... interface{}) {
|
|
||||||
inputs := make([]reflect.Value, len(args))
|
|
||||||
for i, _ := range args {
|
|
||||||
inputs[i] = reflect.ValueOf(args[i])
|
|
||||||
}
|
|
||||||
reflect.ValueOf(any).MethodByName(name).Call(inputs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRelfect02(t *testing.T) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Invoke(YourT2{}, "MethodFoo", 10, "abc")
|
|
||||||
Invoke(YourT1{}, "MethodBar")
|
|
||||||
}
|
|
||||||
|
|
||||||
type Aaa struct {
|
|
||||||
a string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bbb struct {
|
|
||||||
b int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Handler struct{}
|
|
||||||
|
|
||||||
func (h Handler) GET(a Aaa, b Bbb, ptr *Aaa) string {
|
|
||||||
return "OK" + a.a + " ptr:" + ptr.a
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReflect03(t *testing.T) {
|
|
||||||
handler := new(Handler)
|
|
||||||
|
|
||||||
objects := make(map[reflect.Type]interface{})
|
|
||||||
objects[reflect.TypeOf(Aaa{})] = Aaa{"jkljkL"}
|
|
||||||
objects[reflect.TypeOf(new(Aaa))] = &Aaa{"pointer!"}
|
|
||||||
objects[reflect.TypeOf(Bbb{})] = Bbb{}
|
|
||||||
|
|
||||||
//in := make([]reflect.Value, 0)
|
|
||||||
method := reflect.ValueOf(handler).MethodByName("GET")
|
|
||||||
|
|
||||||
fmt.Println(method)
|
|
||||||
|
|
||||||
in := make([]reflect.Value, method.Type().NumIn())
|
|
||||||
|
|
||||||
fmt.Println("method type num in:", method.Type().NumIn())
|
|
||||||
for i := 0; i < method.Type().NumIn(); i++ {
|
|
||||||
t := method.Type().In(i)
|
|
||||||
|
|
||||||
if i == 0 {
|
|
||||||
intPtr := reflect.New(t)
|
|
||||||
a := intPtr.Elem().Interface().(Aaa)
|
|
||||||
a.a = "aaaddsasdf"
|
|
||||||
fmt.Println(a)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(t)
|
|
||||||
object := objects[t]
|
|
||||||
fmt.Println(i, "->", object)
|
|
||||||
in[i] = reflect.ValueOf(object)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("method type num out:", method.Type().NumOut())
|
|
||||||
|
|
||||||
response := method.Call(in)
|
|
||||||
fmt.Println(response)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user