forked from FactomProject/factomd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
general.go
59 lines (50 loc) · 1.39 KB
/
general.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
package files
import (
"io"
"net/http"
"strings"
"time"
"github.com/FactomProject/factomd/controlPanel/files/statics"
"github.com/FactomProject/factomd/controlPanel/files/templates"
)
// This is the general handler. The files are split into two categories to speed
// up globbing. Templates are usually parsed with a '*', and had to cycle through all
// static files as well. This handler will decide which category the user is looking for
// and only search within that category. Now can add more static files without affecting
// performance.
type staticFilesFile struct {
data string
mime string
mtime time.Time
size int
}
var TemplatesServer http.Handler = templates.Server
var StaticServer http.Handler = statics.Server
func Open(name string) (io.ReadCloser, error) {
if strings.Contains(name, "templates/") {
return templates.Open(name[10:])
} else {
return statics.Open(name)
}
}
func ModTime(file string) (t time.Time) {
if strings.Contains(file, "templates/") {
return templates.ModTime(file[10:])
} else {
return statics.ModTime(file)
}
}
func Hash(file string) (s string) {
if strings.Contains(file, "templates/") {
return templates.Hash(file[10:])
} else {
return statics.Hash(file)
}
}
func OpenGlob(name string) ([]io.ReadCloser, error) {
if strings.Contains(name, "templates/") {
return templates.OpenGlob(name[10:])
} else {
return statics.OpenGlob(name)
}
}