commit 377eafaf26ad5b5ef78ff34ac8f5e731ad0707f4
parent 6655dc376f01de237a8c1f1915fb03098badaa13
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 4 Jan 2024 12:02:42 +0900
use goto in sAuth
Diffstat:
M | server.go | | | 47 | ++++++++++++++++++++++------------------------- |
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/server.go b/server.go
@@ -248,38 +248,35 @@ func sAuth(ctx context.Context, c *conn, rc <-chan *request) {
if !ok {
return
}
+ var (
+ err error
+ ifcall *TAuth
+ )
if c.s.Auth == nil {
- setError(r, fmt.Errorf("authentication not required"))
- select {
- case c.respChan <- r:
- case <-ctx.Done():
- return
- }
- continue
+ r.err = fmt.Errorf("authentication not required")
+ goto resp
}
- ifcall := r.ifcall.(*TAuth)
- var err error
+ ifcall = r.ifcall.(*TAuth)
if ifcall.Afid == NOFID {
- setError(r, fmt.Errorf("NOFID can't be used for afid")) // TODO: really?
- select {
- case c.respChan <- r:
- case <-ctx.Done():
- return
- }
- continue
+ r.err = fmt.Errorf("NOFID can't be used for afid") // TODO: really?
+ goto resp
}
r.afid, err = c.fPool.add(ifcall.Afid)
if err != nil {
- setError(r, ErrDupFid)
- select {
- case c.respChan <- r:
- case <-ctx.Done():
- return
- }
- continue
+ r.err = ErrDupFid
+ goto resp
+ }
+resp:
+ if r.err != nil {
+ setError(r, r.err)
+ } else {
+ c.s.Auth(ctx, r)
+ }
+ select {
+ case c.respChan <- r:
+ case <-ctx.Done():
+ return
}
- c.s.Auth(ctx, r)
- c.respChan <- r
}
}
}