-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
105 lines (96 loc) · 2.47 KB
/
configuration.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Defines configuration struct and methods
package main
import (
"fmt"
"github.com/icwells/compOncDB/src/codbutils"
"github.com/icwells/go-tools/iotools"
"html/template"
"net/http"
"path"
)
type urls struct {
changepw string
get string
lifehist string
login string
logout string
menu string
newpw string
output string
prevalence string
reftaxa string
source string
static string
summary string
table string
tissue string
tutorial string
}
func setURLs() *urls {
// Stores url stems
u := new(urls)
u.source = "/codb/"
u.changepw = fmt.Sprintf("%schangepassword", u.source)
u.get = fmt.Sprintf("%sget/", u.source)
u.lifehist = fmt.Sprintf("%slifehistory/", u.source)
u.login = fmt.Sprintf("%slogin", u.source)
u.logout = fmt.Sprintf("%slogout", u.source)
u.menu = fmt.Sprintf("%smenu/", u.source)
u.newpw = fmt.Sprintf("%snewpassword", u.source)
u.output = fmt.Sprintf("%sresults/", u.source)
u.prevalence = fmt.Sprintf("%sprevalence/", u.source)
u.reftaxa = fmt.Sprintf("%sreferencetaxonomy/", u.source)
u.static = "/static/"
u.summary = fmt.Sprintf("%ssummary/", u.source)
u.table = fmt.Sprintf("%sextractTable/", u.source)
u.tissue = fmt.Sprintf("%stissue/", u.source)
u.tutorial = fmt.Sprintf("%stutorial/", u.source)
return u
}
type temps struct {
source string
login string
change string
menu string
result string
search string
tutorial string
}
func setTemps() *temps {
// Stores tmeplate names
t := new(temps)
t.source = "templates/*.html"
t.login = "login"
t.change = "changepassword"
t.menu = "menu"
t.result = "result"
t.search = "search"
t.tutorial = "tutorial"
return t
}
type configuration struct {
name string
appdir string
u *urls
temp *temps
templates *template.Template
config codbutils.Configuration
}
func setConfiguration() *configuration {
// Returns pointer to initialized configuration struct
var c configuration
c.name = "session"
c.appdir = path.Join(iotools.GetGOPATH(), "src/github.com/icwells/compOncDB/app")
c.u = setURLs()
c.temp = setTemps()
c.templates = template.Must(template.ParseGlob(c.temp.source))
c.config = codbutils.SetConfiguration("", false)
return &c
}
func (c *configuration) renderTemplate(tmpl string, out *Output) {
// Renders template and handles errrors
err := c.templates.ExecuteTemplate(out.w, tmpl, out)
if err != nil {
http.Error(out.w, err.Error(), http.StatusInternalServerError)
}
}