Skip to content

Commit

Permalink
可以自定义路径了
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieYu4994 committed Mar 29, 2021
1 parent fce8595 commit c9496e8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type config struct {
KeyPath string `json:"keypath"`
Port string `json:"port"`
DataBase string `json:"database"`
UrlBase string `json:"urlbase"`
}

func readConf(path string, conf *config) error {
Expand Down
3 changes: 2 additions & 1 deletion config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"enabletls": true,
"certpath": "/path/to/your/crt/file",
"keypath": "/path/to/your/key/file",
"updatetime": 1,
"urlbase": "bing",
"port": "9090",
"database": "./picture.db",
"updatetime": 1,
"picnum": 7
}
//you can use relative path as well as absolute path
Expand Down
6 changes: 3 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func getDuration(t int) time.Duration {
}

func updatePic(i inserter, v validator) error {
pics, err := getPictureInfo("zh-CN")
pics, err := getPicture("zh-CN")
if err != nil {
return err
}

for j := len(pics) - 1; j >= 0; j-- {
status, _ := v(pics[j].Date)
if status {
ok, _ := v(pics[j].Date)
if ok {
i(pics[j].Date, pics[j].Burl)
}
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func init() {

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

go bingHandler.timeToUpdatePic()
}

func main() {
http.HandleFunc("/bing", bingHandler.redirectToPic)
http.HandleFunc("/"+conf.UrlBase, bingHandler.redirectToPic)
time.Sleep(time.Second)
if conf.EnableTLS {
http.ListenAndServeTLS("0.0.0.0:"+conf.Port,
Expand Down
2 changes: 1 addition & 1 deletion pic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type picture struct {
Burl string `json:"urlbase"`
}

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

response, err := http.Get(gURL)
Expand Down

0 comments on commit c9496e8

Please sign in to comment.