- 授权协议: MIT
- 开发语言: Google Go
- 操作系统: 跨平台
- 软件首页: http://didipkerabat.com/posts/1432264032306462173-tollbooth-http-rate-limiter-middleware-in-go.html
软件介绍
Tollbooth 是一个用 Go 语言编写的用来限制 HTTP 访问速度的中间件,可用来限制每个 HTTP 请求的传输速率。例如你可以不限制 / 的访问速率,但是可以针对 /login 限制每个 IP 每秒最多 POST 多少个请求。
Go 程序中使用的方法:
package main
import (
"github.com/didip/tollbooth"
"net/http"
"time"
)
func HelloHandler(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Hello, World!"))
}
func main() {
// You can create a generic limiter for all your handlers
// or one for each handler. Your choice.
// This limiter basically says: allow at most 1 request per 1 second.
limiter := tollbooth.NewLimiter(1, time.Second)
// This is an example on how to limit only GET and POST requests.
limiter.Methods = []string{"GET", "POST"}
// You can also limit by specific request headers, containing certain values.
// Typically, you prefetched these values from the database.
limiter.Headers = make(map[string][]string)
limiter.Headers["X-Access-Token"] = []string{"abc123", "xyz098"}
// And finally, you can limit access based on basic auth usernames.
// Typically, you prefetched these values from the database as well.
limiter.BasicAuthUsers = []string{"bob", "joe", "didip"}
// Example on how to wrap your request handler.
http.Handle("/", tollbooth.LimitFuncHandler(limiter, HelloHandler))
http.ListenAndServe(":12345", nil)
数据结构、算法与应用
(美)Sartaj Sahni / 汪诗林、孙晓东、等 / 机械工业出版社 / 2000-01 / 49.00
本书是关于计算机科学与工程领域的基础性研究科目之一――数据结构与算法的专著。 本书在简要回顾了基本的C++ 程序设计概念的基础上,全面系统地介绍了队列、堆栈、树、图等基本数据结构,以及贪婪算法、分而治之算法、分枝定界算法等多种算法设计方法,为数据结构与算法的继续学习和研究奠定了一个坚实的基础。更为可贵的是,本书不仅仅介绍了理论知识,还提供了50多个应用实例及600多道练习题。 本书......一起来看看 《数据结构、算法与应用》 这本书的介绍吧!
