File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
1920func readConf (path string , conf * config ) error {
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -26,14 +26,14 @@ func getDuration(t int) time.Duration {
2626}
2727
2828func 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 }
Original file line number Diff line number Diff 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
4040func 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 ,
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments