Mercurial > mercurial > hgweb_golang.cgi
comparison src/kaigo/horori/searcher/server/searcher.go @ 46:6ec28d3c3e00
small changes.
| author | pyon@macmini |
|---|---|
| date | Sat, 18 Apr 2020 21:10:29 +0900 |
| parents | 20b42e2deae1 |
| children | 169936fed61b |
comparison
equal
deleted
inserted
replaced
| 45:20b42e2deae1 | 46:6ec28d3c3e00 |
|---|---|
| 1 /* | 1 /* |
| 2 Last Change: 2020-04-16 木 17:15:49. | 2 Last Change: 2020-04-17 金 17:04:25. |
| 3 */ | 3 */ |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 82 if err := loadDB(); err != nil { | 82 if err := loadDB(); err != nil { |
| 83 log.Fatal(err) | 83 log.Fatal(err) |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Http-Handler | 86 // Http-Handler |
| 87 http.HandleFunc("/h/", hhs_handler) | 87 http.HandleFunc("/h/", hhs_handler) // Get /h/0800012345 -> name:addr:20200101#20210701#... |
| 88 http.HandleFunc("/ha/", hhsdb_handler) | 88 http.HandleFunc("/hn/", hhsnm_handler) // Get /h/0800012345:0800098765:... -> name1:name2:... |
| 89 http.HandleFunc("/u/", uphhsdb_handler) | 89 http.HandleFunc("/ht/", hhstm_handler) // Get /ht -> 20200314 |
| 90 http.HandleFunc("/i/", image_handler) | 90 http.HandleFunc("/ha/", hhsdb_handler) // Get /ha/ -> hhsdb.csv for Mover |
| 91 http.HandleFunc("/r/", recent_handler) | 91 http.HandleFunc("/i/", image_handler) // Get /i/20200110/0800012345.tgz |
| 92 http.HandleFunc("/d/", index_handler) | 92 http.HandleFunc("/r/", recent_handler) // Get /r/0800012345:0800067890:0800099999:... -> 0800012345,name1,20200101:0800067890,name2,20210405:... |
| 93 http.HandleFunc("/d/", index_handler) // Get /d/20xx -> 20xx0401:2020xx0408:... , /d/20xx0401 -> 0800012345:0800098765:... | |
| 94 http.HandleFunc("/u/", uphhsdb_handler) // Get /u/ -> ? | |
| 93 | 95 |
| 94 log.Fatal(http.ListenAndServe(server, nil)) | 96 log.Fatal(http.ListenAndServe(server, nil)) |
| 95 } | 97 } |
| 96 | 98 |
| 97 func loadDB() error { | 99 func loadDB() error { |
| 150 } | 152 } |
| 151 | 153 |
| 152 return nil | 154 return nil |
| 153 } | 155 } |
| 154 | 156 |
| 155 /* Get /h/0800012345 -> name:addr:ymd1#ymd2#... */ | 157 /* Get /h/0800012345 -> name:addr:20200101#20210701#... */ |
| 156 func hhs_handler(w http.ResponseWriter, r *http.Request) { | 158 func hhs_handler(w http.ResponseWriter, r *http.Request) { |
| 157 hno := r.URL.Path[len("/h/"):] | 159 hno := r.URL.Path[len("/h/"):] |
| 158 s := "" | 160 s := "" |
| 159 if h, ok := hhash[hno]; ok { | 161 if h, ok := hhash[hno]; ok { |
| 160 s = h.GetData() | 162 s = h.GetData() |
| 161 } | 163 } |
| 162 w.Write([]byte(s)) | 164 w.Write([]byte(s)) |
| 163 } | 165 } |
| 164 | 166 |
| 167 /* Get /hn/0800012345:0800098765:... -> name1:name2:... */ | |
| 168 func hhsnm_handler(w http.ResponseWriter, r *http.Request) { | |
| 169 hnolist := strings.Split(r.URL.Path[len("/hn/"):], ":") | |
| 170 var buf []string | |
| 171 for _, hno := range hnolist { | |
| 172 var n string | |
| 173 if h, ok := hhash[hno]; ok { | |
| 174 n = h.Name | |
| 175 } | |
| 176 buf = append(buf, n) | |
| 177 } | |
| 178 w.Write([]byte(strings.Join(buf, ":"))) | |
| 179 } | |
| 180 | |
| 181 /* Get /ht > 20200314 */ | |
| 182 func hhstm_handler(w http.ResponseWriter, r *http.Request) { | |
| 183 date := "" | |
| 184 w.Write([]byte(date)) | |
| 185 } | |
| 186 | |
| 165 /* Get /ha/ -> hhsdb.csv for Mover */ | 187 /* Get /ha/ -> hhsdb.csv for Mover */ |
| 166 func hhsdb_handler(w http.ResponseWriter, r *http.Request) { | 188 func hhsdb_handler(w http.ResponseWriter, r *http.Request) { |
| 167 b, _ := ioutil.ReadFile(hhsdb) | 189 b, _ := ioutil.ReadFile(hhsdb) |
| 168 w.Write(b) | 190 w.Write(b) |
| 169 } | 191 } |
| 185 w.Header().Set("Content-Type", "rsearcher/octet-stream") | 207 w.Header().Set("Content-Type", "rsearcher/octet-stream") |
| 186 w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size())) | 208 w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size())) |
| 187 io.Copy(w, f) | 209 io.Copy(w, f) |
| 188 } | 210 } |
| 189 | 211 |
| 190 /* Get /r/0800012345:0800067890:0800099999:... */ | 212 /* Get /r/0800012345:0800067890:0800099999:... -> 0800012345,name1,20200101:0800067890,name2,20210405:... */ |
| 191 func recent_handler(w http.ResponseWriter, r *http.Request) { | 213 func recent_handler(w http.ResponseWriter, r *http.Request) { |
| 192 hnolist := strings.Split(r.URL.Path[len("/r/"):], ":") | 214 hnolist := strings.Split(r.URL.Path[len("/r/"):], ":") |
| 193 var buf []string | 215 var buf []string |
| 194 for _, hno := range hnolist { | 216 for _, hno := range hnolist { |
| 195 s := hno + ",," | 217 s := hno + ",," |
| 215 buf = iymdhash[ymd] | 237 buf = iymdhash[ymd] |
| 216 } | 238 } |
| 217 w.Write([]byte(buf[1:])) | 239 w.Write([]byte(buf[1:])) |
| 218 } | 240 } |
| 219 | 241 |
| 242 /* /u */ | |
| 220 func uphhsdb_handler(w http.ResponseWriter, r *http.Request) { | 243 func uphhsdb_handler(w http.ResponseWriter, r *http.Request) { |
| 221 server_root := filepath.Dir(os.Args[0]) | 244 server_root := filepath.Dir(os.Args[0]) |
| 222 file := filepath.Join(server_root, "db", hhsdb) | 245 file := filepath.Join(server_root, "db", hhsdb) |
| 223 f, err := os.Create(file) | 246 f, err := os.Create(file) |
| 224 if err != nil { | 247 if err != nil { |
