Skip to content

Commit

Permalink
Remove slow down middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Mar 22, 2020
1 parent d4058d9 commit fcb1798
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions internal/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package backend
import (
"fmt"
"net/http"
"strings"
"time"

"github.com/RadhiFadlillah/duit/internal/backend/api"
Expand All @@ -15,20 +14,6 @@ import (
"github.com/sirupsen/logrus"
)

// SlowDown is middleware to throttle response speed.
// Used to emulate low connection speed.
type SlowDown struct {
router http.Handler
}

func (sd SlowDown) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api") {
time.Sleep(500 * time.Millisecond)
}

sd.router.ServeHTTP(w, r)
}

// ServeApp serves web app in specified port
func ServeApp(db *sqlx.DB, port int) error {
// Prepare authenticator and handler
Expand Down Expand Up @@ -87,7 +72,7 @@ func ServeApp(db *sqlx.DB, port int) error {
url := fmt.Sprintf(":%d", port)
svr := &http.Server{
Addr: url,
Handler: SlowDown{router},
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: time.Minute,
}
Expand Down

0 comments on commit fcb1798

Please sign in to comment.