diff options
Diffstat (limited to 'svc')
-rw-r--r-- | svc/cache.go | 16 | ||||
-rw-r--r-- | svc/conf.go | 28 | ||||
-rw-r--r-- | svc/db.go | 13 | ||||
-rw-r--r-- | svc/http.go | 10 | ||||
-rw-r--r-- | svc/init.go | 12 | ||||
-rw-r--r-- | svc/types.go | 67 |
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 |