Documentation
¶
Overview ¶
Package metered provides a metered web server which makes statistics on handled requests per minute.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // StatURL is used for handling HTTP request statistic inquiry. StatURL = "/stat" // HistoryFilename is the Request History Filename HistoryFilename = "req.his" )
Variables ¶
This section is empty.
Functions ¶
func NewWebServer ¶
NewWebServer returns a metered web server given the http.ServeMux to handle web requests.
Example ¶
package main import ( "fmt" "net/http" "github.com/antonyho/go-project-demo/pkg/webserver/metered" ) func main() { mux := http.NewServeMux() mux.HandleFunc("/", func(resp http.ResponseWriter, req *http.Request) { fmt.Fprintf(resp, "hello") }) meteredWebServer := metered.NewWebServer(mux) go meteredWebServer.Listen(":8080") }
Output:
Types ¶
type RequestInfo ¶
RequestInfo stores the basic information of an HTTP request. URL is the request URL. Request time is the server's local time down to nano-second precision in Unix epoch.
type RequestInfoPool ¶
type RequestInfoPool struct {
// contains filtered or unexported fields
}
RequestInfoPool is a sychronised pool which stores RequestInfo. It is thread safe.
func NewRequestInfoPool ¶
func NewRequestInfoPool() *RequestInfoPool
NewRequestInfoPool returns a RequestInfoPool.
func (*RequestInfoPool) Add ¶
func (p *RequestInfoPool) Add(requestInfos ...RequestInfo)
Add any number of RequestInfo into the pool.
func (*RequestInfoPool) ClearRecord ¶
func (p *RequestInfoPool) ClearRecord(before time.Time)
ClearRecord any RequestInfo from the pool which is earlier than before.
func (*RequestInfoPool) Count ¶
func (p *RequestInfoPool) Count() int
Count the number of RequestInfo in the pool.
Click to show internal directories.
Click to hide internal directories.