You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: offlinegate.go
    path of file: ./repos/portainer/api/http/offlinegate
    
    the code of the file until where you have to start completion: package offlinegate

import (
	"net/http"
	"strings"
	"time"

	httperror "github.com/portainer/portainer/pkg/libhttp/error"

	"github.com/rs/zerolog/log"
	lock "github.com/viney-shih/go-lock"
)

// OfflineGate is an entity that works similar to a mutex with signaling
// Only the caller that has Locked a gate can unlock it, otherwise it will be blocked with a c
    
func (o *OfflineGate) WaitingMiddleware(timeout time.Duration, next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "GET" || r.Method == "HEAD" || r.Method == "OPTIONS" || strings.HasPrefix(r.URL.Path, "/api/backup") || strings.HasPrefix(r.URL.Path, "/api/restore") {
			next.ServeHTTP(w, r)
			return
		}

		if !o.lock.RTryLockWithTimeout(timeout) {
			log.Error().Msg("timeout waiting for the offline gate to signal")
			httperror.WriteError(w, http.StatusRequestTimeout, "Timeout waiting for the offline gate to signal", http.ErrHandlerTimeout)
			return
		}
		next.ServeHTTP(w, r)
		o.lock.RUnlock()
	})
}