mirror of
https://github.com/harness/drone.git
synced 2025-05-05 20:11:36 +08:00

This commit contains the following: - Improve and simplify error handling (remove unnecessary wrappers, make it feel like go) - Add extra validation for path creation and resource moving (path has to be within same top space, no top space alias allowed) - Add access logging for rest api and git api
30 lines
495 B
Go
30 lines
495 B
Go
package request
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/go-chi/chi"
|
|
)
|
|
|
|
const (
|
|
RepoRefParamName = "rref"
|
|
)
|
|
|
|
var (
|
|
ErrRepoReferenceNotFound = errors.New("No repository reference found in request.")
|
|
)
|
|
|
|
func GetRepoRef(r *http.Request) (string, error) {
|
|
rawRef := chi.URLParam(r, RepoRefParamName)
|
|
if rawRef == "" {
|
|
return "", ErrRepoReferenceNotFound
|
|
}
|
|
|
|
// paths are unescaped and lower
|
|
ref, err := url.PathUnescape(rawRef)
|
|
return strings.ToLower(ref), err
|
|
}
|