瀏覽代碼

240526-2326-Kim

EricKIm 6 月之前
父節點
當前提交
9e7d89eb19
共有 1 個文件被更改,包括 67 次插入0 次删除
  1. 67 0
      controller.go

+ 67 - 0
controller.go

@@ -2,11 +2,13 @@ package abango
 
 import (
 	"encoding/json"
+	"io/ioutil"
 	"strings"
 	"time"
 
 	e "github.com/dabory/abango-rest/etc"
 	"github.com/go-xorm/xorm"
+	"gopkg.in/yaml.v2"
 )
 
 func (c *Controller) Init() (int, string) {
@@ -96,6 +98,69 @@ func (c *Controller) GetYDB() (int, string) {
 		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
 	strArr := strings.Split(c.Gtb.ConnString, "@tcp")
 	if len(strArr) == 2 {
@@ -113,6 +178,8 @@ func (c *Controller) GetYDB() (int, string) {
 	} else {
 		return 600, e.LogStr("PMUHIUYBUYJM-", "YDB connection Fail in "+connHint)
 	}
+
+	return 200, ""
 }
 
 // func (c *Controller) Init(ask AbangoAsk) {