Misc idiomatic fixes

This commit is contained in:
emersion 2018-01-10 17:19:45 +01:00 committed by Drew DeVault
parent 305446abfd
commit a0be5e8025
4 changed files with 21 additions and 33 deletions

View File

@ -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)

View File

@ -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

View File

@ -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),
}
}
}

View File

@ -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 {