return error
This commit is contained in:
snoop 2017-06-08 20:53:04 +09:00
parent eab37e4281
commit 37a2128b45
11 changed files with 226 additions and 122 deletions

View File

@ -2,10 +2,11 @@ package agent
import (
"encoding/json"
"fmt"
"git.loafle.net/overflow/overflow_proxy_service/proxy"
//"fmt"
//"git.loafle.net/overflow/overflow_proxy_service/proxy"
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
"time"
"git.loafle.net/overflow/overflow_proxy_service/proxy/utils"
)
type AgentService struct {
@ -37,35 +38,47 @@ func NewAgent(desc string, member member.Member) *Agent {
}
func (as *AgentService) SaveAgent(agent *Agent) (string, error) {
bytes, err := json.Marshal(agent)
//bytes, err := json.Marshal(agent)
//if err != nil {
// return "", err
//}
//fmt.Println(agent.Member.Id)
//fmt.Println(string(bytes))
//paramMap := make(map[string]string)
//paramMap["com.loafle.overflow.agent.model.Agent"] = string(bytes)
//
//out, err := proxy.InvokeDB("agent", "create", paramMap)
out, err := utils.InvokeDB("agent", "create", agent)
if err != nil {
return "", err
}
fmt.Println(agent.Member.Id)
fmt.Println(string(bytes))
paramMap := make(map[string]string)
paramMap["com.loafle.overflow.agent.model.Agent"] = string(bytes)
out := proxy.InvokeDB("agent", "create", paramMap)
return out, nil
}
func (as *AgentService) getAgentList(memberId string) (string, error) {
paramMap := make(map[string]string)
//paramMap := make(map[string]string)
//
mem := member.NewMember()
mem.Id = json.Number(memberId)
//
//bytes, err := json.Marshal(mem)
//if err != nil {
// return "", err
//}
//
//paramMap["com.loafle.overflow.member.model.Member"] = string(bytes)
//
//out, err := proxy.InvokeDB("agent", "findAgentListByMemberId", paramMap)
out, err := utils.InvokeDBByModel("agent", "findAgentListByMemberId", mem, "com.loafle.overflow.member.model.Member")
bytes, err := json.Marshal(mem)
if err != nil {
return "", err
}
paramMap["com.loafle.overflow.member.model.Member"] = string(bytes)
out := proxy.InvokeDB("agent", "findAgentListByMemberId", paramMap)
return out, nil
}

View File

@ -3,8 +3,9 @@ package apikey
import (
"encoding/json"
"git.loafle.net/overflow/commons_go/model/timestamp"
"git.loafle.net/overflow/overflow_proxy_service/proxy"
"log"
//"git.loafle.net/overflow/overflow_proxy_service/proxy"
//"log"
"git.loafle.net/overflow/overflow_proxy_service/proxy/utils"
)
type ApiKeyService struct {
@ -27,21 +28,27 @@ func NewApiKeyService() *ApiKeyService {
func(k *ApiKeyService)SaveApikey(key *ApiKey) (string, error) {
bytes, err := json.Marshal(key)
//bytes, err := json.Marshal(key)
//
//if err != nil {
// return "", err
//}
//
//m := make(map[string]string)
//
//m["com.loafle.overflow.keystore.model.Apikey"] = string(bytes)
//
//out := proxy.InvokeDB("apiKey", "create", m)
//
//log.Print(out)
out, err := utils.InvokeDBByModel("apiKey", "create", key, "com.loafle.overflow.keystore.model.Apikey")
if err != nil {
return "", err
}
m := make(map[string]string)
m["com.loafle.overflow.keystore.model.Apikey"] = string(bytes)
out := proxy.InvokeDB("apiKey", "create", m)
log.Print(out)
return "", nil
return out, nil
}
@ -51,20 +58,27 @@ func(k *ApiKeyService)CheckApikey(apikey string) (bool, error) {
Apikey:apikey,
}
bytes, err := json.Marshal(ak)
//bytes, err := json.Marshal(ak)
//
//if err != nil {
// return false, err
//}
//
//m := make(map[string]string)
//
//m["com.loafle.overflow.keystore.model.Apikey"] = string(bytes)
//
//out := proxy.InvokeDB("apiKey", "findByApiKey", m)
//
//log.Print(out)
_, err := utils.InvokeDB("apiKey", "findByApiKey", ak)
if err != nil {
return false, err
}
m := make(map[string]string)
m["com.loafle.overflow.keystore.model.Apikey"] = string(bytes)
out := proxy.InvokeDB("apiKey", "findByApiKey", m)
log.Print(out)
return true, nil
}

View File

@ -3,7 +3,7 @@ package crawler
import (
"encoding/json"
"git.loafle.net/overflow/commons_go/model/timestamp"
"git.loafle.net/overflow/overflow_proxy_service/proxy"
//"git.loafle.net/overflow/overflow_proxy_service/proxy"
"git.loafle.net/overflow/overflow_proxy_service/proxy/utils"
)
@ -28,25 +28,31 @@ type Crawler struct {
func (c *CrawlerService)List() string {
func (c *CrawlerService)List() (string, error) {
out := proxy.InvokeDB("crawler", "findAll", nil)
//out := proxy.InvokeDB("crawler", "findAll", nil)
return out
out, err := utils.InvokeDB("crawler", "findAll", nil)
if err != nil {
return "", err
}
return out, nil
}
func (c *CrawlerService)Create(ct * Crawler) string {
func (c *CrawlerService)Create(ct * Crawler) (string, error) {
out, err := utils.InvokeDB("crawler", "create", ct)
if err != nil {
return ""
return "", err
}
return out;
return out, nil
}

View File

@ -24,15 +24,15 @@ func NewCrawlerInputItemService() *CrawlerInputItemSerivce {
func (c *CrawlerInputItemSerivce)Create(cii * CrawlerInputItem) string {
func (c *CrawlerInputItemSerivce)Create(cii * CrawlerInputItem) (string, error) {
out, err := utils.InvokeDB("crawlerInputItem", "create", cii)
if err != nil {
return ""
return "", err
}
return out;
return out, nil;
}

View File

@ -27,29 +27,29 @@ func NewCrawlerInputItemMappingService() *CrawlerInputItemMappingService {
return &CrawlerInputItemMappingService{}
}
func (c *CrawlerInputItemMappingService)Create(ciim *CrawlerInputItemMapping) string {
func (c *CrawlerInputItemMappingService)Create(ciim *CrawlerInputItemMapping) (string, error) {
out, err := utils.InvokeDB("crawlerInputItemMapping", "create", ciim)
if err != nil {
return ""
return "", err
}
return out;
return out, nil;
}
func (c *CrawlerInputItemMappingService)List(cr *crawler.Crawler) string {
func (c *CrawlerInputItemMappingService)List(cr *crawler.Crawler) (string, error) {
out, err := utils.InvokeDBByModel("crawlerInputItemMapping", "findByCrawlerId", cr, "com.loafle.overflow.crawler.model.Crawler")
if err != nil {
return ""
return "", err
}
return out;
return out, nil;
}

View File

@ -7,6 +7,7 @@ import (
"git.loafle.net/overflow/overflow_proxy_service/proxy/apikey"
"git.loafle.net/overflow/overflow_proxy_service/proxy/keystore"
"git.loafle.net/overflow/encryption_go"
"errors"
)
type Member struct {
@ -47,54 +48,63 @@ func (m *MemberService) getMemberMap(mem *Member) map[string]string {
return memMap
}
func (m *MemberService) Login(mem *Member) string {
func (m *MemberService) Login(mem *Member) (string,error) {
result := m.ReadByEmail(mem)
if result == "" {
return "login reject"
return "", errors.New("login reject")
}
temp := Member{}
err := json.Unmarshal([]byte(result), &temp)
if err != nil {
return err.Error()
return "", err
}
if temp.AuthorizedDate == "" {
return "Not authenticated."
return "", errors.New("Not authenticated.")
}
b := encryption.Check(mem.PwSalt, temp.PwSalt, temp.Digest)
if !b {
return "login reject"
return "", errors.New("login reject")
}
return "login success"
return "login success", nil
}
func (m *MemberService) Regist(mem *Member) string {
func (m *MemberService) Regist(mem *Member) (string, error ){
log.Println("Call Regist", mem.Email, mem.PwSalt)
pwSalt, digest, err := encryption.Encrypt(mem.PwSalt)
if err != nil {
log.Fatal("encryption Encrypt Error: ", err)
//log.Fatal("encryption Encrypt Error: ", err)
return "", err
}
mem.PwSalt = pwSalt
mem.Digest = digest
memMap := m.getMemberMap(mem)
re := proxy.InvokeDB(TARGET_DAO, "create", memMap)
re, err := proxy.InvokeDB(TARGET_DAO, "create", memMap)
if err != nil {
return "", err
}
return re
return re, nil
}
func (m *MemberService) ReadByEmail(mem *Member) string {
func (m *MemberService) ReadByEmail(mem *Member) (string, error){
log.Println("Call ReadByEmail", mem.Email)
memMap := m.getMemberMap(mem)
re := proxy.InvokeDB(TARGET_DAO, "findByEmail", memMap)
return re
re, err := proxy.InvokeDB(TARGET_DAO, "findByEmail", memMap)
if err != nil {
return "", err
}
return re, nil
}
func (m *MemberService) Read(mem *Member) string {
func (m *MemberService) Read(mem *Member) (string, error) {
log.Println("Call Read", mem.Email)
// Todo Call DB Gateway
mem.Digest = "qwer5795"
@ -102,54 +112,64 @@ func (m *MemberService) Read(mem *Member) string {
mm := make(map[string]string)
mm["id"] = string(mem.Id)
log.Println("Read Member", m)
re := proxy.InvokeDB(TARGET_DAO, "find", mm)
re, err := proxy.InvokeDB(TARGET_DAO, "find", mm)
return re
if err != nil {
return "", err
}
return re, err
}
func (m *MemberService) Modify(mem *Member) string {
func (m *MemberService) Modify(mem *Member) (string, error) {
log.Println("Call Modify", mem.Email, "::", mem.PwSalt)
// Todo Call DB Gateway
mem.Digest = "read"
memMap := m.getMemberMap(mem)
re := proxy.InvokeDB(TARGET_DAO, "update", memMap)
re, err := proxy.InvokeDB(TARGET_DAO, "update", memMap)
return re
if err != nil {
return "", err
}
return re, nil
}
func (m *MemberService) Remove(mem *Member) string {
func (m *MemberService) Remove(mem *Member) (string, error) {
log.Println("Call Remove", mem.Email)
// Todo Call DB Gateway
//m.Digest = "read"
memMap := m.getMemberMap(mem)
re := proxy.InvokeDB(TARGET_DAO, "delete", memMap)
re, err := proxy.InvokeDB(TARGET_DAO, "delete", memMap)
return re
if err != nil {
return "", err
}
return re, nil
}
func (m *MemberService) GetModel() (interface{}) {
return NewMember()
}
func (m *MemberService) EmailConfirm() string {
func (m *MemberService) EmailConfirm() (string, error) {
ks := keystore.NewKeyStoreSerivce()
key, err := ks.CreateKey()
if err != nil {
return ""
return "", err
}
log.Println(key)
ak := apikey.NewApiKeyService()
out, err := ak.SaveApikey(nil)
_, err = ak.SaveApikey(nil)
if err != nil {
return ""
return "", err
}
log.Println(out)
//log.Println(out)
return "";
return "", nil
}

View File

@ -52,7 +52,11 @@ func(as *NoAuthAgentService)SaveNoAuthAgent(na *NoAuthAgent) (string, error) {
memMap := make(map[string]string)
memMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes);
out := proxy.InvokeDB("noauthAgent", "create", memMap);
out, err := proxy.InvokeDB("noauthAgent", "create", memMap);
if err != nil {
return "", err
}
return out, nil;
}
@ -71,7 +75,11 @@ func(as *NoAuthAgentService)CheckAuth(tempKey string) (string,error) {
memMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes);
out := proxy.InvokeDB("noauthAgent", "findByTempKey", memMap);
out, err := proxy.InvokeDB("noauthAgent", "findByTempKey", memMap);
if err != nil {
return "", err
}
nn := NoAuthAgent{}
err = json.Unmarshal([]byte(out), &nn)
@ -98,16 +106,17 @@ func(as *NoAuthAgentService)GetNoAuthList(excludeStatus string) (string,error) {
memMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes);
out := proxy.InvokeDB("noauthAgent", "findAllByNoAuth", memMap);
out, err := proxy.InvokeDB("noauthAgent", "findAllByNoAuth", memMap);
if err != nil {
return "", err
}
return out,nil;
}
func (as *NoAuthAgentService) GetModel() (interface{}) {
return NewNoAuthAgent("", 0, "")
}
func (as *NoAuthAgentService)RequestAuth(noauthAgt NoAuthAgent, memberId, desc string) (string, error) {
paramMap := make(map[string]string)
@ -118,7 +127,12 @@ func (as *NoAuthAgentService)RequestAuth(noauthAgt NoAuthAgent, memberId, desc s
return "", err;
}
paramMap["com.loafle.overflow.noauthagent.model.NoAuthAgent"] = string(bytes)
out := proxy.InvokeDB("noauthAgent", "update", paramMap)
out, err := proxy.InvokeDB("noauthAgent", "update", paramMap)
if err != nil {
return "", err
}
if len(out) == 0 {
return "", errors.New("Cannot update Agent. ")
}
@ -136,7 +150,11 @@ func (as *NoAuthAgentService)RequestAuth(noauthAgt NoAuthAgent, memberId, desc s
func (as *NoAuthAgentService)ReadNoAuthAgent(id string) (string, error){
mm := make(map[string]string)
mm["id"] = id
out := proxy.InvokeDB("noauthAgent", "find", mm)
out, err := proxy.InvokeDB("noauthAgent", "find", mm)
if err != nil {
return "", err
}
return out, nil
}

View File

@ -9,7 +9,7 @@ import (
)
func InvokeDB(targetDb, methodName string, param map[string]string) (string) {
func InvokeDB(targetDb, methodName string, param map[string]string) (string, error) {
in := &pb.DBInput{}
in.TargetDao = targetDb
@ -19,17 +19,19 @@ func InvokeDB(targetDb, methodName string, param map[string]string) (string) {
conn, err := grpc.Dial(":50006", grpc.WithInsecure())
if err != nil {
log.Fatal("Rpc Error: ", err)
//log.Fatal("Rpc Error: ", err)
return "", err
}
defer conn.Close()
client := pb.NewDBClient(conn)
out, err := client.Exec(context.Background(), in)
if err != nil {
log.Fatal("Rpc Client Error: ", err)
//log.Fatal("Rpc Client Error: ", err)
return "", err
}
log.Print(out)
return out.Result
return out.Result, nil
}

View File

@ -37,26 +37,30 @@ func (t *TargetService)GetModel() interface{} {
return &Target{}
}
func (t *TargetService)List(tm *Target) string {
func (t *TargetService)List(tm *Target) (string, error) {
tm.Member.Id = session.GetSessionMember().Id
bytes, err := json.Marshal(tm)
if err != nil {
return ""
return "", err
}
m := make(map[string]string)
m["com.loafle.overflow.target.model.Target"] = string(bytes)
out := proxy.InvokeDB("target", "findAll", m)
out, err := proxy.InvokeDB("target", "findAll", m)
if err != nil {
return "", err
}
return out;
return out, err;
}
func (t *TargetService)Create(tm *Target) string {
func (t *TargetService)Create(tm *Target) (string,error) {
//bytes, err := json.Marshal(tm)
//
@ -72,15 +76,15 @@ func (t *TargetService)Create(tm *Target) string {
out, err := utils.InvokeDB("target", "create", tm)
if err != nil {
return ""
return "", err
}
return out;
return out, nil
}
func (t *TargetService)CreateAll(tmlist *[]*Target) string {
func (t *TargetService)CreateAll(tmlist *[]*Target) (string,error) {
@ -88,34 +92,43 @@ func (t *TargetService)CreateAll(tmlist *[]*Target) string {
for _, ttt := range *tmlist {
ttt.Member = session.GetSessionMember()
out := t.Create(ttt)
out,err := t.Create(ttt)
if err != nil {
return "", err
}
outlist = append(outlist, out)
}
bytes,err := json.Marshal(outlist)
if err != nil {
return ""
return "", err
}
return string(bytes)
return string(bytes), nil
}
func (t *TargetService)CreateListTT(tmlist *[]*Target) string {
func (t *TargetService)CreateListTT(tmlist *[]*Target) (string, error) {
bytes, err := json.Marshal(tmlist)
if err != nil {
return ""
return "",err
}
m := make(map[string]string)
m["java.util.List"] = string(bytes)
fmt.Println(string(bytes))
out := proxy.InvokeDB("target", "createAll", m)
out, err := proxy.InvokeDB("target", "createAll", m)
if err != nil {
return "", err
}
//
//
return out;
return out, nil;
//return ""
}

View File

@ -7,19 +7,23 @@ import (
func InvokeDB( db string, method string, obj interface{}) (string, error) {
bytes, err := json.Marshal(obj)
if err != nil {
return "", err
var m map[string]string = nil;
if obj != nil {
bytes, err := json.Marshal(obj)
if err != nil {
return "", err
}
m = make(map[string]string)
m[GenerateModelStr(db)] = string(bytes)
}
m := make(map[string]string)
m[GenerateModelStr(db)] = string(bytes)
out, err := proxy.InvokeDB(db, method, m)
out := proxy.InvokeDB(db, method, m)
return out, nil
return out, err
}
func InvokeDBByModel( db string, method string, obj interface{}, model string) (string, error) {
@ -33,8 +37,8 @@ func InvokeDBByModel( db string, method string, obj interface{}, model string) (
m[model] = string(bytes)
out := proxy.InvokeDB(db, method, m)
out, err := proxy.InvokeDB(db, method, m)
return out, nil
return out, err
}

View File

@ -21,4 +21,18 @@ func TestGM(t *testing.T) {
t.Log(GenerateModelStr("target"))
}
func TestNil(t *testing.T) {
var oo interface{}
oo = nil;
if oo == nil {
t.Log("nil!!!")
}
}