-
Notifications
You must be signed in to change notification settings - Fork 6
/
form.go
98 lines (78 loc) · 3.46 KB
/
form.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
package config
import "path"
// AssetPrefix is the path prefix for all goradd assets. It indicates to the program to look for the given file in the assets collection of files
// which in development mode is wherever the file is on the disk, and in release mode, the central asset directory where
// all assets get copied
var AssetPrefix = "/assets/"
// ApiPrefix is the url prefix that indicates this is an API call, like a REST or GraphQL call.
// The default is blank and does not serve a REST API.
// Override this in the goradd_project/config/goradd.go file to implement a REST Api
var ApiPrefix = ""
// WebsocketMessengerPrefix is the url prefix that indicates this is a Websocket call to our messenger service.
// The default turns on Websockets and uses this to implement the Watcher and Messenger
// mechanisms.
// Override this in the goradd_project/config/goradd.go file and set to blank to turn off handling of websockets.
var WebsocketMessengerPrefix = "/grw/"
// Minify controls whether we try to strip out unnecessary whitespace from our HTML output
var Minify bool = !Debug
var assetDirectory string
var htmlDirectory string
// ProxyPath is the url path to the application. By default, this is the root, but you can set it
// to any path. This is particularly useful to making the application appear as if it is running in a subdirectory
// of the root path. This is great for putting behind an Apache server, and using ProxyPass and ProxyPassReverse to direct
// traffic from a particular path to the application. This gets stripped off incoming urls automatically by the server,
// but needs to be added to all links to resources on the server.
var ProxyPath string
var DefaultDateFormat = "January 2, 2006"
var DefaultTimeFormat = "3:04 pm"
var DefaultDateTimeFormat = "January 2, 2006 3:04 pm"
var DefaultDateEntryFormat = "1/2/06"
var DefaultTimeEntryFormat = "3:04 pm"
var DefaultDateTimeEntryFormat = "1/2/06 3:04 pm"
// SelectOneString is used in selection lists as the default item to indicate that a selection is required but has not yet been made
var SelectOneString = "- Select One -"
// NoSelectionString is used in selection lists as the item that indicates no selection when a selection is not required
var NoSelectionString = "-"
func SetAssetDirectory(assetDir string) {
if Release && assetDir == "" {
panic("The -assetDir flag is required when running the release build")
}
assetDirectory = assetDir
}
func AssetDirectory() string {
return assetDirectory
}
func SetHtmlDirectory(d string) {
htmlDirectory = d
}
func HtmlDirectory() string {
return htmlDirectory
}
type LocalPathMaker func(string)string
var localPathMaker LocalPathMaker = defaultLocalPathMaker
func defaultLocalPathMaker(p string) string {
var hasSlash bool
if p == "" {
panic(`cannot make a local path to an empty path. If you are trying to refer to the root, use '/'.`)
}
if p[len(p)-1:] == "/" {
hasSlash = true
}
if p[0:1] == "/" && ProxyPath != "" {
p = path.Join(ProxyPath, p) // will strip trailing slashes
if hasSlash {
p = p + "/"
}
}
return p
}
// MakeLocalPath turns a path that points to a resource on this computer into a path that will reach
// that resource. It takes into account a variety of settings that may affect the path and that will
// depend on how the app is deployed.
// You can inject your own local path maker using SetLocalPathMaker
func MakeLocalPath(p string) string {
return localPathMaker(p)
}
func SetLocalPathMaker(f LocalPathMaker) {
localPathMaker = f
}