feat: initial commit
This commit is contained in:
38
internal/http/handler/webui/common/component/util.go
Normal file
38
internal/http/handler/webui/common/component/util.go
Normal file
@ -0,0 +1,38 @@
|
||||
package component
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
httpCtx "forge.cadoles.com/wpetit/kouiz/internal/http/context"
|
||||
"forge.cadoles.com/wpetit/kouiz/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 ©
|
||||
}
|
Reference in New Issue
Block a user