Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

First draft #1

wants to merge 8 commits into from

Conversation

nocive
Copy link
Owner

@nocive nocive commented Dec 19, 2016

No description provided.

@nocive nocive changed the title first commit First draft Dec 19, 2016
Copy link

@ruimbribeiro ruimbribeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

@bictorman bictorman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func boot() {
var err error

logger.Info(fmt.Sprintf("booting! ttl: %dms / refresh interval: %dms / save interval: %dms\n", requestTtl, RefreshInterval, SaveInterval))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in all these you can just use Infof all loggers generally always have a f variant:
https://godoc.org/github.com/op/go-logging#Logger.Infof

reqCounter.Refresh() // purge expired events before starting
}

logger.Info("initializing signal traps\n")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't used that logger but rarely \n is necessary.

}

func (this *RequestCounter) Refresh() {
// is this thread safe? or do we need a mutex?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maps are not thread safe, you need a mutex

}
}

func (this *Request) IsExpired(ttl time.Duration) bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use generic names such as "me", "this" or "self"
https://github.com/golang/go/wiki/CodeReviewComments#receiver-names

@bictorman
Copy link

Looking good, how about adding some interfaces for the main components and pulling the server out into an struct so that main package looks a bit more trim and we make everything more testable?

saveInterval string,
sleepPerRequest string,
) (*Config, error) {
_requestTtl, err := time.ParseDuration(requestTtl)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never seen the underscore naming convention used in Go

http.ListenAndServe(r.config.BindAddr, nil)
}

func (r *RequestCounter) process(response http.ResponseWriter, request *http.Request) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we start to go by the book now, this should implement the http.Handler interface
https://golang.org/pkg/net/http/#Handler

Then the semaphore should become a reusable http middleware.
http://www.alexedwards.net/blog/making-and-using-middleware

Then create http.Server in the main function and .ListenAndServe() from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants