-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquerywrapper.go
More file actions
42 lines (35 loc) · 758 Bytes
/
querywrapper.go
File metadata and controls
42 lines (35 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Author: Markus Stenberg <fingon@iki.fi>
*
* Copyright (c) 2024 Markus Stenberg
*
* Created: Sun Apr 28 10:03:22 2024 mstenber
* Last modified: Sun Apr 28 10:25:19 2024 mstenber
* Edit time: 9 min
*
*/
package main
import (
"net/url"
"github.com/a-h/templ"
)
type QueryWrapper struct {
Base string
Values url.Values
}
func (self *QueryWrapper) Add(key, value string) *QueryWrapper {
if self.Values == nil {
self.Values = url.Values{}
}
self.Values.Add(key, value)
return self
}
func (self QueryWrapper) ToLink() templ.SafeURL {
return templ.URL(self.ToLinkString())
}
func (self QueryWrapper) ToLinkString() string {
if len(self.Values) > 0 {
return self.Base + "?" + self.Values.Encode()
}
return self.Base
}