openidec

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

commit bd8fc0b87c3e478ef239ade86970fe518348d0ba
parent 3fb21ef85b37cdfe945d394a94149806f29d778b
Author: Peter Kosyh <p.kosyh@gmail.com>
Date:   Wed,  9 Sep 2020 11:16:08 +0300

go fmt

Diffstat:
Mii-node/main.go | 17+++++++++--------
Mii-node/web.go | 27+++++++++++++--------------
Mii/db.go | 30+++++++++++++++---------------
Mii/msg.go | 4++--
4 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/ii-node/main.go b/ii-node/main.go @@ -56,12 +56,13 @@ var verbose_opt *bool = flag.Bool("v", false, "Verbose") var echo_opt *string = flag.String("e", "list.txt", "Echoes list") type WWW struct { - Host string; - tpl *template.Template - db *ii.DB - edb *ii.EDB - udb *ii.UDB + Host string + tpl *template.Template + db *ii.DB + edb *ii.EDB + udb *ii.UDB } + func get_ue(echoes []string, db *ii.DB, user ii.User, w http.ResponseWriter, r *http.Request) { if len(echoes) == 0 { return @@ -110,7 +111,7 @@ func main() { http.Handle("/lib/", http.StripPrefix("/lib/", fs)) http.HandleFunc("/list.txt", func(w http.ResponseWriter, r *http.Request) { - echoes := db.Echoes(nil, ii.Query {}) + echoes := db.Echoes(nil, ii.Query{}) for _, v := range echoes { if !ii.IsPrivate(v.Name) { fmt.Fprintf(w, "%s:%d:%s\n", v.Name, v.Count, www.edb.Info[v.Name]) @@ -173,7 +174,7 @@ func main() { }) http.HandleFunc("/x/c/", func(w http.ResponseWriter, r *http.Request) { enames := strings.Split(r.URL.Path[5:], "/") - echoes := db.Echoes(enames, ii.Query {}) + echoes := db.Echoes(enames, ii.Query{}) for _, v := range echoes { if !ii.IsPrivate(v.Name) { fmt.Fprintf(w, "%s:%d:\n", v.Name, v.Count) @@ -191,7 +192,7 @@ func main() { }) http.HandleFunc("/u/e/", func(w http.ResponseWriter, r *http.Request) { echoes := strings.Split(r.URL.Path[5:], "/") - get_ue(echoes, db, ii.User {}, w, r) + get_ue(echoes, db, ii.User{}, w, r) }) http.HandleFunc("/m/", func(w http.ResponseWriter, r *http.Request) { id := r.URL.Path[3:] diff --git a/ii-node/web.go b/ii-node/web.go @@ -131,7 +131,7 @@ func www_logout(ctx *WebContext, w http.ResponseWriter, r *http.Request) error { func www_index(ctx *WebContext, w http.ResponseWriter, r *http.Request) error { ii.Trace.Printf("www index") - ctx.Echoes = ctx.www.db.Echoes(nil, ii.Query { User: *ctx.User }) + ctx.Echoes = ctx.www.db.Echoes(nil, ii.Query{User: *ctx.User}) ctx.Template = "index.tpl" err := ctx.www.tpl.ExecuteTemplate(w, "index.tpl", ctx) return err @@ -144,7 +144,7 @@ func parse_ava(txt string) *image.RGBA { return img } -var magicTable = map[string]string { +var magicTable = map[string]string{ "\xff\xd8\xff": "image/jpeg", "\x89PNG\r\n\x1a\n": "image/png", "GIF87a": "image/gif", @@ -364,7 +364,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que if rss { ctx.Topic = db.Name + " :: " + req fmt.Fprintf(w, -`<?xml version="1.0" encoding="UTF-8"?> + `<?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>%s</title> <subtitle>RSS feed with last messages</subtitle> @@ -372,9 +372,9 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que <id>%s/%s</id> `, str_esc(ctx.Topic), ctx.www.Host, ctx.www.Host, ctx.BasePath) - for _, m := range(ctx.Msg) { + for _, m := range ctx.Msg { fmt.Fprintf(w, -`<entry> + `<entry> <title>%s</title> <id>%s</id> <link href="%s/%s#%s" /> @@ -390,7 +390,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que str_esc(m.From)) } fmt.Fprintf(w, -`</feed> + `</feed> `) return nil } @@ -398,7 +398,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que return ctx.www.tpl.ExecuteTemplate(w, "query.tpl", ctx) } -func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page int) error { +func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page int) error { db := ctx.www.db echo := ctx.BasePath ctx.Echo = echo @@ -447,7 +447,6 @@ func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page i return err } - func www_topic(ctx *WebContext, w http.ResponseWriter, r *http.Request, page int) error { id := ctx.BasePath db := ctx.www.db @@ -578,7 +577,7 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error { if newecho != "" { echo = newecho } - if !ctx.www.edb.Allowed(echo) && ctx.User.Id != 1{ + if !ctx.www.edb.Allowed(echo) && ctx.User.Id != 1 { ii.Error.Printf("This echo is disallowed") return errors.New("This echo is disallowed") } @@ -808,8 +807,8 @@ func msg_access(www *WWW, m ii.Msg, u ii.User) bool { func WebInit(www *WWW) { funcMap := template.FuncMap{ "fdate": func(date int64) template.HTML { - if time.Now().Unix() - date < 60 * 60 * 24 { - return template.HTML("<span class='today'>"+time.Unix(date, 0).Format("2006-01-02 15:04:05") + "</span>") + if time.Now().Unix()-date < 60*60*24 { + return template.HTML("<span class='today'>" + time.Unix(date, 0).Format("2006-01-02 15:04:05") + "</span>") } return template.HTML(time.Unix(date, 0).Format("2006-01-02 15:04:05")) }, @@ -935,7 +934,7 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error { } } ctx.BasePath = "to/" + args[1] - return www_query(ctx, w, r, ii.Query { To: args[1] }, page, rss) + return www_query(ctx, w, r, ii.Query{To: args[1]}, page, rss) } else if args[0] == "from" { page := 1 rss := false @@ -950,7 +949,7 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error { } } ctx.BasePath = "from/" + args[1] - return www_query(ctx, w, r, ii.Query { From: args[1] }, page, rss) + return www_query(ctx, w, r, ii.Query{From: args[1]}, page, rss) } else if args[0] == "echo" { page := 1 rss := false @@ -964,7 +963,7 @@ func _handleWWW(ctx *WebContext, w http.ResponseWriter, r *http.Request) error { fmt.Sscanf(args[2], "%d", &page) } } - q := ii.Query { Echo: args[1] } + q := ii.Query{Echo: args[1]} if args[1] == "all" { q.Echo = "" q.Start = -100 diff --git a/ii/db.go b/ii/db.go @@ -32,11 +32,11 @@ type Index struct { } type DB struct { - Path string - Idx Index - Sync sync.RWMutex + Path string + Idx Index + Sync sync.RWMutex IdxSync sync.RWMutex - Name string + Name string } func append_file(fn string, text string) error { @@ -219,7 +219,7 @@ func (db *DB) LoadIndex() error { err2 = errors.New("Wrong format on line:" + fmt.Sprintf("%d", linenr)) return false } - mi := MsgInfo{Id: info[0], Echo: info[1], To: info[3], From: info[4] } + mi := MsgInfo{Id: info[0], Echo: info[1], To: info[3], From: info[4]} if _, err := fmt.Sscanf(info[2], "%d", &mi.Off); err != nil { err2 = errors.New("Wrong offset on line: " + fmt.Sprintf("%d", linenr)) return false @@ -543,7 +543,7 @@ func (db *DB) SelectIDS(r Query) []string { return Resp } -func (db *DB)GetTopics(mi []*MsgInfo) map[string][]string { +func (db *DB) GetTopics(mi []*MsgInfo) map[string][]string { db.Sync.RLock() defer db.Sync.RUnlock() @@ -669,13 +669,13 @@ type User struct { } type UDB struct { - Path string - Names map[string]User - ById map[int32]string - Secrets map[string]string - List []string - Sync sync.RWMutex - FileSize int64 + Path string + Names map[string]User + ById map[int32]string + Secrets map[string]string + List []string + Sync sync.RWMutex + FileSize int64 } func IsUsername(u string) bool { @@ -833,12 +833,12 @@ func (db *UDB) Edit(u *User) error { os.Remove(db.Path + ".tmp") for _, Name := range db.List { ui := db.Names[Name] - if err := append_file(db.Path + ".tmp", fmt.Sprintf("%d:%s:%s:%s:%s", + if err := append_file(db.Path+".tmp", fmt.Sprintf("%d:%s:%s:%s:%s", ui.Id, Name, ui.Mail, ui.Secret, ui.Tags.String())); err != nil { return err } } - if err := os.Rename(db.Path + ".tmp", db.Path); err != nil { + if err := os.Rename(db.Path+".tmp", db.Path); err != nil { return err } db.FileSize = 0 // force to reload diff --git a/ii/msg.go b/ii/msg.go @@ -221,8 +221,8 @@ func (t *Tags) Del(tag string) bool { for k, v := range t.List { if v == tag { copy(t.List[k:], t.List[k+1:]) - t.List[len(t.List) - 1] = "" - t.List = t.List[:len(t.List) - 1] + t.List[len(t.List)-1] = "" + t.List = t.List[:len(t.List)-1] return true } }