Skip to content

Commit c9496e8

Browse files
committed
可以自定义路径了
1 parent fce8595 commit c9496e8

5 files changed

Lines changed: 9 additions & 7 deletions

File tree

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type config struct {
1414
KeyPath string `json:"keypath"`
1515
Port string `json:"port"`
1616
DataBase string `json:"database"`
17+
UrlBase string `json:"urlbase"`
1718
}
1819

1920
func readConf(path string, conf *config) error {

config.json.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"enabletls": true,
33
"certpath": "/path/to/your/crt/file",
44
"keypath": "/path/to/your/key/file",
5-
"updatetime": 1,
5+
"urlbase": "bing",
66
"port": "9090",
77
"database": "./picture.db",
8+
"updatetime": 1,
89
"picnum": 7
910
}
1011
//you can use relative path as well as absolute path

handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ func getDuration(t int) time.Duration {
2626
}
2727

2828
func updatePic(i inserter, v validator) error {
29-
pics, err := getPictureInfo("zh-CN")
29+
pics, err := getPicture("zh-CN")
3030
if err != nil {
3131
return err
3232
}
3333

3434
for j := len(pics) - 1; j >= 0; j-- {
35-
status, _ := v(pics[j].Date)
36-
if status {
35+
ok, _ := v(pics[j].Date)
36+
if ok {
3737
i(pics[j].Date, pics[j].Burl)
3838
}
3939
}

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func init() {
3232

3333
tmp := make([]picture, conf.PicNum)
3434
bingHandler.pic = tmp
35-
bingHandler.urlbase = "/bing"
35+
bingHandler.urlbase = "/" + conf.UrlBase
3636

3737
go bingHandler.timeToUpdatePic()
3838
}
3939

4040
func main() {
41-
http.HandleFunc("/bing", bingHandler.redirectToPic)
41+
http.HandleFunc("/"+conf.UrlBase, bingHandler.redirectToPic)
4242
time.Sleep(time.Second)
4343
if conf.EnableTLS {
4444
http.ListenAndServeTLS("0.0.0.0:"+conf.Port,

pic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type picture struct {
1212
Burl string `json:"urlbase"`
1313
}
1414

15-
func getPictureInfo(mkt string) (pics []picture, err error) {
15+
func getPicture(mkt string) (pics []picture, err error) {
1616
gURL := fmt.Sprintf("%s/HPImageArchive.aspx?format=js&idx=-1&n=9&mkt=%s", domain, mkt)
1717

1818
response, err := http.Get(gURL)

0 commit comments

Comments
 (0)