-
Notifications
You must be signed in to change notification settings - Fork 3
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
High level library API #2
Comments
func ExamplePatrol() {
// Create a Patrol station.
station, err := patrol.NewStation(
patrol.ReceiveAddress("localhost:16000"),
)
if err != nil {
return err
}
// Start radio transmissions with other stations.
go station.Radio(context.Background())
// Radar returns a speed limiting Radar that reports infractions
// to the given station.
radar := station.Radar("88.12.33.97", patrol.Limit{
Freq: 100,
Per: time.Second,
})
// Returns a speed ticket or nil.
ticket := radar.Check(time.Now(), 1)
defer station.Register(ticket)
if ticket != nil {
// If needed, you can handle speed ticket by waiting.
time.Sleep(ticket.Wait)
}
} |
@peterbourgon: Is this taking it too far? |
I think the nouns and verbs are too cute, and I think you're still exposing too much functionality to the end user. I want: station, _ := patrol.NewStation(peer, peer, peer, ...)
limiter := station.NewSimpleLimiter("name", 100, time.Second)
// In HTTP handler
if !limiter.Allow() {
return http.StatusTooManyRequests
}
// ... |
That's much easier to use indeed :-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue tracks the development of a high level and ergonomic library API.
The text was updated successfully, but these errors were encountered: