| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package applicationconfig
- import (
- "database/sql"
- "strings"
- "time"
- "udeServer/internal/apierr"
- )
- // editFlag 语义与 t_config.edit_flag 一致(移植自 sdf-serve constants):
- // 1=默认配置,禁止修改配置项名与删除;2=允许编辑。
- const (
- editFlagProhibited = 1
- editFlagAllowEdit = 2
- )
- // configOperatorName 无用户体系时的操作人占位,与其他模块一致。
- const configOperatorName = "admin"
- // nullStr 非空字符串转合法 NullString,空串置 NULL。
- func nullStr(v string) sql.NullString {
- return sql.NullString{String: v, Valid: v != ""}
- }
- // trimSpace 去首尾空白。
- func trimSpace(v string) string {
- return strings.TrimSpace(v)
- }
- // normalizePage 页码/页大小兜底:1/10 起,上限 100。
- func normalizePage(page, pageSize int64) (int64, int64) {
- if page < 1 {
- page = 1
- }
- if pageSize < 10 {
- pageSize = 10
- }
- if pageSize > 100 {
- pageSize = 100
- }
- return page, pageSize
- }
- // checkId 主键合法性,与 logic 包同名 helper 行为一致。
- func checkId(id int64) error {
- if id <= 0 {
- return apierr.BadRequest("id must be greater than 0")
- }
- return nil
- }
- // formatConfigTime 时间展示格式与 sdf-serve 保持一致。
- func formatConfigTime(t time.Time) string {
- if t.IsZero() {
- return ""
- }
- return t.Format("2006-01-02 15:04:05")
- }
- // containsConfigKey 判断配置项是否在热加载白名单内(sdf ReloadableKeys 同款)。
- func containsConfigKey(slice []string, item string) bool {
- for _, v := range slice {
- if v == item {
- return true
- }
- }
- return false
- }
- // reloadableKeys 修改后需要重载 MinIO 客户端与审计日志配置的键,
- // 与 audit 包读取的 config_item 完全对应。
- var reloadableKeys = []string{
- "file_endpoint",
- "file_bucket",
- "file_access_key",
- "file_secret_key",
- "file_use_ssl",
- "log_record_level",
- "archive_threshold",
- }
|