39 lines
938 B
Go
39 lines
938 B
Go
package component
|
|
|
|
import (
|
|
"context"
|
|
|
|
httpCtx "forge.cadoles.com/wpetit/clearcase/internal/http/context"
|
|
"forge.cadoles.com/wpetit/clearcase/internal/http/url"
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
var (
|
|
WithPath = url.WithPath
|
|
WithoutValues = url.WithoutValues
|
|
WithValuesReset = url.WithValuesReset
|
|
WithValues = url.WithValues
|
|
)
|
|
|
|
func BaseURL(ctx context.Context, funcs ...url.MutationFunc) templ.SafeURL {
|
|
baseURL := httpCtx.BaseURL(ctx)
|
|
mutated := url.Mutate(baseURL, funcs...)
|
|
return templ.SafeURL(mutated.String())
|
|
}
|
|
|
|
func CurrentURL(ctx context.Context, funcs ...url.MutationFunc) templ.SafeURL {
|
|
currentURL := clone(httpCtx.CurrentURL(ctx))
|
|
mutated := url.Mutate(currentURL, funcs...)
|
|
return templ.SafeURL(mutated.String())
|
|
}
|
|
|
|
func MatchPath(ctx context.Context, path string) bool {
|
|
currentURL := httpCtx.CurrentURL(ctx)
|
|
return currentURL.Path == path
|
|
}
|
|
|
|
func clone[T any](v *T) *T {
|
|
copy := *v
|
|
return ©
|
|
}
|