Upload Modules
This commit is contained in:
7
ngx_http_limit_req_module/reader-go/go.mod
Normal file
7
ngx_http_limit_req_module/reader-go/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module reader-go
|
||||
|
||||
go 1.23.2
|
||||
|
||||
require github.com/vmihailenco/msgpack/v5 v5.4.1
|
||||
|
||||
require github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
12
ngx_http_limit_req_module/reader-go/go.sum
Normal file
12
ngx_http_limit_req_module/reader-go/go.sum
Normal file
@@ -0,0 +1,12 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
63
ngx_http_limit_req_module/reader-go/main.go
Normal file
63
ngx_http_limit_req_module/reader-go/main.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
msgpack "github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
type RateLimitHeader struct {
|
||||
Key string
|
||||
Now int64
|
||||
NowMonotonic int64
|
||||
}
|
||||
|
||||
type RateLimitEntry struct {
|
||||
Key []byte
|
||||
Last int64
|
||||
Excess int64
|
||||
}
|
||||
|
||||
func main() {
|
||||
argc := len(os.Args)
|
||||
argv := os.Args
|
||||
|
||||
file := "./out.bin"
|
||||
if argc == 2 {
|
||||
file = argv[1]
|
||||
}
|
||||
fmt.Printf("Decoding file %s\n", file)
|
||||
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
fmt.Println("error opening file", err)
|
||||
return
|
||||
}
|
||||
|
||||
decoder := msgpack.NewDecoder(f)
|
||||
var header RateLimitHeader
|
||||
entries := []RateLimitEntry{}
|
||||
|
||||
if err := decoder.Decode(&header); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
for {
|
||||
var entry RateLimitEntry
|
||||
if err := decoder.Decode(&entry); err != nil {
|
||||
if err == io.EOF {
|
||||
fmt.Println("EOF found")
|
||||
break
|
||||
}
|
||||
log.Fatalln(err)
|
||||
}
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
fmt.Println(header)
|
||||
for _, entry := range entries {
|
||||
fmt.Println(entry)
|
||||
}
|
||||
fmt.Println(len(entries))
|
||||
}
|
||||
Reference in New Issue
Block a user