Mercurial > mercurial > hgweb_golang.cgi
diff src/kaigo/horori/searcher/server/searcher.go @ 65:0369656be06c default tip
many changes.
author | pyon@macmini |
---|---|
date | Fri, 20 May 2022 06:30:34 +0900 |
parents | 7396e7407abd |
children |
line wrap: on
line diff
--- a/src/kaigo/horori/searcher/server/searcher.go Fri Dec 25 20:48:01 2020 +0900 +++ b/src/kaigo/horori/searcher/server/searcher.go Fri May 20 06:30:34 2022 +0900 @@ -1,5 +1,5 @@ /* - Last Change: 2020-06-23 火 15:48:49. + Last Change: 2022-05-16 月 09:34:18. */ package main @@ -11,7 +11,6 @@ "encoding/csv" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -101,7 +100,7 @@ http.HandleFunc("/ha/", hhsdb_handler) // Get /ha/ -> hhsdb.csv for Mover http.HandleFunc("/i/", image_handler) // Get /i/20200110/0800012345.tgz http.HandleFunc("/r/", recent_handler) // Get /r/0800012345:0800067890:0800099999:... -> 0800012345,name1,20200101:0800067890,name2,20210405:... - http.HandleFunc("/d/", index_handler) // Get /d/20xx -> 20xx0401:20xx0408:... , /d/20xx0401 -> 0800012345:0800098765:... + http.HandleFunc("/d/", index_handler) // Get /d/ -> index.csv, /d/20xx -> 20xx0401:20xx0408:... , /d/20xx0401 -> 0800012345:0800098765:... http.HandleFunc("/dt/", indextm_handler) // Get /dt/ -> 2020-03-14 12:34 (2020-04-02) http.HandleFunc("/hd/", hhsdbidx_handler)// Get /hd/ -> 20010401,0800012345,name1\n20010401,0300011111,name2\n... http.HandleFunc("/ud/", upidx_handler) // Get /ud/20200402 @@ -119,7 +118,7 @@ iymdhash = make(map[string]string) iyhash = make(map[string]string) - b, err := ioutil.ReadFile(hhsdb) + b, err := os.ReadFile(hhsdb) if err != nil { return err } @@ -140,7 +139,7 @@ hhash[record[0]] = h } - b, err = ioutil.ReadFile(indexdb) + b, err = os.ReadFile(indexdb) if err != nil { return err } @@ -232,7 +231,7 @@ /* Get /ha/ -> hhsdb.csv for Mover */ func hhsdb_handler(w http.ResponseWriter, r *http.Request) { - b, _ := ioutil.ReadFile(hhsdb) + b, _ := os.ReadFile(hhsdb) w.Write(b) } @@ -273,14 +272,20 @@ w.Write([]byte(strings.Join(buf, ":"))) } -/* Get /d/20xx -> 20xx0401:20xx0408:... , /d/20xx0401 -> 0800012345:0800098765:... */ +/* Get /d/ -> index.csv, /d/20xx -> 20xx0401:20xx0408:... , /d/20xx0401 -> 0800012345:0800098765:... */ func index_handler(w http.ResponseWriter, r *http.Request) { + ymd := r.URL.Path[len("/d/"):] + + if len(ymd) == 0 { + b, _ := os.ReadFile(indexdb) + w.Write(b) + return + } + var buf string - ymd := r.URL.Path[len("/d/"):] if len(ymd) == 4 { buf = iyhash[ymd] - } - if len(ymd) == 8 { + } else if len(ymd) == 8 { buf = iymdhash[ymd] } w.Write([]byte(buf[1:])) @@ -302,7 +307,7 @@ } defer f.Close() - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { write_errlog(12, "cannot read req-body") @@ -392,7 +397,7 @@ /* Get /hd/ -> 20010401,0800012345,name1\n20010401,0300011111,name2\n... */ func hhsdbidx_handler(w http.ResponseWriter, r *http.Request) { s := "" - b, err := ioutil.ReadFile(indexdb) + b, err := os.ReadFile(indexdb) if err != nil { return } @@ -426,7 +431,7 @@ f.Close() imgdir := filepath.Join(server_root, "images", date) - files, _ := ioutil.ReadDir(imgdir) + files, _ := os.ReadDir(imgdir) for _, file := range files { i := file.Name()[0:10] + "," + date buf = append(buf, i) @@ -436,7 +441,7 @@ os.Remove(indexdb) s := strings.Join(buf, "\n") - ioutil.WriteFile(indexdb, []byte(s), 0644) + os.WriteFile(indexdb, []byte(s), 0644) loadDB(); w.Write([]byte("update index done.")) @@ -451,7 +456,7 @@ /* Get /pw/ -> id1:pw1:id2:pw2:... */ func pw_handler(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadFile(pwdb) + b, err := os.ReadFile(pwdb) if err != nil { write_errlog(30, "cannot read passwd-file") http.NotFound(w, r)