drone/internal/api/request/repo.go
Johannes Batzill b7b9f53b0d Improve error handling to match go standards - don't wrap and rethrow, but log and return. Also adds some more validations for path creation and resource moving. Add accesslogging for git and api router (#14)
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
2022-09-09 22:08:46 -07:00

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
}