设置配置文件参数
This commit is contained in:
parent
fc5e71d79d
commit
8b5424bdd2
|
@ -69,3 +69,5 @@ postCommentUrl: http://wp.test/wp-comments-post.php
|
|||
trustIps: []
|
||||
# trust servername 信任的域名
|
||||
trustServerNames: ["xy.test","blog.xy.test"]
|
||||
# port
|
||||
port: 8082
|
||||
|
|
|
@ -3,7 +3,7 @@ package config
|
|||
import (
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -36,6 +36,7 @@ type Config struct {
|
|||
PostCommentUrl string `yaml:"postCommentUrl"`
|
||||
TrustIps []string `yaml:"trustIps"`
|
||||
TrustServerNames []string `yaml:"trustServerNames"`
|
||||
Port string `yaml:"port"`
|
||||
}
|
||||
|
||||
type Mail struct {
|
||||
|
@ -52,8 +53,11 @@ type Mysql struct {
|
|||
Pool Pool `yaml:"pool"`
|
||||
}
|
||||
|
||||
func InitConfig() error {
|
||||
file, err := ioutil.ReadFile("config.yaml")
|
||||
func InitConfig(conf string) error {
|
||||
if conf == "" {
|
||||
conf = "config.yaml"
|
||||
}
|
||||
file, err := os.ReadFile(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func TestSendMail(t *testing.T) {
|
||||
config.InitConfig()
|
||||
config.InitConfig("config.yaml")
|
||||
type args struct {
|
||||
mailTo []string
|
||||
subject string
|
||||
|
|
11
main.go
11
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github/fthvgb1/wp-go/actions"
|
||||
"github/fthvgb1/wp-go/actions/common"
|
||||
"github/fthvgb1/wp-go/config"
|
||||
|
@ -13,8 +14,11 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
var c string
|
||||
flag.StringVar(&c, "c", "config.yaml", "config file")
|
||||
flag.Parse()
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
err := config.InitConfig()
|
||||
err := config.InitConfig(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -52,7 +56,10 @@ func cronClearCache() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
err := route.SetupRouter().Run(":8082")
|
||||
if config.Conf.Port == "" {
|
||||
config.Conf.Port = "80"
|
||||
}
|
||||
err := route.SetupRouter().Run(config.Conf.Port)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// PasswordHash 目前还不完善,只有encode64 getRandomBytes CryptPrivate 方法能用
|
||||
// PasswordHash 目前还不完善,只有 Encode64 getRandomBytes CryptPrivate 方法能用
|
||||
type PasswordHash struct {
|
||||
itoa64 string
|
||||
iterationCountLog2 int
|
||||
|
|
Loading…
Reference in New Issue
Block a user