Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9802ab5e70
|
@ -16,14 +16,16 @@ type Agent struct {
|
||||||
AuthorizedDate int64 `json:"authorizedDate,Number,omitempty"`
|
AuthorizedDate int64 `json:"authorizedDate,Number,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Member member.Member `json:"member,omitempty"`
|
Member member.Member `json:"member,omitempty"`
|
||||||
LastPollingDate int64 `json:"description,omitempty"`
|
LastPollingDate int64 `json:"lastPollingDate,omitempty"`
|
||||||
Status string `json:"Status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAgentService() *AgentService {
|
func NewAgentService() *AgentService {
|
||||||
return &AgentService{}
|
return &AgentService{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func NewAgent(desc string, member member.Member) *Agent {
|
func NewAgent(desc string, member member.Member) *Agent {
|
||||||
|
|
||||||
na := &Agent{
|
na := &Agent{
|
||||||
|
@ -66,3 +68,7 @@ func (as *AgentService) getAgentList(memberId string) (string, error) {
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (as *AgentService) GetModel() (interface{}) {
|
||||||
|
return &Agent{}
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ import (
|
||||||
"git.loafle.net/overflow/commons_go/model/timestamp"
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||||
"git.loafle.net/overflow/overflow_proxy_service/proxy"
|
"git.loafle.net/overflow/overflow_proxy_service/proxy"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
|
||||||
|
"git.loafle.net/overflow/overflow_proxy_service/proxy/agent"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NoAuthAgentService struct {
|
type NoAuthAgentService struct {
|
||||||
|
@ -26,8 +29,6 @@ type NoAuthAgent struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func NewNoAuthAgent(apikey string, localIp int64, hostName string) *NoAuthAgent {
|
func NewNoAuthAgent(apikey string, localIp int64, hostName string) *NoAuthAgent {
|
||||||
|
|
||||||
na := &NoAuthAgent{
|
na := &NoAuthAgent{
|
||||||
|
@ -72,17 +73,23 @@ func(as *NoAuthAgentService)CheckAuth(tempKey string) (string,error) {
|
||||||
|
|
||||||
out := proxy.InvokeDB("noauthAgent", "findByTempKey", memMap);
|
out := proxy.InvokeDB("noauthAgent", "findByTempKey", memMap);
|
||||||
|
|
||||||
|
nn := NoAuthAgent{}
|
||||||
|
err = json.Unmarshal([]byte(out), &nn)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
return out,nil;
|
return out,nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) {
|
func(as *NoAuthAgentService)GetNoAuthList(excludeStatus string) (string,error) {
|
||||||
|
|
||||||
memMap := make(map[string]string)
|
memMap := make(map[string]string)
|
||||||
|
|
||||||
na := NewNoAuthAgent("", 0, "")
|
na := NewNoAuthAgent("", 0, "")
|
||||||
na.AuthStatus = authStatus
|
na.AuthStatus = excludeStatus
|
||||||
|
|
||||||
bytes, err := json.Marshal(na)
|
bytes, err := json.Marshal(na)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -101,3 +108,35 @@ func(as *NoAuthAgentService)GetNoAuthList(authStatus string) (string,error) {
|
||||||
func (as *NoAuthAgentService) GetModel() (interface{}) {
|
func (as *NoAuthAgentService) GetModel() (interface{}) {
|
||||||
return NewNoAuthAgent("", 0, "")
|
return NewNoAuthAgent("", 0, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (as *NoAuthAgentService)RequestAuth(noauthAgt NoAuthAgent, memberId, desc string) (string, error) {
|
||||||
|
paramMap := make(map[string]string)
|
||||||
|
noauthAgt.AuthStatus = "ACCEPT"
|
||||||
|
|
||||||
|
bytes, err := json.Marshal(noauthAgt)
|
||||||
|
if err != nil {
|
||||||
|
return "", err;
|
||||||
|
}
|
||||||
|
paramMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes)
|
||||||
|
out := proxy.InvokeDB("noauthAgent", "update", paramMap)
|
||||||
|
if len(out) == 0 {
|
||||||
|
return "", errors.New("Cannot update Agent. ")
|
||||||
|
}
|
||||||
|
m := member.Member{}
|
||||||
|
m.Id = json.Number(memberId)
|
||||||
|
newAgent := agent.NewAgent(desc, m)
|
||||||
|
newone, err := agent.NewAgentService().SaveAgent(newAgent)
|
||||||
|
if err!= nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newone, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (as *NoAuthAgentService)ReadNoAuthAgent(id string) (string, error){
|
||||||
|
mm := make(map[string]string)
|
||||||
|
mm["id"] = id
|
||||||
|
out := proxy.InvokeDB("noauthAgent", "find", mm)
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,9 +23,9 @@ func TestCreateUUid(t *testing.T) {
|
||||||
|
|
||||||
func TestCreateNoAuthAgent(t *testing.T) {
|
func TestCreateNoAuthAgent(t *testing.T) {
|
||||||
|
|
||||||
na := NewNoAuthAgent("2334278390283", 111, "Snoop")
|
na := NewNoAuthAgent("233421390283", 111, "Snoop")
|
||||||
|
|
||||||
na.TempKey = "22222222"
|
na.TempKey = "1111111"
|
||||||
na.AuthStatus = "WAIT"
|
na.AuthStatus = "WAIT"
|
||||||
|
|
||||||
nas := NewNoAuthAgentService()
|
nas := NewNoAuthAgentService()
|
||||||
|
@ -73,3 +74,32 @@ func TestNoAuthList(t *testing.T) {
|
||||||
t.Log(out)
|
t.Log(out)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRequestAuth(t *testing.T) {
|
||||||
|
nas := NewNoAuthAgentService()
|
||||||
|
res, err := nas.ReadNoAuthAgent("1")
|
||||||
|
|
||||||
|
na := NoAuthAgent{}
|
||||||
|
json.Unmarshal([]byte(res), na)
|
||||||
|
|
||||||
|
newone, err := nas.RequestAuth(na, "1", "test")
|
||||||
|
if err!= nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(newone)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestCheckAuth(t *testing.T) {
|
||||||
|
|
||||||
|
|
||||||
|
ns := NewNoAuthAgentService()
|
||||||
|
|
||||||
|
str, err := ns.CheckAuth("3398473-90847903874")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(str)
|
||||||
|
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ type Target struct {
|
||||||
Kinds string `json:"kinds,omitempty"`
|
Kinds string `json:"kinds,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
Member *member.MemberService `json:"member,omitempty"`
|
Member *member.Member `json:"member,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TargetService struct {
|
type TargetService struct {
|
||||||
|
@ -27,8 +27,15 @@ func NewTargetService() *TargetService {
|
||||||
return &TargetService{}
|
return &TargetService{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TargetService)GetModel() interface{} {
|
||||||
|
return &Target{}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *TargetService)List(tm *Target) string {
|
func (t *TargetService)List(tm *Target) string {
|
||||||
|
|
||||||
|
|
||||||
|
tm.Member.Id = "1"
|
||||||
|
|
||||||
bytes, err := json.Marshal(tm)
|
bytes, err := json.Marshal(tm)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,6 +6,8 @@ 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) {
|
||||||
|
@ -18,7 +20,7 @@ func TestCreateTarget(t *testing.T) {
|
||||||
Kinds:"PostgreSQL",
|
Kinds:"PostgreSQL",
|
||||||
Version:"9.5.0",
|
Version:"9.5.0",
|
||||||
VendorName:"PostgreSQL 9.5.0",
|
VendorName:"PostgreSQL 9.5.0",
|
||||||
Member:&member.MemberService{Id:"1"},
|
Member:&member.Member{Id:"1"},
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := NewTargetService()
|
ts := NewTargetService()
|
||||||
|
@ -32,7 +34,7 @@ func TestCreateTarget(t *testing.T) {
|
||||||
|
|
||||||
func TestFindAll(t *testing.T) {
|
func TestFindAll(t *testing.T) {
|
||||||
tt := Target{
|
tt := Target{
|
||||||
Member:&member.MemberService{Id:"1"},
|
Member:&member.Member{Id:"1"},
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := NewTargetService()
|
ts := NewTargetService()
|
||||||
|
@ -41,3 +43,122 @@ func TestFindAll(t *testing.T) {
|
||||||
str := ts.List(&tt)
|
str := ts.List(&tt)
|
||||||
t.Log(str)
|
t.Log(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MyInt int
|
||||||
|
func TestRefloect(t *testing.T) {
|
||||||
|
|
||||||
|
f := &Foo{
|
||||||
|
FirstName: "Drew",
|
||||||
|
LastName: "Olson",
|
||||||
|
Age: 30,
|
||||||
|
}
|
||||||
|
|
||||||
|
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…
Reference in New Issue
Block a user