summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-06 15:25:02 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-08 02:29:17 -0400
commit469542518c4bb4db00774734c9cb257cd0050076 (patch)
treeed42f78dbc593102fc9b027962c465153e7d36d0
parent3fe7510b7617780e6bcd7bd9a5575f11f59b6e15 (diff)
downloadgetwtxt-469542518c4bb4db00774734c9cb257cd0050076.tar.gz
moved type declarations into respective files
-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