openidec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d375d7e282d65c6288f3ce8e29facf778739fcc2
parent 642d9e76edcb7b239bf37ab78692e6f34e4df8c4
Author: Peter Kosyh <p.kosyh@gmail.com>
Date:   Tue,  1 Sep 2020 17:21:06 +0300

x/c scheme added

Diffstat:
Mii-node/main.go | 25++++++++++++++++++++++---
Mii/db.go | 28++++++++++++++++++++++------
2 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/ii-node/main.go b/ii-node/main.go @@ -23,13 +23,21 @@ func main() { ii.OpenLog(ioutil.Discard, os.Stdout, os.Stderr) db_opt := flag.String("db", "./db", "II database path (directory)") + listen_opt := flag.String("L", ":8080", "Listen address") db := open_db(*db_opt) flag.Parse() http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%s\n", r.URL.Path) }) http.HandleFunc("/list.txt", func(w http.ResponseWriter, r *http.Request) { - echoes := db.Echoes() + echoes := db.Echoes(nil) + for _, v := range echoes { + fmt.Fprintf(w, "%s:%d:\n", v.Name, v.Count) + } + }) + http.HandleFunc("/x/c/", func(w http.ResponseWriter, r *http.Request) { + enames := strings.Split(r.URL.Path[5:], "/") + echoes := db.Echoes(enames) for _, v := range echoes { fmt.Fprintf(w, "%s:%d:\n", v.Name, v.Count) } @@ -78,10 +86,21 @@ func main() { fmt.Fprintf(w, m.String()) } }) + http.HandleFunc("/e/", func(w http.ResponseWriter, r *http.Request) { + e := r.URL.Path[3:] + if !ii.IsEcho(e) { + return + } + ids := db.SelectIDS(ii.Query{Echo: e}) + for _, id := range ids { + fmt.Fprintf(w, "%s\n", id) + } + }) http.HandleFunc("/x/features", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "list.txt\nu/e\n") + fmt.Fprintf(w, "list.txt\nu/e\nx/c\n") }) - if err := http.ListenAndServe(":8080", nil); err != nil { + ii.Info.Printf("Listening on %s", *listen_opt) + if err := http.ListenAndServe(*listen_opt, nil); err != nil { ii.Error.Printf("Error running web server: %s", err) } } diff --git a/ii/db.go b/ii/db.go @@ -328,13 +328,18 @@ type Echo struct { Count int } -func (db *DB) Echoes() []Echo { +func (db *DB) Echoes(names []string) []Echo { db.Sync.Lock() defer db.Sync.Unlock() db.Lock() defer db.Unlock() var list []Echo + filter := make(map[string]bool) + for _, n := range(names) { + filter[n] = true + } + if err := db.LoadIndex(); err != nil { return list } @@ -345,6 +350,11 @@ func (db *DB) Echoes() []Echo { id := db.Idx.List[i] info := db.Idx.Hash[id] e := info.Echo + if names != nil { // filter? + if _, ok := filter[e]; !ok { + continue + } + } if v, ok := hash[e]; ok { v.Count++ hash[e] = v @@ -352,12 +362,18 @@ func (db *DB) Echoes() []Echo { hash[e] = Echo{Name: e, Count: 1} } } - for _, v := range hash { - list = append(list, v) + if names != nil { + for _, v := range names { + list = append(list, hash[v]) + } + } else { + for _, v := range hash { + list = append(list, v) + } + sort.Slice(list, func(i, j int) bool { + return list[i].Name < list[j].Name + }) } - sort.Slice(list, func(i, j int) bool { - return list[i].Name < list[j].Name - }) return list }