Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package context
|
|
|
|
import (
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"code.gitcaddy.com/server/v3/modules/setting"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
// PathParam returns the param in request path, eg: "/{var}" => "/a%2fb", then `var == "a/b"`
|
|
func (b *Base) PathParam(name string) string {
|
|
s, err := url.PathUnescape(b.PathParamRaw(name))
|
|
if err != nil && !setting.IsProd {
|
|
panic("Failed to unescape path param: " + err.Error() + ", there seems to be a double-unescaping bug")
|
|
}
|
|
return s
|
|
}
|
|
|
|
// PathParamRaw returns the raw param in request path, eg: "/{var}" => "/a%2fb", then `var == "a%2fb"`
|
|
func (b *Base) PathParamRaw(name string) string {
|
|
if strings.HasPrefix(name, ":") {
|
|
setting.PanicInDevOrTesting("path param should not start with ':'")
|
|
name = name[1:]
|
|
}
|
|
return chi.URLParam(b.Req, name)
|
|
}
|
|
|
|
// PathParamInt64 returns the param in request path as int64
|
|
func (b *Base) PathParamInt64(p string) int64 {
|
|
v, _ := strconv.ParseInt(b.PathParam(p), 10, 64)
|
|
return v
|
|
}
|
|
|
|
func (b *Base) PathParamInt(p string) int {
|
|
v, _ := strconv.Atoi(b.PathParam(p))
|
|
return v
|
|
}
|
|
|
|
// SetPathParam set request path params into routes
|
|
func (b *Base) SetPathParam(name, value string) {
|
|
if strings.HasPrefix(name, ":") {
|
|
setting.PanicInDevOrTesting("path param should not start with ':'")
|
|
name = name[1:]
|
|
}
|
|
chi.RouteContext(b).URLParams.Add(name, url.PathEscape(value))
|
|
}
|