Skip to content

Commit

Permalink
Go fileserver support set db charset (#724)
Browse files Browse the repository at this point in the history
Co-authored-by: 杨赫然 <[email protected]>
  • Loading branch information
feiniks and 杨赫然 authored Dec 9, 2024
1 parent 2ab66f0 commit d04c324
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fileserver/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -145,6 +148,7 @@ type DBOption struct {
CaPath string
UseTLS bool
SkipVerify bool
Charset string
}

func loadDBOptionFromEnv(dbOpt *DBOption) *DBOption {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d04c324

Please sign in to comment.