-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
First draft #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
Looking good, how about adding some interfaces for the main components and pulling the server out into an struct so that |
saveInterval string, | ||
sleepPerRequest string, | ||
) (*Config, error) { | ||
_requestTtl, err := time.ParseDuration(requestTtl) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
No description provided.