refactor(ifelse): shorten logic where possible

This commit is contained in:
Gusted 2021-08-03 20:35:55 +02:00 committed by Max Mazurov
parent 53cb4c06c2
commit 32b75262ad
9 changed files with 17 additions and 46 deletions

View file

@ -109,11 +109,10 @@ func ReadPassword(prompt string) (string, error) {
fmt.Println()
return string(buf), nil
} else {
if !stdinScanner.Scan() {
return "", stdinScanner.Err()
}
return stdinScanner.Text(), nil
}
if !stdinScanner.Scan() {
return "", stdinScanner.Err()
}
return stdinScanner.Text(), nil
}

View file

@ -146,11 +146,7 @@ func mboxesRemove(be module.Storage, ctx *cli.Context) error {
}
}
if err := u.DeleteMailbox(name); err != nil {
return err
}
return nil
return u.DeleteMailbox(name)
}
func mboxesRename(be module.Storage, ctx *cli.Context) error {
@ -264,11 +260,7 @@ func msgsRemove(be module.Storage, ctx *cli.Context) error {
}
mboxB := mbox.(*imapsql.Mailbox)
if err := mboxB.DelMessages(ctx.Bool("uid"), seq); err != nil {
return err
}
return nil
return mboxB.DelMessages(ctx.Bool("uid"), seq)
}
func msgsCopy(be module.Storage, ctx *cli.Context) error {

View file

@ -70,17 +70,16 @@ func (e Endpoint) String() string {
func (e Endpoint) Network() string {
if e.Scheme == "unix" {
return "unix"
} else {
return "tcp"
}
return "tcp"
}
func (e Endpoint) Address() string {
if e.Scheme == "unix" {
return e.Path
} else {
return net.JoinHostPort(e.Host, e.Port)
}
return net.JoinHostPort(e.Host, e.Port)
}
func (e Endpoint) IsTLS() bool {

View file

@ -48,9 +48,8 @@ func AuthUsingHelper(binaryPath, accountName, password string) error {
return fmt.Errorf("helperauth: %w: %v", err, string(exitErr.Stderr))
}
return module.ErrUnknownCredentials
} else {
return fmt.Errorf("helperauth: process wait: %w", err)
}
return fmt.Errorf("helperauth: process wait: %w", err)
}
return nil
}

View file

@ -151,11 +151,7 @@ func (endp *Endpoint) Init(cfg *config.Map) error {
})
}
if err := endp.setupListeners(addresses); err != nil {
return err
}
return nil
return endp.setupListeners(addresses)
}
func (endp *Endpoint) setupListeners(addresses []config.Endpoint) error {

View file

@ -135,11 +135,8 @@ func submitMsgOpts(t *testing.T, cl *smtp.Client, from string, rcpts []string, o
if _, err := data.Write([]byte(msg)); err != nil {
return err
}
if err := data.Close(); err != nil {
return err
}
return nil
return data.Close()
}
func TestSMTPDelivery(t *testing.T) {

View file

@ -45,11 +45,7 @@ func doTestDelivery(t *testing.T, conn *C, from string, to []string, opts smtp.M
hdr := textproto.Header{}
hdr.Add("B", "2")
hdr.Add("A", "1")
if err := conn.Data(context.Background(), hdr, strings.NewReader("foobar\n")); err != nil {
return err
}
return nil
return conn.Data(context.Background(), hdr, strings.NewReader("foobar\n"))
}
func TestSMTPUTF8(t *testing.T) {

View file

@ -184,7 +184,7 @@ func readFile(path string, out map[string][]string) error {
}
for scnr.Scan() {
lineCounter += 1
lineCounter++
if strings.HasPrefix(scnr.Text(), "#") {
continue
}
@ -207,11 +207,7 @@ func readFile(path string, out map[string][]string) error {
out[from] = append(out[from], to)
}
if err := scnr.Err(); err != nil {
return err
}
return nil
return scnr.Err()
}
func (f *File) Lookup(_ context.Context, val string) (string, bool, error) {

View file

@ -241,10 +241,7 @@ func ensureDirectoryWritable(path string) error {
return err
}
testFile.Close()
if err := os.Remove(testFile.Name()); err != nil {
return err
}
return nil
return os.Remove(testFile.Name())
}
func ReadGlobals(cfg []config.Node) (map[string]interface{}, []config.Node, error) {