summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-19 19:39:08 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-19 19:39:08 -0400
commit37142b5d78d2eace9fef79d20793b0d42965dae5 (patch)
tree3c0c93fc5daba9916cf00d9dfce1007927694f8f
parent75e9f55daa3946ae3b51cbcf3204d5131e420a84 (diff)
downloadgetwtxt-37142b5d78d2eace9fef79d20793b0d42965dae5.tar.gz
updated internal functionality for registry v0.4.0 v0.4.4
-rw-r--r--svc/db_test.go4
-rw-r--r--svc/init.go2
-rw-r--r--svc/init_test.go6
-rw-r--r--svc/leveldb.go6
-rw-r--r--svc/post.go4
-rw-r--r--svc/post_test.go6
-rw-r--r--svc/query_test.go6
-rw-r--r--svc/sqlite.go6
8 files changed, 20 insertions, 20 deletions
diff --git a/svc/db_test.go b/svc/db_test.go
index 7d3386c..1d2f7cf 100644
--- a/svc/db_test.go
+++ b/svc/db_test.go
@@ -21,7 +21,7 @@ func Test_pushpullDatabase(t *testing.T) {
 		t.Errorf("Couldn't set up test: %v\n", err)
 	}
 
-	twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "", net.ParseIP("127.0.0.1"), statusmap)
+	twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap)
 
 	remoteRegistries.List = append(remoteRegistries.List, "https://twtxt.tilde.institute/api/plain/users")
 
@@ -65,7 +65,7 @@ func Benchmark_pushDatabase(b *testing.B) {
 			b.Errorf("Couldn't set up benchmark: %v\n", err)
 		}
 
-		twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "", net.ParseIP("127.0.0.1"), statusmap)
+		twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap)
 	}
 
 	b.ResetTimer()
diff --git a/svc/init.go b/svc/init.go
index 3e7ab5e..419e684 100644
--- a/svc/init.go
+++ b/svc/init.go
@@ -42,7 +42,7 @@ var cTickC = make(chan *tick, 1)
 var tmpls *template.Template
 
 // Holds the registry data in-memory
-var twtxtCache = registry.NewIndex(nil)
+var twtxtCache = registry.New(nil)
 
 // List of other registries submitted to this registry
 var remoteRegistries = &RemoteRegistries{
diff --git a/svc/init_test.go b/svc/init_test.go
index 72c8e3f..21f0bba 100644
--- a/svc/init_test.go
+++ b/svc/init_test.go
@@ -91,10 +91,10 @@ func testConfig() {
 // Creates a fresh mock registry, with a single
 // user and their statuses, for testing.
 func mockRegistry() {
-	twtxtCache = registry.NewIndex(nil)
+	twtxtCache = registry.New(nil)
 	statuses, _, _ := registry.GetTwtxt("https://gbmor.dev/twtxt.txt", nil)
 	parsed, _ := registry.ParseUserTwtxt(statuses, "gbmor", "https://gbmor.dev/twtxt.txt")
-	_ = twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "1", net.ParseIP("127.0.0.1"), parsed)
+	_ = twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), parsed)
 }
 
 // Empties the mock registry's user of statuses
