-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
81 lines (70 loc) · 1.75 KB
/
utils.go
File metadata and controls
81 lines (70 loc) · 1.75 KB
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
package main
import (
"encoding/xml"
"net/http"
"strings"
"io/ioutil"
"fmt"
"github.com/hoisie/mustache"
"github.com/hoisie/web"
)
type Person struct {
Name string `xml:-`
SteamID string `xml:"steamID"`
Avatar string `xml:"avatarMedium"`
Games []Game `xml:"games>game"`
}
type Game struct {
Name string `xml:"name"`
Storelink string `xml:"storeLink"`
Logo string `xml:"logo"`
}
func LogError(err error) {
if err != nil {
fmt.Println(err)
}
}
func (pe *Person) GetXML(url []string) {
XMLResource, _HTTPerr := http.Get(strings.Join(url, ""))
XMLSource, _iotuilerr := ioutil.ReadAll(XMLResource.Body)
LogError(_HTTPerr)
LogError(_iotuilerr)
XMLResource.Body.Close()
xml.Unmarshal(XMLSource, pe)
}
func (pe *Person) GetData(name string) {
pe.Name = name
pe.GetXML([]string{"http://steamcommunity.com/id/", name, "/games?xml=1"})
pe.GetXML([]string{"http://steamcommunity.com/id/", name, "?xml=1"})
}
func Loadmustache(filename string, args *map[string]string) string {
file, _err := ioutil.ReadFile("Mst/" + filename)
if _err != nil {
fmt.Println(_err)
return "File not found"
}
data := mustache.Render(string(file), args)
return data
}
func GetMustache(filename string) string {
file, _err := ioutil.ReadFile("Mst/" + filename)
LogError(_err)
return string(file)
}
func DelIndex(slice []Game, i int) []Game {
slice = append(slice[:i], slice[i+1:]...)
return slice
}
func Rendermustache(mst string, args *map[string]string) string {
data := mustache.Render(mst, args)
return data
}
func Sendstatic(ctx *web.Context, val string) {
file, _err := ioutil.ReadFile("static/" + val)
if _err != nil {
return
}
filetype := strings.Split(val, ".")
ctx.ContentType(filetype[len(filetype)-1])
ctx.WriteString(string(file))
}