-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_generated_tiddler.go
50 lines (41 loc) · 921 Bytes
/
auto_generated_tiddler.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
package tiddlywikid
import (
"net/http"
"time"
"tiddlywikid/store"
"tiddlywikid/utils"
)
const (
AUTO_GENERATED_NOW = "$:/sync-time"
AUTO_GENERATED_IP = "$:/client-ip"
)
var (
autoGen = make(map[string]AutoGenFn)
autoGenTags = (*store.TiddlerTags)(&[]string{
"auto-generated",
})
)
type AutoGenFn func(r *http.Request) *store.TiddlyWebJSON
func init() {
autoGen = map[string]AutoGenFn{
AUTO_GENERATED_NOW: NewNow,
AUTO_GENERATED_IP: NewSrcIP,
GENERATED_PLUGIN: NewPlugin,
}
}
func NewNow(r *http.Request) *store.TiddlyWebJSON {
return &store.TiddlyWebJSON{
Title: AUTO_GENERATED_NOW,
Text: utils.Now().Format(time.RFC3339Nano),
Tags: autoGenTags,
Type: "text/vnd.tiddlywiki",
}
}
func NewSrcIP(r *http.Request) *store.TiddlyWebJSON {
return &store.TiddlyWebJSON{
Title: AUTO_GENERATED_IP,
Text: r.RemoteAddr,
Tags: autoGenTags,
Type: "text/vnd.tiddlywiki",
}
}