mirror of
https://github.com/PeernetOfficial/WebGatewayUpload.git
synced 2026-07-16 19:47:51 +01:00
added rate limiter
This commit is contained in:
2
go.mod
2
go.mod
@@ -6,6 +6,7 @@ require (
|
||||
github.com/PeernetOfficial/core v0.0.0-20220601150942-0e3e8dc9885c
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/julianshen/gin-limiter v0.0.0-20161123033831-fc39b5e90fe7
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -20,6 +21,7 @@ require (
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/juju/ratelimit v1.0.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@@ -36,6 +36,10 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
|
||||
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
|
||||
github.com/julianshen/gin-limiter v0.0.0-20161123033831-fc39b5e90fe7 h1:hlGKdRwZ0XLX3Sattpx6nqkvI0XFpIpvH7JK1u6ODbs=
|
||||
github.com/julianshen/gin-limiter v0.0.0-20161123033831-fc39b5e90fe7/go.mod h1:rmrkiYPm2yvC0bT9+XTQO9jN1af7kUcdMSGXHLYfptk=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
|
||||
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
|
||||
|
||||
13
main.go
13
main.go
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/PeernetOfficial/core/webapi"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
limiter "github.com/julianshen/gin-limiter"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
@@ -228,11 +229,17 @@ func main() {
|
||||
r := gin.Default()
|
||||
r.LoadHTMLGlob("templates/*.html")
|
||||
r.Static("/templates", "./templates")
|
||||
r.GET("/upload", func(c *gin.Context) {
|
||||
|
||||
// Middleware rate limiter
|
||||
lm := limiter.NewRateLimiter(time.Minute, 2, func(ctx *gin.Context) (string, error) {
|
||||
return "", nil
|
||||
})
|
||||
|
||||
r.GET("/upload", lm.Middleware(), func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "upload.html", nil)
|
||||
})
|
||||
|
||||
r.POST("/uploadFile", func(c *gin.Context) {
|
||||
r.POST("/uploadFile", lm.Middleware(), func(c *gin.Context) {
|
||||
file, header, err := c.Request.FormFile("file")
|
||||
defer file.Close()
|
||||
|
||||
@@ -258,7 +265,7 @@ func main() {
|
||||
// Implement CURL script to ensure linux users can upload directly
|
||||
// the Cli like https://bashupload.com
|
||||
// Ex: curl http://localhost:8080/uploadCurl -F add=@<file name>
|
||||
r.POST("/uploadCurl", func(c *gin.Context) {
|
||||
r.POST("/uploadCurl", lm.Middleware(), func(c *gin.Context) {
|
||||
file, header, err := c.Request.FormFile("add")
|
||||
defer file.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user