From d04c324b24ea5952548750990b86e768fbedbd12 Mon Sep 17 00:00:00 2001 From: feiniks <36756310+feiniks@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:31:55 +0800 Subject: [PATCH] Go fileserver support set db charset (#724) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 杨赫然 --- fileserver/fileserver.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fileserver/fileserver.go b/fileserver/fileserver.go index 469552db..efd5d93a 100644 --- a/fileserver/fileserver.go +++ b/fileserver/fileserver.go @@ -106,6 +106,9 @@ func loadCcnetDB() { } else { dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?tls=%t%s", dbOpt.User, dbOpt.Password, dbOpt.Host, dbOpt.Port, dbOpt.CcnetDbName, dbOpt.UseTLS, timeout) } + if dbOpt.Charset != "" { + dsn = fmt.Sprintf("%s&charset=%s", dsn, dbOpt.Charset) + } ccnetDB, err = sql.Open("mysql", dsn) if err != nil { log.Fatalf("Failed to open database: %v", err) @@ -145,6 +148,7 @@ type DBOption struct { CaPath string UseTLS bool SkipVerify bool + Charset string } func loadDBOptionFromEnv(dbOpt *DBOption) *DBOption { @@ -241,6 +245,9 @@ func loadDBOptionFromFile() (*DBOption, error) { if key, err = section.GetKey("ca_path"); err == nil { dbOpt.CaPath = key.String() } + if key, err = section.GetKey("connection_charset"); err == nil { + dbOpt.Charset = key.String() + } return dbOpt, nil } @@ -276,6 +283,9 @@ func loadSeafileDB() { } else { dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?tls=%t%s", dbOpt.User, dbOpt.Password, dbOpt.Host, dbOpt.Port, dbOpt.SeafileDbName, dbOpt.UseTLS, timeout) } + if dbOpt.Charset != "" { + dsn = fmt.Sprintf("%s&charset=%s", dsn, dbOpt.Charset) + } seafileDB, err = sql.Open("mysql", dsn) if err != nil {