This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
forked from kosto1992/go-sitemap-generator
/
builder.go
85 lines (73 loc) · 1.59 KB
/
builder.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package stm
import "fmt"
var poolBuffer = NewBufferPool()
// BuilderError provides interface for it can confirm the error in some difference.
type BuilderError interface {
error
FullError() bool
}
// Builder provides interface for adds some kind of url sitemap.
type Builder interface {
XMLContent() []byte
Content() []byte
Add(interface{}) BuilderError
Write()
}
// SitemapURL provides generated xml interface.
type SitemapURL interface {
XML() []byte
}
// Attrs defines for xml attribute.
type Attrs []interface{}
// Attr defines for xml attribute.
type Attr map[string]string
// URL User should use this typedef in main func.
type URL [][]interface{}
// URLJoinBy that's convenient.
func (u URL) URLJoinBy(key string, joins ...string) URL {
var values []string
for _, k := range joins {
var vals interface{}
for _, v := range u {
if v[0] == k {
vals = v[1]
break
}
}
values = append(values, fmt.Sprint(vals))
}
var index int
var v []interface{}
for index, v = range u {
if v[0] == key {
break
}
}
u[index][1] = URLJoin("", values...)
return u
}
// BungURLJoinBy that's convenient. Though, this is Bung method.
func (u *URL) BungURLJoinBy(key string, joins ...string) {
orig := *u
var values []string
for _, k := range joins {
var vals interface{}
for _, v := range *u {
if v[0] == k {
vals = v[1]
break
}
}
values = append(values, fmt.Sprint(vals))
}
var index int
var v []interface{}
for index, v = range *u {
if v[0] == key {
break
}
}
orig[index][1] = URLJoin("", values...)
*u = orig
}
// type News map[string]interface{}