From f93fbeea2ff0443ee3184b8e8a883a05da453d48 Mon Sep 17 00:00:00 2001 From: geek Date: Tue, 27 Jun 2017 09:08:47 +0900 Subject: [PATCH] fmt --- gateway/service_test.go | 65 +++++++--------- gateway/services.go | 39 ++++------ gwrpc_main.go | 3 +- proxy/apikey/apikey_service.go | 21 ++--- proxy/apikey/apikey_service_test.go | 2 - proxy/discovery/discovery_service.go | 25 +++--- proxy/discovery/discovery_service_test.go | 3 +- proxy/domain/domain_service.go | 15 ++-- proxy/domain/domain_service_test.go | 7 +- proxy/email/email_service.go | 9 +-- proxy/email/email_service_test.go | 18 ++--- proxy/keystore/keystore_service.go | 4 +- proxy/keystore/keystore_service_test.go | 8 +- proxy/member/member_service.go | 26 +++---- proxy/member/member_service_test.go | 32 ++++---- proxy/meta/meta_noauth_probe_status.go | 14 ++-- proxy/meta/meta_probe_status.go | 12 +-- proxy/meta/meta_probe_task_type.go | 16 ++-- proxy/noauthprobe/noauth_probe_service.go | 78 +++++++++---------- .../noauthprobe/noauth_probe_service_test.go | 11 +-- proxy/probe/probe_service.go | 28 ++++--- proxy/probe/probe_service_test.go | 15 ++-- proxy/probe/probe_task_service.go | 37 +++++---- proxy/probe/probe_task_service_test.go | 9 +-- proxy/sensorItemMapping/sensorItemMapping.go | 4 +- .../sensorItemMapping_test.go | 10 +-- proxy/service.go | 7 +- proxy/session/session.go | 6 +- proxy/utils/DBInvokeUtil.go | 10 +-- proxy/utils/string.go | 5 +- proxy/utils/string_test.go | 10 +-- rpc_main.go | 5 +- server/gwrpc.go | 11 ++- server/rpc.go | 6 +- server/rpc_test.go | 40 ++++------ 35 files changed, 262 insertions(+), 349 deletions(-) diff --git a/gateway/service_test.go b/gateway/service_test.go index 61d9093..b74f079 100644 --- a/gateway/service_test.go +++ b/gateway/service_test.go @@ -1,12 +1,12 @@ package gateway import ( - "testing" - "reflect" - "github.com/stretchr/testify/assert" "encoding/json" - "github.com/golang/glog" "fmt" + "github.com/golang/glog" + "github.com/stretchr/testify/assert" + "reflect" + "testing" "git.loafle.net/overflow/overflow_service/proxy/member" "git.loafle.net/overflow/overflow_service/proxy/target" @@ -26,13 +26,12 @@ func TestServices(t *testing.T) { va := reflect.ValueOf(meb).MethodByName("Regist").Call([]reflect.Value{}) - //reflect.ValueOf(meb).MethodByName("Read").Call(reflect.ValueOf(meb)) assert.Equal(t, 0, len(va)) } -func TestServiceParam(t *testing.T) { +func TestServiceParam(t *testing.T) { InitServices() @@ -42,7 +41,6 @@ func TestServiceParam(t *testing.T) { m["email"] = "geek@loafle.com" m["pw"] = "qwer5795" - paramStr, err := json.Marshal(m) if err != nil { @@ -55,6 +53,7 @@ func TestServiceParam(t *testing.T) { //assert.ObjectsAreEqual(proxy.MemberService{}, meb) } + // //type Member struct { // Email string `json:"email"` @@ -82,7 +81,7 @@ func TestExecServices(t *testing.T) { params := make([]reflect.Value, methodName.Type().NumIn()) var NewObj reflect.Value - for i := 0; i < methodName.Type().NumIn(); i++{ + for i := 0; i < methodName.Type().NumIn(); i++ { temp := methodName.Type().In(i) switch temp.Kind() { @@ -98,22 +97,21 @@ func TestExecServices(t *testing.T) { } //func TestReflectType(t *testing.T) { - //ss := &MemberService{} - ////t1 := reflect.ValueOf(ss.Param).Elem() - // - //ms1 := reflect.New(reflect.TypeOf(ss.Param)).Elem().Type() - // - //fmt.Println(ms1) - ////ss.Param = ms1 - ////ss.Param.Email = "ddd" - ////fmt.Println(ss.Param.Email) - //ms := reflect.New(reflect.ValueOf(ss.Param).Type()).Elem() - //fmt.Printf("created a [%T]\n", reflect.ValueOf(ms).Type()) - +//ss := &MemberService{} +////t1 := reflect.ValueOf(ss.Param).Elem() +// +//ms1 := reflect.New(reflect.TypeOf(ss.Param)).Elem().Type() +// +//fmt.Println(ms1) +////ss.Param = ms1 +////ss.Param.Email = "ddd" +////fmt.Println(ss.Param.Email) +//ms := reflect.New(reflect.ValueOf(ss.Param).Type()).Elem() +//fmt.Printf("created a [%T]\n", reflect.ValueOf(ms).Type()) //} -func TestConvertParamModel(t *testing.T) { +func TestConvertParamModel(t *testing.T) { res := `{"email":"geek@loafle.com","pwSalt":"dssdft","company":"loafle"}` m := make(map[string]string) @@ -133,18 +131,17 @@ func TestParamTypeCreate(t *testing.T) { method := reflect.ValueOf(ms).MethodByName("Regist") - var NewObj reflect.Value; + var NewObj reflect.Value for i := 0; i < method.Type().NumIn(); i++ { tt := method.Type().In(i) t.Log(tt) switch tt.Kind() { - case reflect.Ptr : + case reflect.Ptr: NewObj = reflect.New(tt.Elem()) } - //obj = NewObj.Elem().Interface() //intPtr := reflect.New(tt) @@ -160,40 +157,34 @@ func TestParamTypeCreate(t *testing.T) { params := make([]reflect.Value, method.Type().NumIn()) - params[0] = NewObj; + params[0] = NewObj result := method.Call(params)[0].String() t.Log(result) - - } - func TestListReflect(t *testing.T) { - res := "[{\"id\":1,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496631864025,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":2,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496635285090,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":3,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496642868260,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":4,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496814093714,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":5,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496814103052,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":6,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496814184478,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}}]"; + res := "[{\"id\":1,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496631864025,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":2,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496635285090,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":3,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496642868260,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":4,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496814093714,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":5,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496814103052,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}},{\"id\":6,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496814184478,\"member\":{\"id\":1,\"email\":\"ddddd@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"snnnnn\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}}]" t.Log(res) - ts := target.NewTargetService() - method := reflect.ValueOf(ts).MethodByName("CreateList") - - var NewObj reflect.Value; + var NewObj reflect.Value for i := 0; i < method.Type().NumIn(); i++ { tt := method.Type().In(i) t.Log(tt) switch tt.Kind() { - case reflect.Ptr : + case reflect.Ptr: NewObj = reflect.New(tt.Elem()) - case reflect.Slice : + case reflect.Slice: NewObj = reflect.MakeSlice(tt, 0, 0) } @@ -208,14 +199,12 @@ func TestListReflect(t *testing.T) { params := make([]reflect.Value, method.Type().NumIn()) - params[0] = NewObj; + params[0] = NewObj result := method.Call(params)[0].String() t.Log(result) - //ts.cre } - diff --git a/gateway/services.go b/gateway/services.go index 9bc7fc1..9387c9e 100644 --- a/gateway/services.go +++ b/gateway/services.go @@ -1,45 +1,44 @@ package gateway import ( - "golang.org/x/net/context" + "encoding/json" + "errors" pb "git.loafle.net/overflow/overflow_api_service/grpc" "github.com/golang/glog" - "encoding/json" - "reflect" - "errors" + "golang.org/x/net/context" "log" + "reflect" - "git.loafle.net/overflow/overflow_service/proxy/noauthprobe" - "git.loafle.net/overflow/overflow_service/proxy/target" - "git.loafle.net/overflow/overflow_service/proxy/member" "git.loafle.net/overflow/overflow_service/proxy/crawler" "git.loafle.net/overflow/overflow_service/proxy/crawlerInputItem" "git.loafle.net/overflow/overflow_service/proxy/crawlerinputitemmapping" + "git.loafle.net/overflow/overflow_service/proxy/member" + "git.loafle.net/overflow/overflow_service/proxy/noauthprobe" + "git.loafle.net/overflow/overflow_service/proxy/probe" "git.loafle.net/overflow/overflow_service/proxy/sensor" "git.loafle.net/overflow/overflow_service/proxy/sensorItem" "git.loafle.net/overflow/overflow_service/proxy/sensorItemCategory" "git.loafle.net/overflow/overflow_service/proxy/sensorItemMapping" - "git.loafle.net/overflow/overflow_service/proxy/probe" + "git.loafle.net/overflow/overflow_service/proxy/target" //"google.golang.org/grpc/metadata" - ) var g_services map[string]interface{} -func AddServices(name string, s interface{}) { +func AddServices(name string, s interface{}) { if g_services == nil { - g_services = make(map[string]interface{},0) + g_services = make(map[string]interface{}, 0) } g_services[name] = s } type Services interface { - GetModel()(interface{}) + GetModel() interface{} } -func InitServices() { - g_services = make(map[string]interface{},0) +func InitServices() { + g_services = make(map[string]interface{}, 0) // proxy services save //AddServices("Probe", probe.NewProbeService()) @@ -56,8 +55,8 @@ func InitServices() { AddServices("SensorItemMapping", sensorItemMapping.NewSensorItemMappingService()) } -type ServiceImpl struct { +type ServiceImpl struct { } func (s *ServiceImpl) ExecServices(c context.Context, in *pb.ServiceInput) (*pb.ServiceOutput, error) { @@ -71,12 +70,9 @@ func (s *ServiceImpl) ExecServices(c context.Context, in *pb.ServiceInput) (*pb. return nil, errors.New("Not Exist Service Name") } - - pbs := &pb.ServiceOutput{} methodName := reflect.ValueOf(serviceName).MethodByName(in.MethodName) - if methodName.IsValid() == false { return pbs, errors.New("Not Exist Method Name") } @@ -84,7 +80,7 @@ func (s *ServiceImpl) ExecServices(c context.Context, in *pb.ServiceInput) (*pb. params := make([]reflect.Value, methodName.Type().NumIn()) var NewObj reflect.Value - for i := 0; i < methodName.Type().NumIn(); i++{ + for i := 0; i < methodName.Type().NumIn(); i++ { temp := methodName.Type().In(i) switch temp.Kind() { @@ -96,11 +92,11 @@ func (s *ServiceImpl) ExecServices(c context.Context, in *pb.ServiceInput) (*pb. } // Todo Call Service Method - results := methodName.Call(params); + results := methodName.Call(params) result := results[0].Interface().(string) - var err error = nil; + var err error = nil if len(result) > 1 { obj := results[1].Interface() if obj != nil { @@ -110,7 +106,6 @@ func (s *ServiceImpl) ExecServices(c context.Context, in *pb.ServiceInput) (*pb. } } - pbs.ResultStr = result return pbs, nil diff --git a/gwrpc_main.go b/gwrpc_main.go index 95f8305..1310734 100644 --- a/gwrpc_main.go +++ b/gwrpc_main.go @@ -2,11 +2,10 @@ package main import ( "flag" - "github.com/golang/glog" "git.loafle.net/overflow/overflow_service/server" + "github.com/golang/glog" ) - func main() { flag.Parse() defer glog.Flush() diff --git a/proxy/apikey/apikey_service.go b/proxy/apikey/apikey_service.go index eea7294..84fa407 100644 --- a/proxy/apikey/apikey_service.go +++ b/proxy/apikey/apikey_service.go @@ -9,24 +9,20 @@ import ( ) type ApiKeyService struct { - } type ApiKey struct { - Id json.Number `json:"id,Number,omitempty"` - Apikey string `json:"apiKey,omitempty"` - CreateDAte timestamp.Timestamp`json:"createDate,omitempty"` - HostName string `json:"hostName,omitempty"` + Id json.Number `json:"id,Number,omitempty"` + Apikey string `json:"apiKey,omitempty"` + CreateDAte timestamp.Timestamp `json:"createDate,omitempty"` + HostName string `json:"hostName,omitempty"` } - func NewApiKeyService() *ApiKeyService { return &ApiKeyService{} } - -func(k *ApiKeyService)SaveApikey(key *ApiKey) (string, error) { - +func (k *ApiKeyService) SaveApikey(key *ApiKey) (string, error) { //bytes, err := json.Marshal(key) // @@ -52,10 +48,10 @@ func(k *ApiKeyService)SaveApikey(key *ApiKey) (string, error) { } -func(k *ApiKeyService)CheckApikey(apikey string) (bool, error) { +func (k *ApiKeyService) CheckApikey(apikey string) (bool, error) { ak := ApiKey{ - Apikey:apikey, + Apikey: apikey, } //bytes, err := json.Marshal(ak) @@ -80,5 +76,4 @@ func(k *ApiKeyService)CheckApikey(apikey string) (bool, error) { return true, nil - -} \ No newline at end of file +} diff --git a/proxy/apikey/apikey_service_test.go b/proxy/apikey/apikey_service_test.go index 8555d1a..699d98a 100644 --- a/proxy/apikey/apikey_service_test.go +++ b/proxy/apikey/apikey_service_test.go @@ -1,3 +1 @@ package apikey - - diff --git a/proxy/discovery/discovery_service.go b/proxy/discovery/discovery_service.go index 158ed08..1d6e967 100644 --- a/proxy/discovery/discovery_service.go +++ b/proxy/discovery/discovery_service.go @@ -1,35 +1,32 @@ package discovery import ( - "git.loafle.net/overflow/overflow_service/proxy/probe" - "git.loafle.net/overflow/overflow_service/proxy/meta" "encoding/json" + "git.loafle.net/overflow/overflow_service/proxy/meta" + "git.loafle.net/overflow/overflow_service/proxy/probe" ) type Discovery struct { - StartIp int64 `json:"startIp,omitempty"` - EndIp int64 `json:"endIp,omitempty"` - StartPort int `json:"startPort,omitempty"` - EndPort int `json:"endPort,omitempty"` - ExcludeIp []int64 `json:"excludeIp,omitempty"` - Probe *probe.Probe `json:"probe,omitempty"` + StartIp int64 `json:"startIp,omitempty"` + EndIp int64 `json:"endIp,omitempty"` + StartPort int `json:"startPort,omitempty"` + EndPort int `json:"endPort,omitempty"` + ExcludeIp []int64 `json:"excludeIp,omitempty"` + Probe *probe.Probe `json:"probe,omitempty"` } - type DiscoveryService struct { - } func NewDiscoveryService() *DiscoveryService { return &DiscoveryService{} } - -func (dis *DiscoveryService)Discovery(d *Discovery) (string, error) { +func (dis *DiscoveryService) Discovery(d *Discovery) (string, error) { pts := probe.NewProbeTaskService() - bytes,err := json.Marshal(d) + bytes, err := json.Marshal(d) if err != nil { return "", err @@ -44,4 +41,4 @@ func (dis *DiscoveryService)Discovery(d *Discovery) (string, error) { } return out, nil -} \ No newline at end of file +} diff --git a/proxy/discovery/discovery_service_test.go b/proxy/discovery/discovery_service_test.go index ee5b9fa..ec0c199 100644 --- a/proxy/discovery/discovery_service_test.go +++ b/proxy/discovery/discovery_service_test.go @@ -1,8 +1,8 @@ package discovery import ( - "testing" "git.loafle.net/overflow/overflow_service/proxy/probe" + "testing" ) func TestDiscovery(t *testing.T) { @@ -29,5 +29,4 @@ func TestDiscovery(t *testing.T) { t.Log(out) - } diff --git a/proxy/domain/domain_service.go b/proxy/domain/domain_service.go index 9263ac3..318c36b 100644 --- a/proxy/domain/domain_service.go +++ b/proxy/domain/domain_service.go @@ -7,27 +7,24 @@ import ( ) type Domain struct { - Id json.Number `json:"id,Number,omitempty"` - Name string `json:"name,omitempty"` - CreateDate timestamp.Timestamp `json:"createDate,omitempty"` + Id json.Number `json:"id,Number,omitempty"` + Name string `json:"name,omitempty"` + CreateDate timestamp.Timestamp `json:"createDate,omitempty"` } - type DomainService struct { - } func NewDomainService() *DomainService { return &DomainService{} } +func (d *DomainService) Create(dm *Domain) (string, error) { -func (d *DomainService)Create(dm *Domain) (string, error) { - - str,err :=utils.InvokeDBByModel("domain", "save", dm, "com.loafle.overflow.module.domain.model.Domain") + str, err := utils.InvokeDBByModel("domain", "save", dm, "com.loafle.overflow.module.domain.model.Domain") if err != nil { - return "",err + return "", err } return str, nil diff --git a/proxy/domain/domain_service_test.go b/proxy/domain/domain_service_test.go index 8b46501..1bcaf12 100644 --- a/proxy/domain/domain_service_test.go +++ b/proxy/domain/domain_service_test.go @@ -8,12 +8,11 @@ func TestSave(t *testing.T) { d.Name = "snoop's domain" + str, err := NewDomainService().Create(&d) - str,err := NewDomainService().Create(&d) - - if err != nil{ + if err != nil { t.Fatal(err) } t.Log(str) -} \ No newline at end of file +} diff --git a/proxy/email/email_service.go b/proxy/email/email_service.go index d9b0f1d..14b6584 100644 --- a/proxy/email/email_service.go +++ b/proxy/email/email_service.go @@ -7,13 +7,13 @@ import ( "git.loafle.net/overflow/commons_go/model/timestamp" "git.loafle.net/overflow/overflow_service/proxy" "git.loafle.net/overflow/overflow_service/proxy/member" + "git.loafle.net/overflow/overflow_service/proxy/utils" "github.com/google/uuid" "log" "net" "net/mail" "net/smtp" "strings" - "git.loafle.net/overflow/overflow_service/proxy/utils" ) const ( @@ -148,7 +148,7 @@ func (es *EmailService) SendEmailForAuth(e *Email) error { func (es *EmailService) saveEmail(e *Email) { - rr, err := utils.InvokeDBByModel("emailAuth","save", e, utils.MODEL_EMAIL_AUTH) + rr, err := utils.InvokeDBByModel("emailAuth", "save", e, utils.MODEL_EMAIL_AUTH) if err != nil { log.Fatal(err) @@ -162,13 +162,12 @@ func (es *EmailService) CheckAuthURL(e *Email) bool { //Query from the database with an authentication token. - re, err := utils.InvokeDBByModel("emailAuth","findByEmailAuthKey", e.EmailAuthKey, utils.MODEL_STRING) + re, err := utils.InvokeDBByModel("emailAuth", "findByEmailAuthKey", e.EmailAuthKey, utils.MODEL_STRING) if err != nil { log.Fatal(err) } - tempEmail := &Email{} json.Unmarshal([]byte(re), tempEmail) @@ -190,7 +189,7 @@ func (es *EmailService) CheckAuthURL(e *Email) bool { func (es *EmailService) modifyEmailAuth(e *Email) { proxy.InvokeDB("emailAuth", "update", emMap) - re, err := utils.InvokeDBByModel("emailAuth","save", e, utils.MODEL_EMAIL_AUTH) + re, err := utils.InvokeDBByModel("emailAuth", "save", e, utils.MODEL_EMAIL_AUTH) if err != nil { log.Fatal(err) diff --git a/proxy/email/email_service_test.go b/proxy/email/email_service_test.go index 820091d..6ff98ef 100644 --- a/proxy/email/email_service_test.go +++ b/proxy/email/email_service_test.go @@ -1,23 +1,23 @@ package email import ( - "testing" + "encoding/json" "fmt" "git.loafle.net/overflow/overflow_service/proxy/member" - "encoding/json" + "testing" ) -func getEmailObj() (*Email,*EmailService) { +func getEmailObj() (*Email, *EmailService) { es := NewEmailService() m := member.Member{ - Email:"geek@loafle.com", - Name:"geek", - CompanyName:"loafle", - Id:json.Number("2"), + Email: "geek@loafle.com", + Name: "geek", + CompanyName: "loafle", + Id: json.Number("2"), } e := NewEmail(m, "Hello Oveflow") - return e,es + return e, es } func TestSendEmailForAuth(t *testing.T) { e, es := getEmailObj() @@ -35,7 +35,7 @@ func TestEmailService_CheckAuthURL(t *testing.T) { fmt.Println(rr) } -func TestAuthTokenGeneration(t *testing.T) { +func TestAuthTokenGeneration(t *testing.T) { e, es := getEmailObj() tt := es.generationAuthToken(e) diff --git a/proxy/keystore/keystore_service.go b/proxy/keystore/keystore_service.go index a4d4d89..1de1d63 100644 --- a/proxy/keystore/keystore_service.go +++ b/proxy/keystore/keystore_service.go @@ -6,15 +6,13 @@ import ( ) type KeyStoreService struct { - } - func NewKeyStoreSerivce() *KeyStoreService { return &KeyStoreService{} } -func(k *KeyStoreService)CreateKey() (string,error) { +func (k *KeyStoreService) CreateKey() (string, error) { uu, err := uuid.NewUUID() if err != nil { diff --git a/proxy/keystore/keystore_service_test.go b/proxy/keystore/keystore_service_test.go index 19caae8..72bb1d0 100644 --- a/proxy/keystore/keystore_service_test.go +++ b/proxy/keystore/keystore_service_test.go @@ -2,17 +2,13 @@ package keystore import ( "testing" - ) func TestGetKey(t *testing.T) { - - str, _:= NewKeyStoreSerivce().CreateKey() - + str, _ := NewKeyStoreSerivce().CreateKey() t.Log(str) t.Log(len(str)) - -} \ No newline at end of file +} diff --git a/proxy/member/member_service.go b/proxy/member/member_service.go index 79a7143..bccc160 100644 --- a/proxy/member/member_service.go +++ b/proxy/member/member_service.go @@ -6,19 +6,19 @@ import ( "git.loafle.net/overflow/encryption_go" "git.loafle.net/overflow/overflow_service/proxy/apikey" "git.loafle.net/overflow/overflow_service/proxy/keystore" - "log" "git.loafle.net/overflow/overflow_service/proxy/utils" + "log" ) type Member struct { - Id json.Number `json:"id,Number,omitempty"` - Email string `json:"email"` - PwSalt string `json:"pwSalt"` - Pw string `json:"pw"` - Name string `json:"name"` - CompanyName string `json:"companyName"` - Phone string `json:"phone"` - Status *MetaMemberStatus `json:"status"` + Id json.Number `json:"id,Number,omitempty"` + Email string `json:"email"` + PwSalt string `json:"pwSalt"` + Pw string `json:"pw"` + Name string `json:"name"` + CompanyName string `json:"companyName"` + Phone string `json:"phone"` + Status *MetaMemberStatus `json:"status"` } type MetaMemberStatus struct { @@ -87,7 +87,7 @@ func (m *MemberService) Regist(mem *Member) (string, error) { func (m *MemberService) ReadByEmail(mem *Member) (string, error) { log.Println("Call ReadByEmail", mem.Email) - re, err := utils.InvokeDBByModel(TARGET_DAO, "findByEmail",mem, utils.MODEL_MEMBER) + re, err := utils.InvokeDBByModel(TARGET_DAO, "findByEmail", mem, utils.MODEL_MEMBER) if err != nil { return "", err @@ -98,7 +98,7 @@ func (m *MemberService) ReadByEmail(mem *Member) (string, error) { func (m *MemberService) Read(mem *Member) (string, error) { - re, err := utils.InvokeDBByModel("member","findOne",mem.Id,"java.lang.Long") + re, err := utils.InvokeDBByModel("member", "findOne", mem.Id, "java.lang.Long") if err != nil { return "", err @@ -113,7 +113,7 @@ func (m *MemberService) Modify(mem *Member) (string, error) { log.Fatal("Id nil") } - re, err := utils.InvokeDBByModel("member","findOne",mem,utils.MODEL_MEMBER) + re, err := utils.InvokeDBByModel("member", "findOne", mem, utils.MODEL_MEMBER) if err != nil { return "", err @@ -124,7 +124,7 @@ func (m *MemberService) Modify(mem *Member) (string, error) { func (m *MemberService) Remove(mem *Member) (string, error) { - re, err := utils.InvokeDBByModel("member","delete",mem.Id,"java.lang.Long") + re, err := utils.InvokeDBByModel("member", "delete", mem.Id, "java.lang.Long") if err != nil { return "", err diff --git a/proxy/member/member_service_test.go b/proxy/member/member_service_test.go index 7f73b9f..3b02ce8 100644 --- a/proxy/member/member_service_test.go +++ b/proxy/member/member_service_test.go @@ -1,10 +1,10 @@ package member import ( - "testing" "encoding/json" - "github.com/golang/glog" "fmt" + "github.com/golang/glog" + "testing" ) func TestMemberService_Login(t *testing.T) { @@ -25,13 +25,13 @@ func TestMemberService_Regist(t *testing.T) { ms := NewMemberService() m := &Member{ - Email:"geek2@loafle.com", - PwSalt:"qwer5795", - Pw:"qwer5795", - CompanyName:"Loafle", - Name:"Geek", - Phone:"010-4055-6699", - Status:&MetaMemberStatus{Id:"1"}, + Email: "geek2@loafle.com", + PwSalt: "qwer5795", + Pw: "qwer5795", + CompanyName: "Loafle", + Name: "Geek", + Phone: "010-4055-6699", + Status: &MetaMemberStatus{Id: "1"}, } retMem, _ := ms.Regist(m) t.Log(retMem) @@ -46,8 +46,8 @@ func TestMemberLogin(t *testing.T) { //} ms := NewMemberService() m := &Member{ - Email:"geek@loafle.com", - PwSalt:"qwer5795", + Email: "geek@loafle.com", + PwSalt: "qwer5795", } b, _ := ms.Login(m) @@ -56,7 +56,7 @@ func TestMemberLogin(t *testing.T) { func TestMemberService_Read(t *testing.T) { mm := &Member{ - Id:"1", + Id: "1", } ms := NewMemberService() @@ -69,10 +69,10 @@ func TestMemberService_Read(t *testing.T) { t.Log(rr) } -func TestMemberService_ReadByEmail(t *testing.T) { +func TestMemberService_ReadByEmail(t *testing.T) { ms := NewMemberService() m := &Member{ - Email:"overflow@loafle.com", + Email: "overflow@loafle.com", } rr, err := ms.ReadByEmail(m) @@ -87,7 +87,7 @@ func TestMemberUpdate(t *testing.T) { ms := NewMemberService() m := &Member{ - Id:"1", + Id: "1", } rm, _ := ms.Read(m) @@ -125,4 +125,4 @@ func TestComvertJson(t *testing.T) { // glog.Fatal("Json Unmarshal Failed : ", err.Error()) //} //fmt.Println(mem.(*Member).Email) -} \ No newline at end of file +} diff --git a/proxy/meta/meta_noauth_probe_status.go b/proxy/meta/meta_noauth_probe_status.go index 50a651b..5a2bfc4 100644 --- a/proxy/meta/meta_noauth_probe_status.go +++ b/proxy/meta/meta_noauth_probe_status.go @@ -6,8 +6,8 @@ import ( ) const ( - NOAUTH_PROBE_STATUS_ACCEPT = 1 - NOAUTH_PROBE_STATUS_DENY = 2 + NOAUTH_PROBE_STATUS_ACCEPT = 1 + NOAUTH_PROBE_STATUS_DENY = 2 NOAUTH_PROBE_STATUS_PROCESS = 3 ) @@ -18,8 +18,8 @@ var metaNoauthProbeStatusMap = map[int]string{ } type MetaNoAuthProbeStatus struct { - Id json.Number `json:"id,Number,omitempty"` - Name string `json:"name,omitempty"` + Id json.Number `json:"id,Number,omitempty"` + Name string `json:"name,omitempty"` } func NewMetaNoAuthProbeStatus(types int) *MetaNoAuthProbeStatus { @@ -31,7 +31,7 @@ func NewMetaNoAuthProbeStatus(types int) *MetaNoAuthProbeStatus { } return &MetaNoAuthProbeStatus{ - Id:json.Number(strconv.Itoa(types)), - Name:str, + Id: json.Number(strconv.Itoa(types)), + Name: str, } -} \ No newline at end of file +} diff --git a/proxy/meta/meta_probe_status.go b/proxy/meta/meta_probe_status.go index a8f5d68..c32e090 100644 --- a/proxy/meta/meta_probe_status.go +++ b/proxy/meta/meta_probe_status.go @@ -7,16 +7,17 @@ import ( const ( PROBE_STATUS_INITIAL = 1 - PROBE_STATUS_NORMAL = 2 + PROBE_STATUS_NORMAL = 2 ) + var metaProbeStatusMap = map[int]string{ 1: "INITIAL", 2: "NORMAL", } type MetaProbeStatus struct { - Id json.Number `json:"id,Number,omitempty"` - Name string `json:"name,omitempty"` + Id json.Number `json:"id,Number,omitempty"` + Name string `json:"name,omitempty"` } func NewMetaProbeStatus(types int) *MetaProbeStatus { @@ -27,8 +28,7 @@ func NewMetaProbeStatus(types int) *MetaProbeStatus { return nil } return &MetaProbeStatus{ - Id:json.Number(strconv.Itoa(types)), - Name:str, + Id: json.Number(strconv.Itoa(types)), + Name: str, } } - diff --git a/proxy/meta/meta_probe_task_type.go b/proxy/meta/meta_probe_task_type.go index 066c72c..befc4cd 100644 --- a/proxy/meta/meta_probe_task_type.go +++ b/proxy/meta/meta_probe_task_type.go @@ -6,21 +6,19 @@ import ( "strconv" ) - const ( PROBE_TASK_TYPE_DISOCVERY = 1 - ) + var metaProbeTaskTypeMap = map[int]string{ 1: "DISOCVERY", } - type MetaProbeTaskType struct { - Id json.Number `json:"id,Number,omitempty"` - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - CreateDate timestamp.Timestamp `json:"createDate,omitempty"` + Id json.Number `json:"id,Number,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + CreateDate timestamp.Timestamp `json:"createDate,omitempty"` } func NewMetaProbeTaskType(types int) *MetaProbeTaskType { @@ -31,7 +29,7 @@ func NewMetaProbeTaskType(types int) *MetaProbeTaskType { return nil } return &MetaProbeTaskType{ - Id:json.Number(strconv.Itoa(types)), - Name:str, + Id: json.Number(strconv.Itoa(types)), + Name: str, } } diff --git a/proxy/noauthprobe/noauth_probe_service.go b/proxy/noauthprobe/noauth_probe_service.go index 2e66325..d85f708 100644 --- a/proxy/noauthprobe/noauth_probe_service.go +++ b/proxy/noauthprobe/noauth_probe_service.go @@ -1,16 +1,15 @@ package noauthprobe import ( - "git.loafle.net/overflow/commons_go/model/timestamp" "encoding/json" - "git.loafle.net/overflow/overflow_service/proxy/probe" - "git.loafle.net/overflow/overflow_service/proxy/domain" "errors" - "git.loafle.net/overflow/overflow_service/proxy/utils" + "git.loafle.net/overflow/overflow_service/proxy/domain" "git.loafle.net/overflow/overflow_service/proxy/meta" + "git.loafle.net/overflow/overflow_service/proxy/probe" + "git.loafle.net/overflow/overflow_service/proxy/utils" ) type NoAuthProbeService struct { @@ -20,42 +19,38 @@ func NewNoAuthProbeService() *NoAuthProbeService { return &NoAuthProbeService{} } - type NoAuthProbe struct { - Id json.Number `json:"id,Number,omitempty"` + Id json.Number `json:"id,Number,omitempty"` - HostName string `json:"hostName,omitempty"` - MacAddress int64 `json:"macAddress,omitempty"` - IpAddress int64 `json:"ipAddress,omitempty"` + HostName string `json:"hostName,omitempty"` + MacAddress int64 `json:"macAddress,omitempty"` + IpAddress int64 `json:"ipAddress,omitempty"` // P rocess, A ccept, D eny - Status *meta.MetaNoAuthProbeStatus `json:"status,omitempty"` + Status *meta.MetaNoAuthProbeStatus `json:"status,omitempty"` - TempProbeKey string `json:"tempProbeKey,omitempty"` - - CreateDate timestamp.Timestamp`json:"createDate,omitempty"` - ApiKey string `json:"apiKey,omitempty"` - Domain *domain.Domain `json:"domain,omitempty"` - Probe *probe.Probe `json:"probe,omitempty"` + TempProbeKey string `json:"tempProbeKey,omitempty"` + CreateDate timestamp.Timestamp `json:"createDate,omitempty"` + ApiKey string `json:"apiKey,omitempty"` + Domain *domain.Domain `json:"domain,omitempty"` + Probe *probe.Probe `json:"probe,omitempty"` } - func NewNoAuthProbe(apikey string, ipAddress int64, hostName string, md int64) *NoAuthProbe { na := &NoAuthProbe{ - CreateDate:timestamp.Now(), - ApiKey:apikey, - IpAddress:ipAddress, - HostName:hostName, - MacAddress:md, - Status:meta.NewMetaNoAuthProbeStatus(meta.NOAUTH_PROBE_STATUS_PROCESS), + CreateDate: timestamp.Now(), + ApiKey: apikey, + IpAddress: ipAddress, + HostName: hostName, + MacAddress: md, + Status: meta.NewMetaNoAuthProbeStatus(meta.NOAUTH_PROBE_STATUS_PROCESS), } return na } - -func(as *NoAuthProbeService)Regist(na *NoAuthProbe) (string, error) { +func (as *NoAuthProbeService) Regist(na *NoAuthProbe) (string, error) { out, err := utils.InvokeDBByModel("noauthProbe", "save", na, utils.MODEL_NOAUTHPROBE) @@ -63,10 +58,10 @@ func(as *NoAuthProbeService)Regist(na *NoAuthProbe) (string, error) { return "", err } - return out, nil; + return out, nil } -func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) { +func (as *NoAuthProbeService) CheckAuth(tempKey string) (string, error) { //memMap := make(map[string]string) // @@ -82,7 +77,7 @@ func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) { // //out, err := proxy.InvokeDB("noauthProbe", "findByTempKey", memMap); - out, err:= utils.InvokeDBByModel("noauthProbe","findByTempProbeKey",tempKey, utils.MODEL_STRING) + out, err := utils.InvokeDBByModel("noauthProbe", "findByTempProbeKey", tempKey, utils.MODEL_STRING) if err != nil { return "", err @@ -95,24 +90,21 @@ func(as *NoAuthProbeService)CheckAuth(tempKey string) (string,error) { return "", err } - return out,nil; + return out, nil } +func (as *NoAuthProbeService) ReadAllByDomain(d *domain.Domain) (string, error) { -func(as *NoAuthProbeService)ReadAllByDomain(d *domain.Domain) (string,error) { - - out, err := utils.InvokeDBByModel("noauthProbe","findAllByDomain", d, utils.MODEL_DOMAIN); + out, err := utils.InvokeDBByModel("noauthProbe", "findAllByDomain", d, utils.MODEL_DOMAIN) if err != nil { return "", err } - return out,nil; + return out, nil } - - -func (as *NoAuthProbeService)RequestAuth(np *NoAuthProbe, domainId int, desc string) (string, error) { +func (as *NoAuthProbeService) RequestAuth(np *NoAuthProbe, domainId int, desc string) (string, error) { //paramMap := make(map[string]string) //noauthAgt.Status = "A" // @@ -123,7 +115,7 @@ func (as *NoAuthProbeService)RequestAuth(np *NoAuthProbe, domainId int, desc str //paramMap["com.loafle.overflow.noauthprobe.model.NoAuthProbe"] = string(bytes) //out, err := proxy.InvokeDB("noauthProbe", "update", paramMap) - out ,err := utils.InvokeDBByModel("noauthProbe","findByTempProbeKey", np.TempProbeKey, utils.MODEL_STRING); + out, err := utils.InvokeDBByModel("noauthProbe", "findByTempProbeKey", np.TempProbeKey, utils.MODEL_STRING) if err != nil { return "", err @@ -133,12 +125,12 @@ func (as *NoAuthProbeService)RequestAuth(np *NoAuthProbe, domainId int, desc str } dbnp := NoAuthProbe{} - err = json.Unmarshal([]byte(out), &dbnp); + err = json.Unmarshal([]byte(out), &dbnp) if err != nil { return "", err } - dbnp.Status = np.Status; + dbnp.Status = np.Status //FIXME:: probe @@ -146,23 +138,23 @@ func (as *NoAuthProbeService)RequestAuth(np *NoAuthProbe, domainId int, desc str d.Id = json.Number(domainId) newAgent := probe.NewProbe("", "") newone, err := probe.NewProbeService().Regist(newAgent) - if err!= nil { + if err != nil { return "", err } return newone, nil } -func (as *NoAuthProbeService)Read(id string) (string, error){ +func (as *NoAuthProbeService) Read(id string) (string, error) { //mm := make(map[string]string) //mm["id"] = id //out, err := proxy.InvokeDB("noauthProbe", "findOne", id, "java.lang.Long") - out,err :=utils.InvokeDBByModel("noauthProbe","findOne",id,utils.MODEL_LONG) + out, err := utils.InvokeDBByModel("noauthProbe", "findOne", id, utils.MODEL_LONG) if err != nil { return "", err } return out, nil -} \ No newline at end of file +} diff --git a/proxy/noauthprobe/noauth_probe_service_test.go b/proxy/noauthprobe/noauth_probe_service_test.go index 8707fcf..06962ed 100644 --- a/proxy/noauthprobe/noauth_probe_service_test.go +++ b/proxy/noauthprobe/noauth_probe_service_test.go @@ -1,6 +1,5 @@ package noauthprobe - import ( "github.com/google/uuid" "testing" @@ -10,7 +9,6 @@ import ( "git.loafle.net/overflow/overflow_service/proxy/meta" ) - func TestCreateUUid(t *testing.T) { uu, err := uuid.NewUUID() @@ -22,12 +20,12 @@ func TestCreateUUid(t *testing.T) { t.Log(uu) } + // func TestCreateNoAuthAgent(t *testing.T) { na := NewNoAuthProbe("52abd6fd57e511e7ac52080027658d13", 3232235521, "Snoop2222", 8796753988883) - ns := &meta.MetaNoAuthProbeStatus{} ns.Id = "3" na.Status = ns @@ -49,6 +47,7 @@ func TestCreateNoAuthAgent(t *testing.T) { t.Log(out) } + // //func TestCheckAuthNoAuthAgent(t *testing.T) { // @@ -69,10 +68,8 @@ func TestCreateNoAuthAgent(t *testing.T) { // // //} - func TestNoAuthList(t *testing.T) { - nas := NewNoAuthProbeService() d := domain.Domain{} @@ -87,6 +84,7 @@ func TestNoAuthList(t *testing.T) { t.Log(out) } + // //func TestRequestAuth(t *testing.T) { // nas := NewNoAuthProbeService() @@ -102,10 +100,8 @@ func TestNoAuthList(t *testing.T) { // t.Log(newone) //} - func TestCheckAuth(t *testing.T) { - ns := NewNoAuthProbeService() str, err := ns.CheckAuth("3398473-90847903874") @@ -117,7 +113,6 @@ func TestCheckAuth(t *testing.T) { } - func TestRead(t *testing.T) { out, err := NewNoAuthProbeService().Read("1") diff --git a/proxy/probe/probe_service.go b/proxy/probe/probe_service.go index 2be6581..728e7b3 100644 --- a/proxy/probe/probe_service.go +++ b/proxy/probe/probe_service.go @@ -7,26 +7,25 @@ import ( "git.loafle.net/overflow/overflow_service/proxy/utils" - "git.loafle.net/overflow/overflow_service/proxy/meta" "git.loafle.net/overflow/commons_go/model/timestamp" "git.loafle.net/overflow/overflow_service/proxy/domain" + "git.loafle.net/overflow/overflow_service/proxy/meta" ) type ProbeService struct { } type Probe struct { - Id json.Number `json:"id,Number,omitempty"` - Status *meta.MetaProbeStatus `json:"status,omitempty"` - CreateDate timestamp.Timestamp `json:"createDate,omitempty"` - LastPollingDate timestamp.Timestamp `json:"lastPollingDate,omitempty"` - NextPollingDate timestamp.Timestamp `json:"nextPollingDate,omitempty"` - Domain *domain.Domain `json:"domain,omitempty"` - ProbeKey string `json:"probeKey,omitempty"` - EncryptionKey string `json:"encryptionKey,omitempty"` + Id json.Number `json:"id,Number,omitempty"` + Status *meta.MetaProbeStatus `json:"status,omitempty"` + CreateDate timestamp.Timestamp `json:"createDate,omitempty"` + LastPollingDate timestamp.Timestamp `json:"lastPollingDate,omitempty"` + NextPollingDate timestamp.Timestamp `json:"nextPollingDate,omitempty"` + Domain *domain.Domain `json:"domain,omitempty"` + ProbeKey string `json:"probeKey,omitempty"` + EncryptionKey string `json:"encryptionKey,omitempty"` } - func NewProbeService() *ProbeService { return &ProbeService{} } @@ -34,10 +33,9 @@ func NewProbeService() *ProbeService { func NewProbe(probeKey string, encryptionKey string) *Probe { na := &Probe{ - Status:meta.NewMetaProbeStatus(meta.PROBE_STATUS_INITIAL), - ProbeKey:probeKey, - EncryptionKey:encryptionKey, - + Status: meta.NewMetaProbeStatus(meta.PROBE_STATUS_INITIAL), + ProbeKey: probeKey, + EncryptionKey: encryptionKey, } return na } @@ -73,4 +71,4 @@ func (as *ProbeService) ReadByProbeKey(probeKey string) (string, error) { } return out, nil -} \ No newline at end of file +} diff --git a/proxy/probe/probe_service_test.go b/proxy/probe/probe_service_test.go index 7770bc0..34ccdc8 100644 --- a/proxy/probe/probe_service_test.go +++ b/proxy/probe/probe_service_test.go @@ -1,13 +1,10 @@ package probe import ( - "testing" - "git.loafle.net/overflow/overflow_service/proxy/keystore" "git.loafle.net/overflow/overflow_service/proxy/domain" - - + "git.loafle.net/overflow/overflow_service/proxy/keystore" ) func TestSaveProbe(t *testing.T) { @@ -17,7 +14,7 @@ func TestSaveProbe(t *testing.T) { enks, _ := ks.CreateKey() ppp := NewProbe(pks, enks) - ppp.Domain = &domain.Domain{Id:"1"} + ppp.Domain = &domain.Domain{Id: "1"} as := NewProbeService() res, err := as.Regist(ppp) @@ -30,12 +27,11 @@ func TestSaveProbe(t *testing.T) { func TestListProbe(t *testing.T) { as := NewProbeService() - d := &domain.Domain{Id:"1"} - + d := &domain.Domain{Id: "1"} if res, err := as.ReadAllByDomain(d); err != nil { t.Fatal(err) - }else { + } else { t.Log(res) } @@ -55,7 +51,6 @@ func TestReadProbeKey(t *testing.T) { } - func TestDDDD(t *testing.T) { -} \ No newline at end of file +} diff --git a/proxy/probe/probe_task_service.go b/proxy/probe/probe_task_service.go index 3565ee5..10d568c 100644 --- a/proxy/probe/probe_task_service.go +++ b/proxy/probe/probe_task_service.go @@ -2,44 +2,43 @@ package probe import ( "encoding/json" - "git.loafle.net/overflow/overflow_service/proxy/meta" "git.loafle.net/overflow/commons_go/model/timestamp" + "git.loafle.net/overflow/overflow_service/proxy/meta" "git.loafle.net/overflow/overflow_service/proxy/utils" ) type ProbeTask struct { - Id json.Number `json:"id,Number,omitempty"` - MetaProbeTaskType *meta.MetaProbeTaskType `json:"metaProbeTaskType,omitempty"` - Probe *Probe `json:"probe,omitempty"` - Data string `json:"data,omitempty"` - CreateDate timestamp.Timestamp `json:"createDate,omitempty"` - SendDate timestamp.Timestamp `json:"sendDate,omitempty"` - StartDate timestamp.Timestamp `json:"startDate,omitempty"` - EndDate timestamp.Timestamp `json:"startDate,omitempty"` - Succeed bool `json:"succeed,omitempty"` + Id json.Number `json:"id,Number,omitempty"` + MetaProbeTaskType *meta.MetaProbeTaskType `json:"metaProbeTaskType,omitempty"` + Probe *Probe `json:"probe,omitempty"` + Data string `json:"data,omitempty"` + CreateDate timestamp.Timestamp `json:"createDate,omitempty"` + SendDate timestamp.Timestamp `json:"sendDate,omitempty"` + StartDate timestamp.Timestamp `json:"startDate,omitempty"` + EndDate timestamp.Timestamp `json:"startDate,omitempty"` + Succeed bool `json:"succeed,omitempty"` } func NewProbeTask(types *meta.MetaProbeTaskType, data string, p *Probe) *ProbeTask { return &ProbeTask{ - MetaProbeTaskType:types, - Data:data, - Probe:p, + MetaProbeTaskType: types, + Data: data, + Probe: p, } } type ProbeTaskService struct { - } -func NewProbeTaskService() *ProbeTaskService{ +func NewProbeTaskService() *ProbeTaskService { return &ProbeTaskService{} } -func(pts* ProbeTaskService)Regist(pt *ProbeTask) (string, error) { +func (pts *ProbeTaskService) Regist(pt *ProbeTask) (string, error) { - out, err := utils.InvokeDBByModel("probeTask","save", pt, utils.MODEL_PROBE_TASK) + out, err := utils.InvokeDBByModel("probeTask", "save", pt, utils.MODEL_PROBE_TASK) if err != nil { return "", err @@ -48,9 +47,9 @@ func(pts* ProbeTaskService)Regist(pt *ProbeTask) (string, error) { return out, nil } -func(pts* ProbeTaskService)ReadAllByProbe(p *Probe) (string, error) { +func (pts *ProbeTaskService) ReadAllByProbe(p *Probe) (string, error) { - out, err := utils.InvokeDBByModel("probeTask","findAllByProbe", p, utils.MODEL_PROBE) + out, err := utils.InvokeDBByModel("probeTask", "findAllByProbe", p, utils.MODEL_PROBE) if err != nil { return "", err diff --git a/proxy/probe/probe_task_service_test.go b/proxy/probe/probe_task_service_test.go index 7d4965e..1d441a9 100644 --- a/proxy/probe/probe_task_service_test.go +++ b/proxy/probe/probe_task_service_test.go @@ -1,8 +1,8 @@ package probe import ( - "testing" "git.loafle.net/overflow/overflow_service/proxy/meta" + "testing" ) func TestCreate(t *testing.T) { @@ -17,14 +17,13 @@ func TestCreate(t *testing.T) { out, err := pts.Regist(pt) - if err != nil{ + if err != nil { t.Fatal(err) } t.Log(out) } - func TestListByProbe(t *testing.T) { p := &Probe{} @@ -40,6 +39,4 @@ func TestListByProbe(t *testing.T) { t.Log(out) - - -} \ No newline at end of file +} diff --git a/proxy/sensorItemMapping/sensorItemMapping.go b/proxy/sensorItemMapping/sensorItemMapping.go index 53f6095..a85ccb3 100644 --- a/proxy/sensorItemMapping/sensorItemMapping.go +++ b/proxy/sensorItemMapping/sensorItemMapping.go @@ -35,14 +35,14 @@ func (sims *SensorItemMappingService) CreateAll(siml *[]*SensorItemMapping) (str outlist := make([]string, 0) for _, sim := range *siml { - out,err := sims.Create(sim) + out, err := sims.Create(sim) if err != nil { return "", err } outlist = append(outlist, out) } - bytes,err := json.Marshal(outlist) + bytes, err := json.Marshal(outlist) if err != nil { return "", err diff --git a/proxy/sensorItemMapping/sensorItemMapping_test.go b/proxy/sensorItemMapping/sensorItemMapping_test.go index d548ef2..c8526ca 100644 --- a/proxy/sensorItemMapping/sensorItemMapping_test.go +++ b/proxy/sensorItemMapping/sensorItemMapping_test.go @@ -2,11 +2,11 @@ package sensorItemMapping import ( "encoding/json" - "git.loafle.net/overflow/overflow_service/proxy/sensor" - "testing" "fmt" - "sync" + "git.loafle.net/overflow/overflow_service/proxy/sensor" "strconv" + "sync" + "testing" ) func TestSensorItemMappingService_List(t *testing.T) { @@ -19,7 +19,6 @@ func TestSensorItemMappingService_List(t *testing.T) { t.Log(res) } - func TestSensorItemMappingService_List_GoRutine(t *testing.T) { //s := &sensor.Sensor{} //s.Id = json.Number("14") @@ -36,7 +35,6 @@ func TestSensorItemMappingService_List_GoRutine(t *testing.T) { for _, ii := range il { - go func(i int) { s := &sensor.Sensor{} s.Id = json.Number(strconv.Itoa(ii)) @@ -44,14 +42,12 @@ func TestSensorItemMappingService_List_GoRutine(t *testing.T) { fmt.Print(res) }(ii) - } wg := sync.WaitGroup{} wg.Add(1) - wg.Wait() //res, _ := sims.List(s) diff --git a/proxy/service.go b/proxy/service.go index 95b669a..a42b230 100644 --- a/proxy/service.go +++ b/proxy/service.go @@ -1,14 +1,12 @@ package proxy import ( - "log" pb "git.loafle.net/overflow/overflow_api_db/build/golang" - "google.golang.org/grpc" "golang.org/x/net/context" - + "google.golang.org/grpc" + "log" ) - func InvokeDB(targetDb, methodName string, param map[string]string) (string, error) { in := &pb.DBInput{} @@ -34,4 +32,3 @@ func InvokeDB(targetDb, methodName string, param map[string]string) (string, err return out.Result, nil } - diff --git a/proxy/session/session.go b/proxy/session/session.go index a765a2c..96550d9 100644 --- a/proxy/session/session.go +++ b/proxy/session/session.go @@ -6,7 +6,7 @@ import "git.loafle.net/overflow/overflow_service/proxy/member" func GetSessionMember() *member.Member { m := member.NewMember() - m.Id = "1"; + m.Id = "1" - return m; -} \ No newline at end of file + return m +} diff --git a/proxy/utils/DBInvokeUtil.go b/proxy/utils/DBInvokeUtil.go index 3a130ee..efc7060 100644 --- a/proxy/utils/DBInvokeUtil.go +++ b/proxy/utils/DBInvokeUtil.go @@ -6,9 +6,9 @@ import ( ) // Deprecated: package rule changed...T__T -func InvokeDB( db string, method string, obj interface{}) (string, error) { +func InvokeDB(db string, method string, obj interface{}) (string, error) { - var m map[string]string = nil; + var m map[string]string = nil if obj != nil { bytes, err := json.Marshal(obj) @@ -21,13 +21,12 @@ func InvokeDB( db string, method string, obj interface{}) (string, error) { m[GenerateModelStr(db)] = string(bytes) } - out, err := proxy.InvokeDB(db, method, m) return out, err } -func InvokeDBByModel( db string, method string, obj interface{}, model string) (string, error) { +func InvokeDBByModel(db string, method string, obj interface{}, model string) (string, error) { bytes, err := json.Marshal(obj) if err != nil { @@ -40,6 +39,5 @@ func InvokeDBByModel( db string, method string, obj interface{}, model string) ( out, err := proxy.InvokeDB(db, method, m) - return out, err -} \ No newline at end of file +} diff --git a/proxy/utils/string.go b/proxy/utils/string.go index 883fc9d..08741bb 100644 --- a/proxy/utils/string.go +++ b/proxy/utils/string.go @@ -3,7 +3,7 @@ package utils import "strings" const ( - defaultPackage = "com.loafle.overflow." + defaultPackage = "com.loafle.overflow." modelPackageName = ".model." ) @@ -11,11 +11,10 @@ func GenerateModelStr(model string) string { tm := strings.Title(model) - res := defaultPackage res += model res += modelPackageName res += tm return res -} \ No newline at end of file +} diff --git a/proxy/utils/string_test.go b/proxy/utils/string_test.go index 63c6580..5ecc688 100644 --- a/proxy/utils/string_test.go +++ b/proxy/utils/string_test.go @@ -1,8 +1,8 @@ package utils import ( - "testing" "strings" + "testing" ) func TestStringUpper(t *testing.T) { @@ -11,10 +11,8 @@ func TestStringUpper(t *testing.T) { aa := strings.Title(res) - t.Log(aa) - } func TestGM(t *testing.T) { @@ -23,16 +21,14 @@ func TestGM(t *testing.T) { } - func TestNil(t *testing.T) { var oo interface{} - oo = nil; + oo = nil if oo == nil { t.Log("nil!!!") } - -} \ No newline at end of file +} diff --git a/rpc_main.go b/rpc_main.go index 36f8bc2..9ade698 100644 --- a/rpc_main.go +++ b/rpc_main.go @@ -1,13 +1,12 @@ package main import ( - "git.loafle.net/overflow/overflow_service/gateway" "flag" - "github.com/golang/glog" + "git.loafle.net/overflow/overflow_service/gateway" "git.loafle.net/overflow/overflow_service/server" + "github.com/golang/glog" ) - func main() { flag.Parse() defer glog.Flush() diff --git a/server/gwrpc.go b/server/gwrpc.go index d0d82c2..1456a0e 100644 --- a/server/gwrpc.go +++ b/server/gwrpc.go @@ -2,13 +2,13 @@ package server import ( "flag" - "golang.org/x/net/context" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "google.golang.org/grpc" pb "git.loafle.net/overflow/overflow_api_service/grpc" + "github.com/golang/glog" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "golang.org/x/net/context" + "google.golang.org/grpc" "net/http" "strings" - "github.com/golang/glog" ) var ( @@ -32,7 +32,6 @@ func RunGwRpc() (err error) { return http.ListenAndServe(":8080", allowCORS(mux)) } - //https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/main.go func allowCORS(h http.Handler) http.Handler { @@ -55,4 +54,4 @@ func preflightHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Methods", strings.Join(methods, ",")) glog.Infof("preflight request for %s", r.URL.Path) return -} \ No newline at end of file +} diff --git a/server/rpc.go b/server/rpc.go index a58f5c1..f05c531 100644 --- a/server/rpc.go +++ b/server/rpc.go @@ -1,10 +1,10 @@ package server import ( - "net" - "google.golang.org/grpc" pb "git.loafle.net/overflow/overflow_api_service/grpc" "git.loafle.net/overflow/overflow_service/gateway" + "google.golang.org/grpc" + "net" ) func RunRpc() error { @@ -20,4 +20,4 @@ func RunRpc() error { s.Serve(l) return nil -} \ No newline at end of file +} diff --git a/server/rpc_test.go b/server/rpc_test.go index 0cb5853..765c07c 100644 --- a/server/rpc_test.go +++ b/server/rpc_test.go @@ -1,23 +1,23 @@ package server import ( - "testing" - "git.loafle.net/overflow/overflow_gateway_service/gateway" - "flag" - "github.com/golang/glog" - "time" - "fmt" - "os" - "net/http" "bytes" + "flag" + "fmt" + pb "git.loafle.net/overflow/overflow_api_service/grpc" + "git.loafle.net/overflow/overflow_gateway_service/gateway" + "github.com/golang/glog" + "golang.org/x/net/context" + "google.golang.org/grpc" "io/ioutil" "log" - "google.golang.org/grpc" - pb "git.loafle.net/overflow/overflow_api_service/grpc" - "golang.org/x/net/context" + "net/http" + "os" + "testing" + "time" ) -func startRpcServerTest() <- chan error{ +func startRpcServerTest() <-chan error { ch := make(chan error, 2) go func() { if err := RunRpc(); err != nil { @@ -74,34 +74,30 @@ func TestRpcServer(t *testing.T) { errch := startRpcServerTest() - chStr := make(chan string , 1) + chStr := make(chan string, 1) go func() { chStr <- callGatewayRpc() }() - select { - case err := <- errch: + case err := <-errch: log.Println(err) os.Exit(1) case status := <-chStr: - log.Println( status) + log.Println(status) os.Exit(1) } } - func TestRPC(t *testing.T) { - - conn, err := grpc.Dial(":9090", grpc.WithInsecure()); + conn, err := grpc.Dial(":9090", grpc.WithInsecure()) if err != nil { t.Log(err) } - client := pb.NewOverflowGatewayClient(conn) si := pb.ServiceInput{} @@ -114,6 +110,4 @@ func TestRPC(t *testing.T) { t.Log(so.ResultStr) - - -} \ No newline at end of file +}