正在显示
11 个修改的文件
包含
80 行增加
和
11 行删除
@@ -13,4 +13,7 @@ ENV GOPROXY https://goproxy.cn | @@ -13,4 +13,7 @@ ENV GOPROXY https://goproxy.cn | ||
13 | RUN ["go","mod","tidy"] | 13 | RUN ["go","mod","tidy"] |
14 | RUN ["ls"] | 14 | RUN ["ls"] |
15 | RUN ["go","build"] | 15 | RUN ["go","build"] |
16 | + | ||
17 | +#EXPOSE 8080 | ||
18 | + | ||
16 | ENTRYPOINT ["./character-library-metadata-bastion"] | 19 | ENTRYPOINT ["./character-library-metadata-bastion"] |
@@ -16,6 +16,8 @@ METADATA_BASTION_HOST = http://106.75.231.90:9999 | @@ -16,6 +16,8 @@ METADATA_BASTION_HOST = http://106.75.231.90:9999 | ||
16 | KAFKA_HOST =47.97.5.102:9092 | 16 | KAFKA_HOST =47.97.5.102:9092 |
17 | #192.168.100.35:9092 | 17 | #192.168.100.35:9092 |
18 | 18 | ||
19 | +REDIS_HOST=127.0.0.1 | ||
20 | + | ||
19 | STARROCKS_DB_NAME = character_library | 21 | STARROCKS_DB_NAME = character_library |
20 | STARROCKS_USER = root | 22 | STARROCKS_USER = root |
21 | STARROCKS_PASSWORD = eagle1010 | 23 | STARROCKS_PASSWORD = eagle1010 |
@@ -33,6 +33,7 @@ require ( | @@ -33,6 +33,7 @@ require ( | ||
33 | github.com/ajg/form v1.5.1 // indirect | 33 | github.com/ajg/form v1.5.1 // indirect |
34 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | 34 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect |
35 | github.com/fatih/structs v1.1.0 // indirect | 35 | github.com/fatih/structs v1.1.0 // indirect |
36 | + github.com/go-sql-driver/mysql v1.7.0 | ||
36 | github.com/google/go-querystring v1.1.0 // indirect | 37 | github.com/google/go-querystring v1.1.0 // indirect |
37 | github.com/imkira/go-interpol v1.1.0 // indirect | 38 | github.com/imkira/go-interpol v1.1.0 // indirect |
38 | github.com/moul/http2curl v1.0.0 // indirect | 39 | github.com/moul/http2curl v1.0.0 // indirect |
@@ -52,7 +53,7 @@ require ( | @@ -52,7 +53,7 @@ require ( | ||
52 | 53 | ||
53 | replace ( | 54 | replace ( |
54 | github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1 | 55 | github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1 |
56 | + github.com/go-sql-driver/mysql v1.7.0 => github.com/StarRocks/go-mysql-driver v1.7.0 | ||
55 | //github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 | 57 | //github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 |
56 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.2 | 58 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.2 |
57 | - | ||
58 | ) | 59 | ) |
1 | package main | 1 | package main |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "database/sql" | ||
4 | "fmt" | 5 | "fmt" |
5 | "github.com/beego/beego/v2/server/web" | 6 | "github.com/beego/beego/v2/server/web" |
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/crontab" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/crontab" |
@@ -39,6 +40,7 @@ func main() { | @@ -39,6 +40,7 @@ func main() { | ||
39 | log.Logger.Info("Service:" + constant.SERVICE_NAME) | 40 | log.Logger.Info("Service:" + constant.SERVICE_NAME) |
40 | log.Logger.Info("Version:" + Version) | 41 | log.Logger.Info("Version:" + Version) |
41 | log.Logger.Info("server start!") | 42 | log.Logger.Info("server start!") |
43 | + log.Logger.Info("db driver", map[string]interface{}{"drivers": sql.Drivers()}) | ||
42 | web.Run() | 44 | web.Run() |
43 | log.Logger.Info("server stop!") | 45 | log.Logger.Info("server stop!") |
44 | } | 46 | } |
@@ -470,15 +470,22 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | @@ -470,15 +470,22 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | ||
470 | if len(cmd.ExprSql) == 0 { | 470 | if len(cmd.ExprSql) == 0 { |
471 | selectValue = "''" | 471 | selectValue = "''" |
472 | } | 472 | } |
473 | + selectValue = domain.RemoveInvalidChar(selectValue) | ||
473 | sql := "select " + selectValue + " as expr" | 474 | sql := "select " + selectValue + " as expr" |
474 | if len(set.KeysStr()) > 0 { | 475 | if len(set.KeysStr()) > 0 { |
475 | sql += " from " + strings.Join(set.KeysStr(), ",") | 476 | sql += " from " + strings.Join(set.KeysStr(), ",") |
476 | sql += " limit 1" | 477 | sql += " limit 1" |
477 | } | 478 | } |
478 | - tx := starrocks.DB.Exec(sql) | ||
479 | - if tx.Error != nil { | 479 | + //tx := starrocks.DB.Exec(sql) |
480 | + //if tx.Error != nil { | ||
481 | + // return map[string]string{ | ||
482 | + // "result": tx.Error.Error(), | ||
483 | + // }, nil | ||
484 | + //} | ||
485 | + err := starrocks.ExecOfficial(sql) | ||
486 | + if err != nil { | ||
480 | return map[string]string{ | 487 | return map[string]string{ |
481 | - "result": tx.Error.Error(), | 488 | + "result": err.Error(), |
482 | }, nil | 489 | }, nil |
483 | } | 490 | } |
484 | case domain.ExprModeExcelFunction: | 491 | case domain.ExprModeExcelFunction: |
1 | package constant | 1 | package constant |
2 | 2 | ||
3 | -var POSTGRESQL_DB_NAME = "terms" | 3 | +var POSTGRESQL_DB_NAME = "allied_creation_test" |
4 | var POSTGRESQL_USER = "postgres" | 4 | var POSTGRESQL_USER = "postgres" |
5 | -var POSTGRESQL_PASSWORD = "123456" | ||
6 | -var POSTGRESQL_HOST = "127.0.0.1" | ||
7 | -var POSTGRESQL_PORT = "5432" | 5 | +var POSTGRESQL_PASSWORD = "eagle1010" |
6 | +var POSTGRESQL_HOST = "114.55.200.59" | ||
7 | +var POSTGRESQL_PORT = "31543" | ||
8 | var DISABLE_CREATE_TABLE = false | 8 | var DISABLE_CREATE_TABLE = false |
9 | var DISABLE_SQL_GENERATE_PRINT = false | 9 | var DISABLE_SQL_GENERATE_PRINT = false |
10 | var DISABLE_SQL_GENERATE_COMMENT = true | 10 | var DISABLE_SQL_GENERATE_COMMENT = true |
@@ -2,10 +2,10 @@ package constant | @@ -2,10 +2,10 @@ package constant | ||
2 | 2 | ||
3 | import "fmt" | 3 | import "fmt" |
4 | 4 | ||
5 | -var STARROCKS_DB_NAME = "character_library_standard" | 5 | +var STARROCKS_DB_NAME = "character_library" |
6 | var STARROCKS_USER = "root" | 6 | var STARROCKS_USER = "root" |
7 | var STARROCKS_PASSWORD = "eagle1010" | 7 | var STARROCKS_PASSWORD = "eagle1010" |
8 | -var STARROCKS_HOST = "118.178.239.45" | 8 | +var STARROCKS_HOST = "220.250.41.79" |
9 | var STARROCKS_PORT = "9030" | 9 | var STARROCKS_PORT = "9030" |
10 | var STARROCKS_MYSQL_DATA_SOURCE = "" | 10 | var STARROCKS_MYSQL_DATA_SOURCE = "" |
11 | 11 |
@@ -110,6 +110,16 @@ func (expr *FieldExpr) Complete() string { | @@ -110,6 +110,16 @@ func (expr *FieldExpr) Complete() string { | ||
110 | } | 110 | } |
111 | exprSql = strings.ReplaceAll(exprSql, sql, sub) | 111 | exprSql = strings.ReplaceAll(exprSql, sql, sub) |
112 | } | 112 | } |
113 | + exprSql = RemoveInvalidChar(exprSql) | ||
114 | + return exprSql | ||
115 | +} | ||
116 | + | ||
117 | +// RemoveInvalidChar 移除非法字符 | ||
118 | +// 前台的字符串的一个空格(ASCII:32)被UTF-8编码之后变成了一个诡异的字符(ASCII:194 和 160的组合) | ||
119 | +// https://www.cnblogs.com/mingmingruyuedlut/archive/2012/07/04/2575180.html | ||
120 | +func RemoveInvalidChar(exprSql string) string { | ||
121 | + tmpValue := string([]byte{0xC2, 0xA0}) | ||
122 | + exprSql = strings.ReplaceAll(exprSql, tmpValue, " ") | ||
113 | return exprSql | 123 | return exprSql |
114 | } | 124 | } |
115 | 125 |
1 | package starrocks | 1 | package starrocks |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + _ "github.com/go-sql-driver/mysql" | ||
4 | "github.com/linmadan/egglib-go/utils/json" | 5 | "github.com/linmadan/egglib-go/utils/json" |
5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" |
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" |
@@ -29,6 +30,9 @@ func Init() error { | @@ -29,6 +30,9 @@ func Init() error { | ||
29 | ) | 30 | ) |
30 | DB, err = gorm.Open(mysql.Open(constant.STARROCKS_MYSQL_DATA_SOURCE), &gorm.Config{Logger: newLogger, PrepareStmt: false}) | 31 | DB, err = gorm.Open(mysql.Open(constant.STARROCKS_MYSQL_DATA_SOURCE), &gorm.Config{Logger: newLogger, PrepareStmt: false}) |
31 | 32 | ||
33 | + if err = InitDBOfficial(); err != nil { | ||
34 | + return err | ||
35 | + } | ||
32 | //Test1() | 36 | //Test1() |
33 | return err | 37 | return err |
34 | } | 38 | } |
1 | +package starrocks | ||
2 | + | ||
3 | +import ( | ||
4 | + "database/sql" | ||
5 | + "github.com/go-sql-driver/mysql" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
8 | + "time" | ||
9 | +) | ||
10 | + | ||
11 | +var DBOfficial *sql.DB | ||
12 | + | ||
13 | +func InitDBOfficial() error { | ||
14 | + var err error | ||
15 | + sql.Register("mysql-star", &mysql.MySQLDriver{}) | ||
16 | + DBOfficial, err = sql.Open("mysql-star", constant.STARROCKS_MYSQL_DATA_SOURCE) | ||
17 | + if err != nil { | ||
18 | + return err | ||
19 | + } | ||
20 | + // See "Important settings" section. | ||
21 | + DBOfficial.SetConnMaxLifetime(time.Minute * 3) | ||
22 | + DBOfficial.SetMaxOpenConns(2) | ||
23 | + DBOfficial.SetMaxIdleConns(2) | ||
24 | + return nil | ||
25 | +} | ||
26 | + | ||
27 | +func ExecOfficial(sql string) error { | ||
28 | + log.Logger.Debug(sql) | ||
29 | + result, err := DBOfficial.Exec(sql) | ||
30 | + if err != nil { | ||
31 | + log.Logger.Error("exec error", map[string]interface{}{"err": err.Error()}) | ||
32 | + return err | ||
33 | + } | ||
34 | + _, err = result.RowsAffected() | ||
35 | + if err != nil { | ||
36 | + log.Logger.Error("result error", map[string]interface{}{"result": err.Error()}) | ||
37 | + return err | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
-
请 注册 或 登录 后发表评论