Compare commits

...

2 Commits
v0.2.1 ... main

Author SHA1 Message Date
b6d0ecee68 fix: initialize database options before use 2026-08-11 18:47:19 +08:00
3c158ea1ee add MustString 2026-08-11 15:27:21 +08:00
2 changed files with 12 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ var (
// options: 数据库连接选项
// 返回: GORM数据库实例
func NewDatabase(driver string, dsn []string, options *types.SqlOptions) (db *gorm.DB, err error) {
options = dbsql.SetOptions(options)
driver = strings.ToLower(driver)
switch driver {
case "mysql":

View File

@@ -1,6 +1,8 @@
package utils
import (
"fmt"
"regexp"
"strconv"
"strings"
)
@@ -33,3 +35,12 @@ func ParseParams(in map[string]string) map[string]any {
}
return out
}
func MustString(value string) (string, error) {
var workspacePattern = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$`)
value = strings.ToLower(strings.TrimSpace(value))
if !workspacePattern.MatchString(value) {
return "", fmt.Errorf("workspace must match %s", workspacePattern.String())
}
return value, nil
}