Browse Source

Fix go vet and golint errors

Carl Jackson 11 years ago
parent
commit
87830ef549
8 changed files with 45 additions and 42 deletions
  1. +4
    -4
      graceful/listener/listener.go
  2. +1
    -0
      graceful/serve.go
  3. +1
    -0
      graceful/serve13.go
  4. +7
    -5
      graceful/server.go
  5. +0
    -2
      web/bytecode_runner.go
  6. +1
    -1
      web/chanpool.go
  7. +30
    -29
      web/mux.go
  8. +1
    -1
      web/router_middleware_test.go

+ 4
- 4
graceful/listener/listener.go View File

@ -143,7 +143,7 @@ func (t *T) DrainAll() error {
return nil
}
var notManagedErr = errors.New("listener: passed net.Conn is not managed by this package")
var errNotManaged = errors.New("listener: passed net.Conn is not managed by this package")
// Disown causes a connection to no longer be tracked by the listener. The
// passed connection must have been returned by a call to Accept from this
@ -152,7 +152,7 @@ func Disown(c net.Conn) error {
if cn, ok := c.(*conn); ok {
return cn.disown()
}
return notManagedErr
return errNotManaged
}
// MarkIdle marks the given connection as being idle, and therefore eligible for
@ -163,7 +163,7 @@ func MarkIdle(c net.Conn) error {
cn.markIdle()
return nil
}
return notManagedErr
return errNotManaged
}
// MarkInUse marks this connection as being in use, removing it from the set of
@ -174,5 +174,5 @@ func MarkInUse(c net.Conn) error {
cn.markInUse()
return nil
}
return notManagedErr
return errNotManaged
}

+ 1
- 0
graceful/serve.go View File

