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() { func main() {
var ( conf, err := config.LoadConfig(nil)
conf *config.AercConfig if err != nil {
err error
)
if conf, err = config.LoadConfig(nil); err != nil {
panic(err) panic(err)
} }
workers := make([]worker.Worker, 0) var workers []worker.Worker
for _, account := range conf.Accounts { for _, account := range conf.Accounts {
var work worker.Worker work, err := worker.NewWorker(account.Source)
if work, err = worker.NewWorker(account.Source); err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Printf("Initializing worker %s\n", account.Name) fmt.Printf("Initializing worker %s\n", account.Name)

View File

@ -1,13 +1,13 @@
package config package config
import ( import (
"github.com/go-ini/ini"
"github.com/kyoh86/xdg"
"fmt" "fmt"
"path" "path"
"strings" "strings"
"unicode" "unicode"
"github.com/go-ini/ini"
"github.com/kyoh86/xdg"
) )
type UIConfig struct { type UIConfig struct {
@ -50,16 +50,13 @@ func mapName(raw string) string {
} }
func loadAccountConfig(path string) ([]AccountConfig, error) { func loadAccountConfig(path string) ([]AccountConfig, error) {
var ( file, err := ini.Load(path)
file *ini.File if err != nil {
err error
accounts []AccountConfig
)
accounts = make([]AccountConfig, 0)
if file, err = ini.Load(path); err != nil {
return nil, err return nil, err
} }
file.NameMapper = mapName file.NameMapper = mapName
var accounts []AccountConfig
for _, _sec := range file.SectionStrings() { for _, _sec := range file.SectionStrings() {
if _sec == "DEFAULT" { if _sec == "DEFAULT" {
continue continue
@ -87,15 +84,12 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
} }
func LoadConfig(root *string) (*AercConfig, error) { func LoadConfig(root *string) (*AercConfig, error) {
var (
err error
file *ini.File
)
if root == nil { if root == nil {
_root := path.Join(xdg.ConfigHome(), "aerc") _root := path.Join(xdg.ConfigHome(), "aerc")
root = &_root 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 return nil, err
} }
file.NameMapper = mapName file.NameMapper = mapName

View File

@ -1,10 +1,10 @@
package imap package imap
import ( import (
"git.sr.ht/~sircmpwn/aerc2/worker/types"
"fmt" "fmt"
"time" "time"
"git.sr.ht/~sircmpwn/aerc2/worker/types"
) )
type IMAPWorker struct { type IMAPWorker struct {
@ -32,15 +32,15 @@ func (w *IMAPWorker) PostAction(msg types.WorkerMessage) {
w.actions <- msg w.actions <- msg
} }
func (w *IMAPWorker) handleMessage(_msg types.WorkerMessage) { func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) {
switch msg := _msg.(type) { switch msg := msg.(type) {
case types.Ping: case types.Ping:
w.messages <- types.Ack{ w.messages <- types.Ack{
Message: types.RespondTo(msg), Message: types.RespondTo(msg),
} }
default: default:
w.messages <- types.Unsupported{ 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 // Guesses the appropriate worker type based on the given source string
func NewWorker(source string) (Worker, error) { func NewWorker(source string) (Worker, error) {
var ( u, err := url.Parse(source)
u *url.URL if err != nil {
err error
)
if u, err = url.Parse(source); err != nil {
return nil, err return nil, err
} }
switch u.Scheme { switch u.Scheme {