From 903d5c95f0840bc3b9e9fc89ea760dcff08a2466 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 20 Feb 2016 16:16:18 -0500 Subject: [PATCH] remove named returns and useless closures --- cmux.go | 16 ++++++++-------- matchers.go | 10 +++------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cmux.go b/cmux.go index f0adc10..1d5f8f3 100644 --- a/cmux.go +++ b/cmux.go @@ -7,11 +7,11 @@ import ( ) // Matcher matches a connection based on its content. -type Matcher func(r io.Reader) (ok bool) +type Matcher func(io.Reader) bool // ErrorHandler handles an error and returns whether // the mux should continue serving the listener. -type ErrorHandler func(err error) (ok bool) +type ErrorHandler func(error) bool var _ net.Error = ErrNotMatched{} @@ -49,7 +49,7 @@ func New(l net.Listener) CMux { return &cMux{ root: l, bufLen: 1024, - errh: func(err error) bool { return true }, + errh: func(_ error) bool { return true }, } } @@ -59,12 +59,12 @@ type CMux interface { // the connections matched by at least one of the matcher. // // The order used to call Match determines the priority of matchers. - Match(matchers ...Matcher) net.Listener + Match(...Matcher) net.Listener // Serve starts multiplexing the listener. Serve blocks and perhaps // should be invoked concurrently within a go routine. Serve() error // HandleError registers an error handler that handles listener errors. - HandleError(h ErrorHandler) + HandleError(ErrorHandler) } type matchersListener struct { @@ -79,7 +79,7 @@ type cMux struct { sls []matchersListener } -func (m *cMux) Match(matchers ...Matcher) (l net.Listener) { +func (m *cMux) Match(matchers ...Matcher) net.Listener { ml := muxListener{ Listener: m.root, connc: make(chan net.Conn, m.bufLen), @@ -155,9 +155,9 @@ type muxListener struct { donec chan struct{} } -func (l muxListener) Accept() (c net.Conn, err error) { +func (l muxListener) Accept() (net.Conn, error) { select { - case c = <-l.connc: + case c := <-l.connc: return c, nil case <-l.donec: return nil, ErrListenerClosed diff --git a/matchers.go b/matchers.go index e890a53..1a84deb 100644 --- a/matchers.go +++ b/matchers.go @@ -21,9 +21,7 @@ func Any() Matcher { // starts with any of the strings in strs. func PrefixMatcher(strs ...string) Matcher { pt := newPatriciaTreeString(strs...) - return func(r io.Reader) bool { - return pt.matchPrefix(r) - } + return pt.matchPrefix } var defaultHTTPMethods = []string{ @@ -88,9 +86,7 @@ var ( // HTTP2 parses the frame header of the first frame to detect whether the // connection is an HTTP2 connection. func HTTP2() Matcher { - return func(r io.Reader) bool { - return hasHTTP2Preface(r) - } + return hasHTTP2Preface } // HTTP1HeaderField returns a matcher matching the header fields of the first @@ -109,7 +105,7 @@ func HTTP2HeaderField(name, value string) Matcher { } } -func hasHTTP2Preface(r io.Reader) (ok bool) { +func hasHTTP2Preface(r io.Reader) bool { b := make([]byte, len(http2Preface)) n, err := r.Read(b) if err != nil {