@ -13,6 +13,7 @@ import (
// About 200 years, also known as "forever"
const forever time.Duration = 200 * 365 * 24 * time.Hour
// Serve behaves like the method on net/http.Server with the same name.
func (srv *Server) Serve(l net.Listener) error {
// Spawn a shadow http.Server to do the actual servering. We do this
// because we need to sketch on some of the parameters you passed in,


+ 1
- 0
graceful/serve13.go View File

@ -59,6 +59,7 @@ func (c connState) Wrap(nc net.Conn, s http.ConnState) {
}
}
// Serve behaves like the method on net/http.Server with the same name.
func (srv *Server) Serve(l net.Listener) error {
// Spawn a shadow http.Server to do the actual servering. We do this
// because we need to sketch on some of the parameters you passed in,


+ 7
- 5
graceful/server.go View File

@ -8,10 +8,11 @@ import (
// Most of the code here is lifted straight from net/http
// Type Server is exactly the same as an http.Server, but provides more graceful
// A Server is exactly the same as an http.Server, but provides more graceful
// implementations of its methods.
type Server http.Server
// ListenAndServe behaves like the method on net/http.Server with the same name.
func (srv *Server) ListenAndServe() error {
addr := srv.Addr
if addr == "" {
@ -24,10 +25,11 @@ func (srv *Server) ListenAndServe() error {
return srv.Serve(l)
}
// Unlike the method of the same name on http.Server, this function defaults to
// enforcing TLS 1.0 or higher in order to address the POODLE vulnerability.
// Users who wish to enable SSLv3 must do so by supplying a TLSConfig
// explicitly.
// ListenAndServeTLS behaves like the method on net/http.Server with the same
// name. Unlike the method of the same name on http.Server, this function
// defaults to enforcing TLS 1.0 or higher in order to address the POODLE
// vulnerability. Users who wish to enable SSLv3 must do so by supplying a
// TLSConfig explicitly.
func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
addr := srv.Addr
if addr == "" {


+ 0
- 2
web/bytecode_runner.go View File

@ -80,6 +80,4 @@ func (rm routeMachine) route(c *C, w http.ResponseWriter, r *http.Request) (meth
i++
}
}
return methods, nil
}

+ 1
- 1
web/chanpool.go View File

@ -10,7 +10,7 @@ const cPoolSize = 32
type cPool chan *cStack
func makeCPool() *cPool {
var p cPool = make(chan *cStack, cPoolSize)
p := make(cPool, cPoolSize)
return &p
}


+ 30
- 29
web/mux.go View File

@ -56,7 +56,7 @@ func (m *Mux) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
// Middleware Stack functions
// Append the given middleware to the middleware stack.
// Use appends the given middleware to the middleware stack.
//
// No attempt is made to enforce the uniqueness of middlewares. It is illegal to
// call this function concurrently with active requests.
@ -64,8 +64,9 @@ func (m *Mux) Use(middleware MiddlewareType) {
m.ms.Use(middleware)
}
// Insert the given middleware immediately before a given existing middleware in
// the stack. Returns an error if "before" cannot be found in the current stack.
// Insert inserts the given middleware immediately before a given existing
// middleware in the stack. Returns an error if "before" cannot be found in the
// current stack.
//
// No attempt is made to enforce the uniqueness of middlewares. If the insertion
// point is ambiguous, the first (outermost) one is chosen. It is illegal to
@ -74,8 +75,8 @@ func (m *Mux) Insert(middleware, before MiddlewareType) error {
return m.ms.Insert(middleware, before)
}
// Remove the given middleware from the middleware stack. Returns an error if
// no such middleware can be found.
// Abandon removes the given middleware from the middleware stack. Returns an
// error if no such middleware can be found.
//
// If the name of the middleware to delete is ambiguous, the first (outermost)
// one is chosen. It is illegal to call this function concurrently with active
@ -112,8 +113,8 @@ func (m *Mux) Router(c *C, h http.Handler) http.Handler {
}
/*
Dispatch to the given handler when the pattern matches, regardless of HTTP
method.
Handle dispatches to the given handler when the pattern matches, regardless of
HTTP method.
This method is commonly used to implement sub-routing: an admin application, for
instance, can expose a single handler that is attached to the main Mux by
@ -126,20 +127,20 @@ func (m *Mux) Handle(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mALL, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// CONNECT.
// Connect dispatches to the given handler when the pattern matches and the HTTP
// method is CONNECT.
func (m *Mux) Connect(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mCONNECT, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// DELETE.
// Delete dispatches to the given handler when the pattern matches and the HTTP
// method is DELETE.
func (m *Mux) Delete(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mDELETE, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// GET.
// Get dispatches to the given handler when the pattern matches and the HTTP
// method is GET.
//
// All GET handlers also transparently serve HEAD requests, since net/http will
// take care of all the fiddly bits for you. If you wish to provide an alternate
@ -149,43 +150,43 @@ func (m *Mux) Get(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mGET|mHEAD, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// HEAD.
// Head dispatches to the given handler when the pattern matches and the HTTP
// method is HEAD.
func (m *Mux) Head(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mHEAD, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// OPTIONS.
// Options dispatches to the given handler when the pattern matches and the HTTP
// method is OPTIONS.
func (m *Mux) Options(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mOPTIONS, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// PATCH.
// Patch dispatches to the given handler when the pattern matches and the HTTP
// method is PATCH.
func (m *Mux) Patch(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPATCH, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// POST.
// Post dispatches to the given handler when the pattern matches and the HTTP
// method is POST.
func (m *Mux) Post(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPOST, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// PUT.
// Put dispatches to the given handler when the pattern matches and the HTTP
// method is PUT.
func (m *Mux) Put(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPUT, handler)
}
// Dispatch to the given handler when the pattern matches and the HTTP method is
// TRACE.
// Trace dispatches to the given handler when the pattern matches and the HTTP
// method is TRACE.
func (m *Mux) Trace(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mTRACE, handler)
}
// Set the fallback (i.e., 404) handler for this mux.
// NotFound sets the fallback (i.e., 404) handler for this mux.
//
// As a convenience, the context environment variable "goji.web.validMethods"
// (also available as the constant ValidMethodsKey) will be set to the list of
@ -195,9 +196,9 @@ func (m *Mux) NotFound(handler HandlerType) {
m.rt.notFound = parseHandler(handler)
}
// Compile the list of routes into bytecode. This only needs to be done once
// after all the routes have been added, and will be called automatically for
// you (at some performance cost on the first request) if you do not call it
// Compile compiles the list of routes into bytecode. This only needs to be done
// once after all the routes have been added, and will be called automatically
// for you (at some performance cost on the first request) if you do not call it
// explicitly.
func (m *Mux) Compile() {
m.rt.compile()


+ 1
- 1
web/router_middleware_test.go View File

@ -30,6 +30,6 @@ func TestRouterMiddleware(t *testing.T) {
w := httptest.NewRecorder()
m.ServeHTTP(w, r)
if v := <-ch; v != "a" {
t.Error("Routing was not frozen! %s", v)
t.Errorf("Routing was not frozen! %s", v)
}
}

Loading…
Cancel
Save