diff --git a/go.mod b/go.mod index 38dbb1c..cce3a1e 100644 --- a/go.mod +++ b/go.mod @@ -33,9 +33,9 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/ugorji/go/codec v1.2.7 // indirect - golang.org/x/net v0.4.0 // indirect - golang.org/x/sys v0.3.0 // indirect - golang.org/x/text v0.5.0 // indirect + golang.org/x/net v0.5.0 // indirect + golang.org/x/sys v0.4.0 // indirect + golang.org/x/text v0.6.0 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect diff --git a/go.sum b/go.sum index 428d1a8..bb41a88 100644 --- a/go.sum +++ b/go.sum @@ -96,22 +96,22 @@ golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9 h1:frX3nT9RkKybPnjyI+yvZh6Zu golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= -golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= -golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/internal/cmd/main.go b/internal/cmd/main.go index fc98a17..e111fc5 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -16,7 +16,6 @@ import ( "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/fthvgb1/wp-go/model" "log" - "math/rand" "os" "os/signal" "regexp" @@ -39,7 +38,6 @@ func init() { if intReg.MatchString(address) && !strings.Contains(address, ":") { address = ":" + address } - rand.Seed(time.Now().UnixNano()) err := initConf(confPath) if err != nil { panic(err) @@ -101,6 +99,8 @@ func reloads() { }() err := config.InitConfig(confPath) logs.ErrPrintln(err, "获取配置文件失败", confPath) + _, err = db.InitDb() + logs.ErrPrintln(err, "重新读取db失败", config.GetConfig().Mysql) err = wpconfig.InitOptions() logs.ErrPrintln(err, "获取网站设置WpOption失败") err = wpconfig.InitTerms() diff --git a/internal/middleware/sendmail.go b/internal/middleware/sendmail.go index c0d6450..5f7bf04 100644 --- a/internal/middleware/sendmail.go +++ b/internal/middleware/sendmail.go @@ -10,9 +10,9 @@ import ( "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/gin-gonic/gin" "io" - "io/ioutil" "net/http" "net/http/httputil" + "os" "runtime" "strings" "time" @@ -92,7 +92,7 @@ func stack(skip int) []byte { // Print this much at least. If we can't find the source, it won't show. fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc) if file != lastFile { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { continue } diff --git a/internal/pkg/db/db.go b/internal/pkg/db/db.go index 21ddf71..b1b78cd 100644 --- a/internal/pkg/db/db.go +++ b/internal/pkg/db/db.go @@ -4,18 +4,18 @@ import ( "context" "github.com/fthvgb1/wp-go/internal/pkg/config" "github.com/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/safety" _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" "log" ) -var db *sqlx.DB +var safeDb = safety.NewVar[*sqlx.DB](nil) -func InitDb() (*sqlx.DB, error) { +func InitDb() (*safety.Var[*sqlx.DB], error) { c := config.GetConfig() dsn := c.Mysql.Dsn.GetDsn() - var err error - db, err = sqlx.Open("mysql", dsn) + db, err := sqlx.Open("mysql", dsn) if err != nil { return nil, err } @@ -31,14 +31,14 @@ func InitDb() (*sqlx.DB, error) { if c.Mysql.Pool.ConnMaxLifetime != 0 { db.SetConnMaxLifetime(c.Mysql.Pool.ConnMaxLifetime) } - return db, err + safeDb.Store(db) + return safeDb, err } -func QueryDb(db *sqlx.DB) *model.SqlxQuery { +func QueryDb(db *safety.Var[*sqlx.DB]) *model.SqlxQuery { query := model.NewSqlxQuery(db, model.NewUniversalDb( nil, nil)) - model.SetSelect(query, func(ctx context.Context, a any, s string, args ...any) error { if config.GetConfig().ShowQuerySql { go log.Println(model.FormatSql(s, args...)) diff --git a/internal/theme/wp/components/block/category.go b/internal/theme/wp/components/block/category.go index cc60412..02980e0 100644 --- a/internal/theme/wp/components/block/category.go +++ b/internal/theme/wp/components/block/category.go @@ -161,6 +161,7 @@ func categoryUl(h *wp.Handle, categories []models.TermsMy, conf map[any]any) str func dropdown(h *wp.Handle, categories []models.TermsMy, id int, args map[string]string, conf map[any]any) string { s := str.NewBuilder() ids := fmt.Sprintf(`wp-block-categories-%v`, id) + args = maps.Copy(args) args["{$selectId}"] = ids attrs := reload.GetAnyValBys("block-category-attr", conf, parseAttr) selects := widget.DropdownCategories(h, args, conf, categories) diff --git a/internal/theme/wp/components/widget/archive.go b/internal/theme/wp/components/widget/archive.go index 47eb1f2..2018b9d 100644 --- a/internal/theme/wp/components/widget/archive.go +++ b/internal/theme/wp/components/widget/archive.go @@ -57,7 +57,7 @@ func Archive(h *wp.Handle, id string) string { args = maps.FilterZeroMerge(archiveArgs, CommonArgs(), commonArgs, args) args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("archives-", id), str.Join("widget widget_", "archive")) args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"]) - if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") { + if conf["dropdown"].(int64) == 0 && slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") { args["{$nav}"] = fmt.Sprintf(`" } diff --git a/internal/theme/wp/components/widget/category.go b/internal/theme/wp/components/widget/category.go index 84ca019..23b4566 100644 --- a/internal/theme/wp/components/widget/category.go +++ b/internal/theme/wp/components/widget/category.go @@ -63,6 +63,10 @@ func Category(h *wp.Handle, id string) string { args = maps.FilterZeroMerge(categoryArgs(), CommonArgs(), commonArgs, args) args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("categories-", id), str.Join("widget widget_", "categories")) args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"]) + if conf["dropdown"].(int64) == 0 && slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") { + args["{$nav}"] = fmt.Sprintf(`" + } return args }) @@ -118,10 +122,6 @@ func CategoryLi(h *wp.Handle, conf map[any]any, categories []models.TermsMy) str } func categoryUL(h *wp.Handle, args map[string]string, conf map[any]any, categories []models.TermsMy) string { - if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") { - args["{$nav}"] = fmt.Sprintf(`" - } s := str.NewBuilder() s.WriteString("