@@ -105,7 +105,7 @@ func killStatuses() {
 	user.Mu.Lock()
 
 	user.Status = registry.NewTimeMap()
-	user.RLen = "0"
+	user.LastModified = "0"
 	twtxtCache.Users["https://gbmor.dev/twtxt.txt"] = user
 
 	user.Mu.Unlock()
diff --git a/svc/leveldb.go b/svc/leveldb.go
index 91d7ca9..3a1fccf 100644
--- a/svc/leveldb.go
+++ b/svc/leveldb.go
@@ -23,7 +23,7 @@ func (lvl *dbLevel) push() error {
 		dbBasket.Put([]byte(k+"*URL"), []byte(v.URL))
 		dbBasket.Put([]byte(k+"*IP"), []byte(v.IP.String()))
 		dbBasket.Put([]byte(k+"*Date"), []byte(v.Date))
-		dbBasket.Put([]byte(k+"*RLen"), []byte(v.RLen))
+		dbBasket.Put([]byte(k+"*LastModified"), []byte(v.LastModified))
 
 		for i, e := range v.Status {
 			rfc := i.Format(time.RFC3339)
@@ -68,8 +68,8 @@ func (lvl *dbLevel) pull() {
 			data.Nick = val
 		case "URL":
 			data.URL = val
-		case "RLen":
-			data.RLen = val
+		case "LastModified":
+			data.LastModified = val
 		case "Date":
 			data.Date = val
 		case "Status":
diff --git a/svc/post.go b/svc/post.go
index 9baafbe..5908673 100644
--- a/svc/post.go
+++ b/svc/post.go
@@ -28,7 +28,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 
 	uip := getIPFromCtx(r.Context())
 
-	out, remoteRegistry, err := registry.GetTwtxt(urls, twtxtCache.Client)
+	out, remoteRegistry, err := registry.GetTwtxt(urls, twtxtCache.HTTPClient)
 	if err != nil {
 		errHTTP(w, r, fmt.Errorf("error fetching twtxt Data: %v", err.Error()), http.StatusBadRequest)
 		return
@@ -52,7 +52,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 		statuses, err := registry.ParseUserTwtxt(out, nick, urls)
 		errLog("Error Parsing User Data: ", err)
 
-		if err := twtxtCache.AddUser(nick, urls, "", uip, statuses); err != nil {
+		if err := twtxtCache.AddUser(nick, urls, uip, statuses); err != nil {
 			errHTTP(w, r, fmt.Errorf("error adding user to cache: %v", err.Error()), http.StatusBadRequest)
 			break
 		}
diff --git a/svc/post_test.go b/svc/post_test.go
index 1c7e9b5..87db88d 100644
--- a/svc/post_test.go
+++ b/svc/post_test.go
@@ -46,7 +46,7 @@ var apiPostUserCases = []struct {
 func Test_apiPostUser(t *testing.T) {
 	initTestConf()
 	portnum := fmt.Sprintf(":%v", confObj.Port)
-	twtxtCache = registry.NewIndex(nil)
+	twtxtCache = registry.New(nil)
 
 	for _, tt := range apiPostUserCases {
 		t.Run(tt.name, func(t *testing.T) {
@@ -78,7 +78,7 @@ func Test_apiPostUser(t *testing.T) {
 func Benchmark_apiPostUser(b *testing.B) {
 	initTestConf()
 	portnum := fmt.Sprintf(":%v", confObj.Port)
-	twtxtCache = registry.NewIndex(nil)
+	twtxtCache = registry.New(nil)
 
 	params := url.Values{}
 	params.Set("url", "https://gbmor.dev/twtxt.txt")
@@ -91,7 +91,7 @@ func Benchmark_apiPostUser(b *testing.B) {
 		apiEndpointPOSTHandler(rr, req)
 
 		b.StopTimer()
-		twtxtCache = registry.NewIndex(nil)
+		twtxtCache = registry.New(nil)
 		b.StartTimer()
 	}
 }
diff --git a/svc/query_test.go b/svc/query_test.go
index 414f99b..5581592 100644
--- a/svc/query_test.go
+++ b/svc/query_test.go
@@ -55,7 +55,7 @@ func Test_parseQueryOut(t *testing.T) {
 		t.Errorf("Couldn't set up test: %v\n", err)
 	}
 
-	twtxtCache.AddUser(nick, urls, "", net.ParseIP("127.0.0.1"), statusmap)
+	twtxtCache.AddUser(nick, urls, net.ParseIP("127.0.0.1"), statusmap)
 
 	t.Run("Parsing Status Query", func(t *testing.T) {
 		data, err := twtxtCache.QueryAllStatuses()
@@ -89,7 +89,7 @@ func Benchmark_parseQueryOut(b *testing.B) {
 		b.Errorf("Couldn't set up test: %v\n", err)
 	}
 
-	twtxtCache.AddUser(nick, urls, "", net.ParseIP("127.0.0.1"), statusmap)
+	twtxtCache.AddUser(nick, urls, net.ParseIP("127.0.0.1"), statusmap)
 
 	data, err := twtxtCache.QueryAllStatuses()
 	if err != nil {
@@ -186,7 +186,7 @@ func Benchmark_compositeStatusQuery(b *testing.B) {
 	initTestConf()
 	statuses, _, _ := registry.GetTwtxt("https://gbmor.dev/twtxt.txt", nil)
 	parsed, _ := registry.ParseUserTwtxt(statuses, "gbmor", "https://gbmor.dev/twtxt.txt")
-	_ = twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "1", net.ParseIP("127.0.0.1"), parsed)
+	_ = twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), parsed)
 	b.ResetTimer()
 
 	for i := 0; i < b.N; i++ {
diff --git a/svc/sqlite.go b/svc/sqlite.go
index 8a7b1a4..c9a9f5a 100644
--- a/svc/sqlite.go
+++ b/svc/sqlite.go
@@ -58,7 +58,7 @@ func (lite *dbSqlite) push() error {
 
 		_, err = txst.Exec(i, true, "nickname", e.Nick)
 		errLog("", err)
-		_, err = txst.Exec(i, true, "rlen", e.RLen)
+		_, err = txst.Exec(i, true, "lastmodified", e.LastModified)
 		errLog("", err)
 		_, err = txst.Exec(i, true, "uip", e.IP)
 		errLog("", err)
@@ -122,8 +122,8 @@ func (lite *dbSqlite) pull() {
 			user.IP = net.ParseIP(string(dBlob))
 		case "date":
 			user.Date = string(dBlob)
-		case "rlen":
-			user.RLen = string(dBlob)
+		case "lastmodified":
+			user.LastModified = string(dBlob)
 		default:
 			thetime, err := time.Parse(time.RFC3339, dataKey)
 			errLog("While pulling statuses from SQLite: ", err)