aerc

Working clone of aerc-mail.org
git clone git://git.danielmoch.com/aerc.git
Log | Files | Refs | README | LICENSE

commit a0be5e80256b98237241b2f3d7825484e7a9c964
parent 305446abfd66e85fe2c46cb4a07a3abb9fa809a4
Author: emersion <contact@emersion.fr>
Date:   Wed, 10 Jan 2018 17:19:45 +0100

Misc idiomatic fixes

Diffstat:
Mcmd/aerc/main.go | 13+++++--------
Mconfig/config.go | 24+++++++++---------------
Mworker/imap/worker.go | 10+++++-----
Mworker/worker.go | 7++-----
4 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/cmd/aerc/main.go b/cmd/aerc/main.go @@ -10,17 +10,14 @@ import ( ) func main() { - var ( - conf *config.AercConfig - err error - ) - if conf, err = config.LoadConfig(nil); err != nil { + conf, err := config.LoadConfig(nil) + if err != nil { panic(err) } - workers := make([]worker.Worker, 0) + var workers []worker.Worker for _, account := range conf.Accounts { - var work worker.Worker - if work, err = worker.NewWorker(account.Source); err != nil { + work, err := worker.NewWorker(account.Source) + if err != nil { panic(err) } fmt.Printf("Initializing worker %s\n", account.Name) diff --git a/config/config.go b/config/config.go @@ -1,13 +1,13 @@ package config import ( - "github.com/go-ini/ini" - "github.com/kyoh86/xdg" - "fmt" "path" "strings" "unicode" + + "github.com/go-ini/ini" + "github.com/kyoh86/xdg" ) type UIConfig struct { @@ -50,16 +50,13 @@ func mapName(raw string) string { } func loadAccountConfig(path string) ([]AccountConfig, error) { - var ( - file *ini.File - err error - accounts []AccountConfig - ) - accounts = make([]AccountConfig, 0) - if file, err = ini.Load(path); err != nil { + file, err := ini.Load(path) + if err != nil { return nil, err } file.NameMapper = mapName + + var accounts []AccountConfig for _, _sec := range file.SectionStrings() { if _sec == "DEFAULT" { continue @@ -87,15 +84,12 @@ func loadAccountConfig(path string) ([]AccountConfig, error) { } func LoadConfig(root *string) (*AercConfig, error) { - var ( - err error - file *ini.File - ) if root == nil { _root := path.Join(xdg.ConfigHome(), "aerc") root = &_root } - if file, err = ini.Load(path.Join(*root, "aerc.conf")); err != nil { + file, err := ini.Load(path.Join(*root, "aerc.conf")) + if err != nil { return nil, err } file.NameMapper = mapName diff --git a/worker/imap/worker.go b/worker/imap/worker.go @@ -1,10 +1,10 @@ package imap import ( - "git.sr.ht/~sircmpwn/aerc2/worker/types" - "fmt" "time" + + "git.sr.ht/~sircmpwn/aerc2/worker/types" ) type IMAPWorker struct { @@ -32,15 +32,15 @@ func (w *IMAPWorker) PostAction(msg types.WorkerMessage) { w.actions <- msg } -func (w *IMAPWorker) handleMessage(_msg types.WorkerMessage) { - switch msg := _msg.(type) { +func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) { + switch msg := msg.(type) { case types.Ping: w.messages <- types.Ack{ Message: types.RespondTo(msg), } default: w.messages <- types.Unsupported{ - Message: types.RespondTo(_msg), + Message: types.RespondTo(msg), } } } diff --git a/worker/worker.go b/worker/worker.go @@ -16,11 +16,8 @@ type Worker interface { // Guesses the appropriate worker type based on the given source string func NewWorker(source string) (Worker, error) { - var ( - u *url.URL - err error - ) - if u, err = url.Parse(source); err != nil { + u, err := url.Parse(source) + if err != nil { return nil, err } switch u.Scheme {