summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
Diffstat (limited to 'svc')
-rw-r--r--svc/cache.go16
-rw-r--r--svc/conf.go28
-rw-r--r--svc/db.go13
-rw-r--r--svc/http.go10
-rw-r--r--svc/init.go12
-rw-r--r--svc/types.go67
6 files changed, 68 insertions, 78 deletions
diff --git a/svc/cache.go b/svc/cache.go
index fb6a9ab..db427db 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -5,9 +5,25 @@ import (
 	"io/ioutil"
 	"log"
 	"os"
+	"sync"
 	"time"
 )
 
+// RemoteRegistries holds a list of remote registries to
+// periodically scrape for new users. The remote registries
+// must have been added via POST like a user.
+type RemoteRegistries struct {
+	Mu   sync.RWMutex
+	List []string
+}
+
+type staticAssets struct {
+	index    []byte
+	indexMod time.Time
+	css      []byte
+	cssMod   time.Time
+}
+
 func cacheTimer() bool {
 	confObj.Mu.RLock()
 	answer := time.Since(confObj.LastCache) > confObj.CacheInterval
diff --git a/svc/conf.go b/svc/conf.go
index 4a75011..24ff305 100644
--- a/svc/conf.go
+++ b/svc/conf.go
@@ -6,12 +6,40 @@ import (
 	"os"
 	"path/filepath"
 	"strings"
+	"sync"
 	"time"
 
 	"github.com/fsnotify/fsnotify"
 	"github.com/spf13/viper"
 )
 
+// Configuration object definition
+type Configuration struct {
+	Mu            sync.RWMutex
+	Port          int           `yaml:"ListenPort"`
+	LogFile       string        `yaml:"LogFile"`
+	DBType        string        `yaml:"DatabaseType"`
+	DBPath        string        `yaml:"DatabasePath"`
+	AssetsDir     string        `yaml:"-"`
+	StdoutLogging bool          `yaml:"StdoutLogging"`
+	Version       string        `yaml:"-"`
+	CacheInterval time.Duration `yaml:"StatusFetchInterval"`
+	DBInterval    time.Duration `yaml:"DatabasePushInterval"`
+	LastCache     time.Time     `yaml:"-"`
+	LastPush      time.Time     `yaml:"-"`
+	Instance      `yaml:"Instance"`
+}
+
+// Instance refers to this specific instance of getwtxt
+type Instance struct {
+	Vers  string `yaml:"-"`
+	Name  string `yaml:"Instance.SiteName"`
+	URL   string `yaml:"Instance.URL"`
+	Owner string `yaml:"Instance.OwnerName"`
+	Mail  string `yaml:"Instance.Email"`
+	Desc  string `yaml:"Instance.Description"`
+}
+
 func initTemplates() *template.Template {
 	confObj.Mu.RLock()
 	assetsDir := confObj.AssetsDir
diff --git a/svc/db.go b/svc/db.go
index 2289771..0bb96ee 100644
--- a/svc/db.go
+++ b/svc/db.go
@@ -11,6 +11,19 @@ import (
 	"github.com/syndtr/goleveldb/leveldb"
 )
 
+type dbLevel struct {
+	db *leveldb.DB
+}
+
+type dbSqlite struct {
+	db *sql.DB
+}
+
+type dbase interface {
+	push() error
+	pull()
+}
+
 // Pull DB data into cache, if available.
 func initDatabase() {
 	var db dbase
diff --git a/svc/http.go b/svc/http.go
index ddf8669..347430e 100644
--- a/svc/http.go
+++ b/svc/http.go
@@ -8,6 +8,16 @@ import (
 	"strings"
 )
 
+// content-type consts
+const txtutf8 = "text/plain; charset=utf-8"
+const htmlutf8 = "text/html; charset=utf-8"
+const cssutf8 = "text/css; charset=utf-8"
+
+// ipCtxKey is the Context value key for user IP addresses
+type ipCtxKey int
+
+const ctxKey ipCtxKey = iota
+
 // Attaches a request's IP address to the request's context.
 // If getwtxt is behind a reverse proxy, get the last entry
 // in the X-Forwarded-For or X-Real-IP HTTP header as the user IP.
diff --git a/svc/init.go b/svc/init.go
index 01e1192..aed3449 100644
--- a/svc/init.go
+++ b/svc/init.go
@@ -38,17 +38,7 @@ var twtxtCache = registry.NewIndex()
 
 var remoteRegistries = &RemoteRegistries{}
 
-var staticCache = &struct {
-	index    []byte
-	indexMod time.Time
-	css      []byte
-	cssMod   time.Time
-}{
-	index:    nil,
-	indexMod: time.Time{},
-	css:      nil,
-	cssMod:   time.Time{},
-}
+var staticCache = &staticAssets{}
 
 // I'm not using init() because it runs
 // even during testing and was causing
diff --git a/svc/types.go b/svc/types.go
deleted file mode 100644
index 978e0df..0000000
--- a/svc/types.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package svc // import "github.com/getwtxt/getwtxt/svc"
-
-import (
-	"database/sql"
-	"sync"
-	"time"
-
-	"github.com/syndtr/goleveldb/leveldb"
-)
-
-// content-type consts
-const txtutf8 = "text/plain; charset=utf-8"
-const htmlutf8 = "text/html; charset=utf-8"
-const cssutf8 = "text/css; charset=utf-8"
-
-// Configuration object definition
-type Configuration struct {
-	Mu            sync.RWMutex
-	Port          int           `yaml:"ListenPort"`
-	LogFile       string        `yaml:"LogFile"`
-	DBType        string        `yaml:"DatabaseType"`
-	DBPath        string        `yaml:"DatabasePath"`
-	AssetsDir     string        `yaml:"-"`
-	StdoutLogging bool          `yaml:"StdoutLogging"`
-	Version       string        `yaml:"-"`
-	CacheInterval time.Duration `yaml:"StatusFetchInterval"`
-	DBInterval    time.Duration `yaml:"DatabasePushInterval"`
-	LastCache     time.Time     `yaml:"-"`
-	LastPush      time.Time     `yaml:"-"`
-	Instance      `yaml:"Instance"`
-}
-
-// Instance refers to this specific instance of getwtxt
-type Instance struct {
-	Vers  string `yaml:"-"`
-	Name  string `yaml:"Instance.SiteName"`
-	URL   string `yaml:"Instance.URL"`
-	Owner string `yaml:"Instance.OwnerName"`
-	Mail  string `yaml:"Instance.Email"`
-	Desc  string `yaml:"Instance.Description"`
-}
-
-type dbLevel struct {
-	db *leveldb.DB
-}
-
-type dbSqlite struct {
-	db *sql.DB
-}
-
-type dbase interface {
-	push() error
-	pull()
-}
-
-// RemoteRegistries holds a list of remote registries to
-// periodically scrape for new users. The remote registries
-// must have been added via POST like a user.
-type RemoteRegistries struct {
-	Mu   sync.RWMutex
-	List []string
-}
-
-// ipCtxKey is the Context value key for user IP addresses
-type ipCtxKey int
-
-const ctxKey ipCtxKey = iota
6'>^
201458e3 ^
204dae92 ^







201458e3 ^
204dae92 ^

201458e3 ^

204dae92 ^
201458e3 ^
204dae92 ^


201458e3 ^

204dae92 ^

201458e3 ^

204dae92 ^





201458e3 ^
204dae92 ^

672e3e50 ^


a654e4ec ^
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131