完善,添加ssl证书配置
This commit is contained in:
parent
63e72f7aa1
commit
3d07fffc82
@ -23,6 +23,10 @@ Mail:
|
|||||||
Port: 465
|
Port: 465
|
||||||
Ssl: true
|
Ssl: true
|
||||||
|
|
||||||
|
ssl:
|
||||||
|
cert: ""
|
||||||
|
key: ""
|
||||||
|
|
||||||
# 最近文章缓存时间
|
# 最近文章缓存时间
|
||||||
recentPostCacheTime: 5m
|
recentPostCacheTime: 5m
|
||||||
# 分类缓存时间
|
# 分类缓存时间
|
||||||
|
@ -24,19 +24,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var confPath string
|
var confPath string
|
||||||
var port string
|
var address string
|
||||||
var middleWareReloadFn func()
|
var middleWareReloadFn func()
|
||||||
var intReg = regexp.MustCompile(`^\d`)
|
var intReg = regexp.MustCompile(`^\d`)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&confPath, "c", "config.yaml", "config file")
|
flag.StringVar(&confPath, "c", "config.yaml", "config file")
|
||||||
flag.StringVar(&port, "p", "", "port")
|
flag.StringVar(&address, "p", "", "listen address(port)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if port == "" && os.Getenv("PORT") == "" {
|
if address == "" && os.Getenv("PORT") == "" {
|
||||||
port = "80"
|
address = "80"
|
||||||
}
|
}
|
||||||
if intReg.MatchString(port) && !strings.Contains(port, ":") {
|
if intReg.MatchString(address) && !strings.Contains(address, ":") {
|
||||||
port = ":" + port
|
address = ":" + address
|
||||||
}
|
}
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
err := initConf(confPath)
|
err := initConf(confPath)
|
||||||
@ -129,8 +129,16 @@ func signalNotify() {
|
|||||||
func main() {
|
func main() {
|
||||||
go signalNotify()
|
go signalNotify()
|
||||||
Gin, reloadFn := route.SetupRouter()
|
Gin, reloadFn := route.SetupRouter()
|
||||||
|
c := config.Conf.Load()
|
||||||
middleWareReloadFn = reloadFn
|
middleWareReloadFn = reloadFn
|
||||||
err := Gin.Run(port)
|
if c.Ssl.Key != "" && c.Ssl.Cert != "" {
|
||||||
|
err := Gin.RunTLS(address, c.Ssl.Cert, c.Ssl.Key)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := Gin.Run(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
var Conf safety.Var[Config]
|
var Conf safety.Var[Config]
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Ssl Ssl `yaml:"ssl"`
|
||||||
Mysql Mysql `yaml:"mysql"`
|
Mysql Mysql `yaml:"mysql"`
|
||||||
Mail Mail `yaml:"mail"`
|
Mail Mail `yaml:"mail"`
|
||||||
RecentPostCacheTime time.Duration `yaml:"recentPostCacheTime"`
|
RecentPostCacheTime time.Duration `yaml:"recentPostCacheTime"`
|
||||||
@ -41,6 +42,11 @@ type Config struct {
|
|||||||
PostOrder string `yaml:"postOrder"`
|
PostOrder string `yaml:"postOrder"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Ssl struct {
|
||||||
|
Cert string `yaml:"cert"`
|
||||||
|
Key string `yaml:"key"`
|
||||||
|
}
|
||||||
|
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
Alias string `yaml:"alias"`
|
Alias string `yaml:"alias"`
|
||||||
|
@ -2,18 +2,16 @@ package plugins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/fthvgb1/wp-go/helper/number"
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"math/rand"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Gravatar(email string, isTls bool) (u string) {
|
func Gravatar(email string, isTls bool) (u string) {
|
||||||
email = strings.Trim(email, " \t\n\r\000\x0B")
|
email = strings.Trim(email, " \t\n\r\000\x0B")
|
||||||
rand.Seed(time.Now().UnixNano())
|
num := number.Rand(0, 2)
|
||||||
num := rand.Intn(3)
|
|
||||||
h := ""
|
h := ""
|
||||||
if email != "" {
|
if email != "" {
|
||||||
h = str.Md5(strings.ToLower(email))
|
h = str.Md5(strings.ToLower(email))
|
||||||
|
@ -29,7 +29,7 @@ var twentyFifteen = PageEle{
|
|||||||
<span class="meta-nav screen-reader-text">页 </span>%d</span>`,
|
<span class="meta-nav screen-reader-text">页 </span>%d</span>`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PageEle) Current(page int) string {
|
func (p PageEle) Current(page, totalPage int) string {
|
||||||
return fmt.Sprintf(p.CurrentEle, page)
|
return fmt.Sprintf(p.CurrentEle, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Elements interface {
|
type Elements interface {
|
||||||
Current(page int) string
|
Current(page, totalPage int) string
|
||||||
Prev(url string) string
|
Prev(url string) string
|
||||||
Next(url string) string
|
Next(url string) string
|
||||||
Dots() string
|
Dots() string
|
||||||
@ -68,7 +68,7 @@ func (p ParsePagination) ToHtml() (html string) {
|
|||||||
for page := start; page <= end; page++ {
|
for page := start; page <= end; page++ {
|
||||||
h := ""
|
h := ""
|
||||||
if p.CurrentPage == page {
|
if p.CurrentPage == page {
|
||||||
h = p.Current(page)
|
h = p.Current(page, p.TotalPage)
|
||||||
} else {
|
} else {
|
||||||
h = p.Middle(page, p.Url(p.Path, p.Query, page))
|
h = p.Middle(page, p.Url(p.Path, p.Query, page))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user