-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.go
50 lines (42 loc) · 834 Bytes
/
misc.go
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
43
44
45
46
47
48
49
50
package utils
import "fmt"
// Misc - misc
type Misc struct{}
// NewMisc - create new misc
func NewMisc() Misc {
return Misc{}
}
// URLBuilder - URL string builder
type URLBuilder struct {
Scheme string
URL string
PortString string
}
// NewURLBuilder - returns new url builder
func (m Misc) NewURLBuilder(opts ...string) URLBuilder {
u := URLBuilder{
Scheme: "http",
URL: "localhost",
PortString: "",
}
if len(opts) >= 1 {
if opts[0] != "" {
u.Scheme = opts[0]
}
}
if len(opts) >= 2 {
if opts[1] != "" {
u.URL = opts[1]
}
}
if len(opts) >= 3 {
if opts[2] != "" {
u.PortString = fmt.Sprintf(":%s", opts[2])
}
}
return u
}
// Build - builds and returns URL string
func (u URLBuilder) Build() string {
return fmt.Sprintf("%s://%s%s", u.Scheme, u.URL, u.PortString)
}