Skip to content

Commit

Permalink
Fixed function comments based on effective go best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
eko committed Mar 16, 2019
1 parent 8dfbc3d commit 4c8fa9c
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions context.go
Expand Up @@ -17,12 +17,12 @@ type Context struct {
route *Route
}

// Creates a new context component instance
// NewContext creates a new context component instance
func NewContext() Context {
return Context{}
}

// Sets Logrus logger instance
// SetLogger sets Logrus logger instance
func (c *Context) SetLogger(logger *logrus.Logger) {
c.logger = logger
}
Expand All @@ -32,7 +32,7 @@ func (c *Context) GetLogger() *logrus.Logger {
return c.logger
}

// Sets a HTTP request instance
// SetRequest sets a HTTP request instance
func (c *Context) SetRequest(req *http.Request) {
request := NewRequest(req)
c.request = &request
Expand All @@ -43,7 +43,7 @@ func (c *Context) GetRequest() *Request {
return c.request
}

// Sets a route instance
// SetRoute sets a route instance
func (c *Context) SetRoute(route *Route) {
c.route = route
}
Expand All @@ -53,7 +53,7 @@ func (c *Context) GetRoute() *Route {
return c.route
}

// Sets a HTTP response instance
// SetResponse sets a HTTP response instance
func (c *Context) SetResponse(res http.ResponseWriter) {
response := NewResponse(res)
c.response = &response
Expand Down
10 changes: 5 additions & 5 deletions gofast.go
Expand Up @@ -27,7 +27,7 @@ type Gofast struct {
*Middleware
}

// Bootstraps a new instance
// Bootstrap bootstraps a new instance
func Bootstrap() *Gofast {
logrus.WithFields(logrus.Fields{"version": VERSION}).Info("gofast is running")

Expand All @@ -39,7 +39,7 @@ func Bootstrap() *Gofast {
return &Gofast{logger, &router, &templating, &middleware}
}

// Prepares a HTTP server
// PrepareHttpServer prepares a HTTP server
func (g *Gofast) PrepareHttpServer() string {
sort.Sort(RouteLen(g.GetRoutes()))
http.Handle("/", g)
Expand All @@ -59,14 +59,14 @@ func (g *Gofast) PrepareHttpServer() string {
return port
}

// Listens and handles HTTP requests
// Listen listens and handles HTTP requests
func (g *Gofast) Listen() {
port := g.PrepareHttpServer()

http.ListenAndServe(port, nil)
}

// Listens and handles HTTP/2 requests
// ListenHttp2 listens and handles HTTP/2 requests
func (g *Gofast) ListenHttp2(certificate string, key string) {
port := g.PrepareHttpServer()
server := &http.Server{Addr: port, Handler: nil}
Expand All @@ -75,7 +75,7 @@ func (g *Gofast) ListenHttp2(certificate string, key string) {
logrus.Fatal(server.ListenAndServeTLS(certificate, key))
}

// Serves HTTP request by matching the correct route
// ServeHTTP serves HTTP request by matching the correct route
func (g *Gofast) ServeHTTP(res http.ResponseWriter, req *http.Request) {
matchedRoute := g.GetFallback()

Expand Down
2 changes: 1 addition & 1 deletion middleware.go
Expand Up @@ -10,7 +10,7 @@ type Middleware struct {

type MiddlewareFunc func(context Context, middleware MiddlewareFunc) Handler

// Creates a new middleware component instance
// NewMiddleware creates a new middleware component instance
func NewMiddleware() Middleware {
return Middleware{middlewares: make([]MiddlewareFunc, 0)}
}
Expand Down
4 changes: 2 additions & 2 deletions middleware_test.go
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

// Tests initializing a new middleware component
// TestMiddleware tests initializing a new middleware component
func TestMiddleware(t *testing.T) {
middleware := NewMiddleware()

Expand All @@ -17,7 +17,7 @@ func TestMiddleware(t *testing.T) {
}
}

// Tests adding a new middlewares
// TestUseNewMiddlewares tests adding a new middlewares
func TestUseNewMiddlewares(t *testing.T) {
middleware := NewMiddleware()
middleware.Use(func(context Context, next MiddlewareFunc) Handler {
Expand Down
4 changes: 2 additions & 2 deletions request.go
Expand Up @@ -18,14 +18,14 @@ type Parameter struct {
value interface{}
}

// Creates a new Request component instance
// NewRequest creates a new Request component instance
func NewRequest(req *http.Request) Request {
req.ParseForm()

return Request{req, make([]Parameter, 0)}
}

// Returs HTTP request
// GetHttpRequest returs HTTP request
func (r *Request) GetHttpRequest() *http.Request {
return r.httpRequest
}
Expand Down
4 changes: 2 additions & 2 deletions request_test.go
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

// Tests setting and retrieving request parameters
// TestParameters tests setting and retrieving request parameters
func TestParameters(t *testing.T) {
httpRequest := new(http.Request)
request := NewRequest(httpRequest)
Expand All @@ -26,7 +26,7 @@ func TestParameters(t *testing.T) {
}
}

// Tests retrieving a header
// TestGetHeader tests retrieving a header
func TestGetHeader(t *testing.T) {
httpRequest, _ := http.NewRequest("GET", "/", nil)
httpRequest.Header.Set("X-Test-Header", "yes")
Expand Down
4 changes: 2 additions & 2 deletions response.go
Expand Up @@ -13,12 +13,12 @@ type Response struct {
statusCode int
}

// Creates a new Response component instance
// NewResponse creates a new Response component instance
func NewResponse(res http.ResponseWriter) Response {
return Response{res, 200}
}

// Sets Response status code
// SetStatusCode sets Response status code
func (r *Response) SetStatusCode(statusCode int) {
r.WriteHeader(statusCode)
r.statusCode = statusCode
Expand Down
2 changes: 1 addition & 1 deletion response_test.go
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

// Tests setting and retrieving a status code
// TestStatusCode tests setting and retrieving a status code
func TestStatusCode(t *testing.T) {
recorder := httptest.NewRecorder()

Expand Down
8 changes: 4 additions & 4 deletions router.go
Expand Up @@ -23,7 +23,7 @@ type RouteLen []Route

type Handler func(context Context)

// Creates a new router component instance
// NewRouter creates a new router component instance
func NewRouter() Router {
return Router{routes: make([]Route, 0)}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func (r *Router) GetRoute(name string) Route {
return result
}

// Sets route fallback (for 404 error pages)
// SetFallback sets route fallback (for 404 error pages)
func (r *Router) SetFallback(handler Handler) {
r.Add("*", "fallback", "/", handler)
}
Expand All @@ -100,7 +100,7 @@ func (r *Route) GetPattern() *regexp.Regexp {
return r.pattern
}

// Sets a route handler
// SetHandler sets a route handler
func (r *Route) SetHandler(handler Handler) {
r.handler = handler
}
Expand All @@ -110,7 +110,7 @@ func (r *Route) GetHandler() Handler {
return r.handler
}

// Route sort functions
// Len route sort functions
func (this RouteLen) Len() int {
return len(this)
}
Expand Down
6 changes: 3 additions & 3 deletions router_test.go
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

// Tests different add methods
// TestAllAddMethods tests different add methods
func TestAllAddMethods(t *testing.T) {
router := NewRouter()

Expand Down Expand Up @@ -60,7 +60,7 @@ func TestAllAddMethods(t *testing.T) {
}
}

// Tests adding a fallback route
// TestFallbackRoute tests adding a fallback route
func TestFallbackRoute(t *testing.T) {
router := NewRouter()

Expand All @@ -73,7 +73,7 @@ func TestFallbackRoute(t *testing.T) {
}
}

// Tests route handling getter
// TestRouteGetHandler tests route handling getter
func TestRouteGetHandler(t *testing.T) {
handler := func(c Context) {}

Expand Down
6 changes: 3 additions & 3 deletions templating.go
Expand Up @@ -17,12 +17,12 @@ type Templating struct {
assetsDirectory string
}

// Creates a new templating component instance
// NewTemplating creates a new templating component instance
func NewTemplating() Templating {
return Templating{}
}

// Sets templating views directory
// SetViewsDirectory sets templating views directory
func (t *Templating) SetViewsDirectory(name string) {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
Expand All @@ -39,7 +39,7 @@ func (t *Templating) GetViewsDirectory() string {
return t.viewsDirectory
}

// Sets templating assets directory
// SetAssetsDirectory sets templating assets directory
func (t *Templating) SetAssetsDirectory(name string) {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
Expand Down
4 changes: 2 additions & 2 deletions templating_test.go
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

// Tests directory setter/getter
// TestSetDirectories tests directory setter/getter
func TestSetDirectories(t *testing.T) {
templating := NewTemplating()

Expand All @@ -25,7 +25,7 @@ func TestSetDirectories(t *testing.T) {
}
}

// Tests rendering a view via pongo2 library
// TestRender tests rendering a view via pongo2 library
func TestRender(t *testing.T) {
templating := NewTemplating()
templating.SetViewsDirectory("../")
Expand Down

0 comments on commit 4c8fa9c

Please sign in to comment.