|
@@ -2,11 +2,13 @@ package abango
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "io/ioutil"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
e "github.com/dabory/abango-rest/etc"
|
|
e "github.com/dabory/abango-rest/etc"
|
|
"github.com/go-xorm/xorm"
|
|
"github.com/go-xorm/xorm"
|
|
|
|
+ "gopkg.in/yaml.v2"
|
|
)
|
|
)
|
|
|
|
|
|
func (c *Controller) Init() (int, string) {
|
|
func (c *Controller) Init() (int, string) {
|
|
@@ -96,6 +98,69 @@ func (c *Controller) GetYDB() (int, string) {
|
|
return 600, e.LogStr("ADASEF", "DBEngine Open Error")
|
|
return 600, e.LogStr("ADASEF", "DBEngine Open Error")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if status, msg := c.AttachDB(); status != 200 { // DB 까지 붙여야 memory error 가 안난다.
|
|
|
|
+ return status, e.LogStr("PBUYJM-", msg)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 200, ""
|
|
|
|
+ // var connHint string
|
|
|
|
+ // strArr := strings.Split(c.Gtb.ConnString, "@tcp")
|
|
|
|
+ // if len(strArr) == 2 {
|
|
|
|
+ // connHint = strArr[1]
|
|
|
|
+ // } else {
|
|
|
|
+ // return 507, e.LogStr("ASDFQEWFA", "connString format mismatch: "+strArr[1])
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // c.Db.ShowSQL(false)
|
|
|
|
+ // c.Db.SetMaxOpenConns(100)
|
|
|
|
+ // c.Db.SetMaxIdleConns(20)
|
|
|
|
+ // c.Db.SetConnMaxLifetime(60 * time.Second)
|
|
|
|
+ // if _, err := c.Db.IsTableExist("aaa"); err == nil {
|
|
|
|
+ // return 200, e.LogStr("ASDFASFQFE", "YDB connection in "+connHint)
|
|
|
|
+ // } else {
|
|
|
|
+ // return 600, e.LogStr("PMUHIUYBUYJM-", "YDB connection Fail in "+connHint)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type Config struct {
|
|
|
|
+ // GateTokenDev string `yaml:"gate_token_dev"`
|
|
|
|
+ Source GateTokenBase
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type Target struct {
|
|
|
|
+ Type string `yaml:"type"`
|
|
|
|
+ Language string `yaml:"language"`
|
|
|
|
+ OutputDir string `yaml:"output_dir"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (c *Controller) CustomYmlToGateTokenBaseAndDbGet() (int, string) {
|
|
|
|
+ data, err := ioutil.ReadFile("models/custom.yml")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return 507, e.LogStr("ASDFQEWFA", "Can NOT Read custom.yml")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var config Config
|
|
|
|
+ if err := yaml.Unmarshal(data, &config); err == nil {
|
|
|
|
+ c.Gtb = config.Source
|
|
|
|
+ c.Gtb.ConnString = config.Source.ConnStr // custom.yml의 Variable name 이 서로 달라서 복사해줌.
|
|
|
|
+ } else {
|
|
|
|
+ return 507, e.LogStr("ASDWEWFA", "connString in custom.yml format mismatch ")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if c.Db, err = xorm.NewEngine(XConfig["DbType"], c.Gtb.ConnString); err != nil {
|
|
|
|
+ return 600, e.LogStr("ADASEF", "DBEngine Open Error")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if status, msg := c.AttachDB(); status != 200 { // DB 까지 붙여야 memory error 가 안난다.
|
|
|
|
+ return status, e.LogStr("PBUYJM-", msg)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 200, ""
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (c *Controller) AttachDB() (int, string) {
|
|
|
|
+
|
|
var connHint string
|
|
var connHint string
|
|
strArr := strings.Split(c.Gtb.ConnString, "@tcp")
|
|
strArr := strings.Split(c.Gtb.ConnString, "@tcp")
|
|
if len(strArr) == 2 {
|
|
if len(strArr) == 2 {
|
|
@@ -113,6 +178,8 @@ func (c *Controller) GetYDB() (int, string) {
|
|
} else {
|
|
} else {
|
|
return 600, e.LogStr("PMUHIUYBUYJM-", "YDB connection Fail in "+connHint)
|
|
return 600, e.LogStr("PMUHIUYBUYJM-", "YDB connection Fail in "+connHint)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return 200, ""
|
|
}
|
|
}
|
|
|
|
|
|
// func (c *Controller) Init(ask AbangoAsk) {
|
|
// func (c *Controller) Init(ask AbangoAsk) {
|