diff --git a/config.example.yaml b/config.example.yaml index 5dff392..170218f 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -69,3 +69,5 @@ postCommentUrl: http://wp.test/wp-comments-post.php trustIps: [] # trust servername 信任的域名 trustServerNames: ["xy.test","blog.xy.test"] +# port +port: 8082 diff --git a/config/config.go b/config/config.go index 1afadef..db6bf49 100644 --- a/config/config.go +++ b/config/config.go @@ -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 } diff --git a/mail/mail_test.go b/mail/mail_test.go index fac1e42..dfcbe25 100644 --- a/mail/mail_test.go +++ b/mail/mail_test.go @@ -6,7 +6,7 @@ import ( ) func TestSendMail(t *testing.T) { - config.InitConfig() + config.InitConfig("config.yaml") type args struct { mailTo []string subject string diff --git a/main.go b/main.go index f009a84..648dc9a 100644 --- a/main.go +++ b/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) } diff --git a/phpass/phpass.go b/phpass/phpass.go index 51ee5d8..59af774 100644 --- a/phpass/phpass.go +++ b/phpass/phpass.go @@ -13,7 +13,7 @@ import ( "unicode/utf8" ) -// PasswordHash 目前还不完善,只有encode64 getRandomBytes CryptPrivate 方法能用 +// PasswordHash 目前还不完善,只有 Encode64 getRandomBytes CryptPrivate 方法能用 type PasswordHash struct { itoa64 string iterationCountLog2 int