From 538e305925b9b04102ef0a4fb7cca19a6c116142 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Sat, 20 Jun 2020 02:27:31 -0400 Subject: updating module to live at sourcehut Also moving the 'registry' library into this repo, rather than maintaining them separately. It will still be decoupled, just live in this repository. --- svc/README.md | 8 -------- svc/cache.go | 2 +- svc/cache_test.go | 6 +++--- svc/conf.go | 2 +- svc/db.go | 2 +- svc/db_test.go | 22 +++++++++++----------- svc/handlers.go | 4 ++-- svc/handlers_test.go | 2 +- svc/help.go | 6 +++--- svc/http.go | 2 +- svc/init.go | 4 ++-- svc/init_test.go | 16 +++++++++------- svc/leveldb.go | 4 ++-- svc/periodic.go | 2 +- svc/post.go | 4 ++-- svc/post_test.go | 8 ++++---- svc/query.go | 4 ++-- svc/query_test.go | 14 +++++++------- svc/sqlite.go | 4 ++-- svc/svc.go | 2 +- 20 files changed, 56 insertions(+), 62 deletions(-) delete mode 100644 svc/README.md (limited to 'svc') diff --git a/svc/README.md b/svc/README.md deleted file mode 100644 index 797b7ab..0000000 --- a/svc/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# `getwtxt|svc` - -This is an internal package created for code organization -purposes. - -The file `getwtxt.go` in the parent directory calls -`svc.go::Start()`, which starts the registry server. - diff --git a/svc/cache.go b/svc/cache.go index f887d05..16287bf 100644 --- a/svc/cache.go +++ b/svc/cache.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "bytes" diff --git a/svc/cache_test.go b/svc/cache_test.go index 96c2638..c37f099 100644 --- a/svc/cache_test.go +++ b/svc/cache_test.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "bytes" @@ -27,7 +27,7 @@ import ( "reflect" "testing" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" ) func Test_initTemplates(t *testing.T) { @@ -49,7 +49,7 @@ func Test_cacheUpdate(t *testing.T) { killStatuses() cacheUpdate() - urls := "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt" + urls := testTwtxtURL newStatus := twtxtCache.Users[urls].Status t.Run("Checking for any data", func(t *testing.T) { diff --git a/svc/conf.go b/svc/conf.go index 8968ed4..7365b2b 100644 --- a/svc/conf.go +++ b/svc/conf.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "log" diff --git a/svc/db.go b/svc/db.go index 34b7c34..8cd05d1 100644 --- a/svc/db.go +++ b/svc/db.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "log" diff --git a/svc/db_test.go b/svc/db_test.go index f54d610..21fc972 100644 --- a/svc/db_test.go +++ b/svc/db_test.go @@ -17,30 +17,30 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "net" "testing" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" ) func Test_pushpullDatabase(t *testing.T) { initTestConf() initTestDB() - out, _, err := registry.GetTwtxt("https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", nil) + out, _, err := registry.GetTwtxt(testTwtxtURL, nil) if err != nil { t.Errorf("Couldn't set up test: %v\n", err) } - statusmap, err := registry.ParseUserTwtxt(out, "getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt") + statusmap, err := registry.ParseUserTwtxt(out, "getwtxttest", testTwtxtURL) if err != nil { t.Errorf("Couldn't set up test: %v\n", err) } - twtxtCache.AddUser("getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap) + twtxtCache.AddUser("getwtxttest", testTwtxtURL, net.ParseIP("127.0.0.1"), statusmap) remoteRegistries.List = append(remoteRegistries.List, "https://twtxt.tilde.institute/api/plain/users") @@ -52,7 +52,7 @@ func Test_pushpullDatabase(t *testing.T) { }) t.Run("Clearing Registry", func(t *testing.T) { - err := twtxtCache.DelUser("https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt") + err := twtxtCache.DelUser(testTwtxtURL) if err != nil { t.Errorf("%v", err) } @@ -62,7 +62,7 @@ func Test_pushpullDatabase(t *testing.T) { pullDB() twtxtCache.Mu.RLock() - if _, ok := twtxtCache.Users["https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt"]; !ok { + if _, ok := twtxtCache.Users[testTwtxtURL]; !ok { t.Errorf("Missing user previously pushed to database\n") } twtxtCache.Mu.RUnlock() @@ -73,18 +73,18 @@ func Benchmark_pushDatabase(b *testing.B) { initTestConf() initTestDB() - if _, ok := twtxtCache.Users["https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt"]; !ok { - out, _, err := registry.GetTwtxt("https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", nil) + if _, ok := twtxtCache.Users[testTwtxtURL]; !ok { + out, _, err := registry.GetTwtxt(testTwtxtURL, nil) if err != nil { b.Errorf("Couldn't set up benchmark: %v\n", err) } - statusmap, err := registry.ParseUserTwtxt(out, "getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt") + statusmap, err := registry.ParseUserTwtxt(out, "getwtxttest", testTwtxtURL) if err != nil { b.Errorf("Couldn't set up benchmark: %v\n", err) } - twtxtCache.AddUser("getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap) + twtxtCache.AddUser("getwtxttest", testTwtxtURL, net.ParseIP("127.0.0.1"), statusmap) } b.ResetTimer() diff --git a/svc/handlers.go b/svc/handlers.go index 7ce4b77..cb07349 100644 --- a/svc/handlers.go +++ b/svc/handlers.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "fmt" @@ -27,7 +27,7 @@ import ( "strings" "time" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" "github.com/gorilla/mux" ) diff --git a/svc/handlers_test.go b/svc/handlers_test.go index a2d77e2..46151d7 100644 --- a/svc/handlers_test.go +++ b/svc/handlers_test.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "bytes" diff --git a/svc/help.go b/svc/help.go index 3cc60ff..6eb5be7 100644 --- a/svc/help.go +++ b/svc/help.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import "fmt" @@ -31,7 +31,7 @@ func titleScreen() { \__, |\___|\__| \_/\_/ \__/_/\_\\__| |___/ version ` + Vers + ` - github.com/getwtxt/getwtxt + git.sr.ht/~gbmor/getwtxt GPL v3 `) @@ -284,7 +284,7 @@ func manualScreen() { Adding a user: curl -X POST 'http://localhost:9001/api/plain/users\ - ?url=https://gbmor.dev/twtxt.txt&nickname=gbmor' + ?url=https://example.org/twtxt.txt&nickname=somebody' Retrieve user list: curl 'http://localhost:9001/api/plain/users' diff --git a/svc/http.go b/svc/http.go index 6350e9e..c137d08 100644 --- a/svc/http.go +++ b/svc/http.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "context" diff --git a/svc/init.go b/svc/init.go index 00e107b..3f9d505 100644 --- a/svc/init.go +++ b/svc/init.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "html/template" @@ -26,7 +26,7 @@ import ( "os/signal" "time" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" "github.com/spf13/pflag" ) diff --git a/svc/init_test.go b/svc/init_test.go index 2fbfd5e..0c255c5 100644 --- a/svc/init_test.go +++ b/svc/init_test.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "bytes" @@ -29,10 +29,12 @@ import ( "sync" "testing" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" "github.com/spf13/viper" ) +const testTwtxtURL = "https://git.sr.ht/~gbmor/getwtxt/blob/master/testdata/twtxt.txt" + var ( testport string initTestOnce sync.Once @@ -111,21 +113,21 @@ func testConfig() { // user and their statuses, for testing. func mockRegistry() { twtxtCache = registry.New(nil) - statuses, _, _ := registry.GetTwtxt("https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", nil) - parsed, _ := registry.ParseUserTwtxt(statuses, "getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt") - _ = twtxtCache.AddUser("getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", net.ParseIP("127.0.0.1"), parsed) + statuses, _, _ := registry.GetTwtxt(testTwtxtURL, nil) + parsed, _ := registry.ParseUserTwtxt(statuses, "getwtxttest", testTwtxtURL) + _ = twtxtCache.AddUser("getwtxttest", testTwtxtURL, net.ParseIP("127.0.0.1"), parsed) } // Empties the mock registry's user of statuses // for functions that test status modifications func killStatuses() { twtxtCache.Mu.Lock() - user := twtxtCache.Users["https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt"] + user := twtxtCache.Users[testTwtxtURL] user.Mu.Lock() user.Status = registry.NewTimeMap() user.LastModified = "0" - twtxtCache.Users["https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt"] = user + twtxtCache.Users[testTwtxtURL] = user user.Mu.Unlock() twtxtCache.Mu.Unlock() diff --git a/svc/leveldb.go b/svc/leveldb.go index 16751ce..5fb4a45 100644 --- a/svc/leveldb.go +++ b/svc/leveldb.go @@ -17,14 +17,14 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "net" "strings" "time" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" "github.com/syndtr/goleveldb/leveldb" ) diff --git a/svc/periodic.go b/svc/periodic.go index c8b918b..c6818a6 100644 --- a/svc/periodic.go +++ b/svc/periodic.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "log" diff --git a/svc/post.go b/svc/post.go index db4afd7..bba8136 100644 --- a/svc/post.go +++ b/svc/post.go @@ -17,14 +17,14 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "fmt" "net/http" "strings" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" ) // Requests to apiEndpointPOSTHandler are passed off to this diff --git a/svc/post_test.go b/svc/post_test.go index cd15565..6f68a66 100644 --- a/svc/post_test.go +++ b/svc/post_test.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "fmt" @@ -27,7 +27,7 @@ import ( "strings" "testing" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" ) var apiPostUserCases = []struct { @@ -39,7 +39,7 @@ var apiPostUserCases = []struct { { name: "Known Good User", nick: "getwtxttest", - uri: "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", + uri: testTwtxtURL, wantErr: false, }, { @@ -100,7 +100,7 @@ func Benchmark_apiPostUser(b *testing.B) { twtxtCache = registry.New(nil) params := url.Values{} - params.Set("url", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt") + params.Set("url", testTwtxtURL) params.Set("nickname", "gbmor") req, _ := http.NewRequest("POST", "https://localhost"+portnum+"/api/plain/users", strings.NewReader(params.Encode())) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") diff --git a/svc/query.go b/svc/query.go index 8f22838..6da3601 100644 --- a/svc/query.go +++ b/svc/query.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "crypto/sha256" @@ -28,7 +28,7 @@ import ( "strings" "sync" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" "github.com/gorilla/mux" ) diff --git a/svc/query_test.go b/svc/query_test.go index d2d7304..939592e 100644 --- a/svc/query_test.go +++ b/svc/query_test.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "net" @@ -25,7 +25,7 @@ import ( "strings" "testing" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" ) func Test_dedupe(t *testing.T) { @@ -61,7 +61,7 @@ func Benchmark_dedupe(b *testing.B) { func Test_parseQueryOut(t *testing.T) { initTestConf() - urls := "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt" + urls := testTwtxtURL nick := "getwtxttest" out, _, err := registry.GetTwtxt(urls, nil) @@ -95,7 +95,7 @@ func Test_parseQueryOut(t *testing.T) { func Benchmark_parseQueryOut(b *testing.B) { initTestConf() - urls := "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt" + urls := testTwtxtURL nick := "getwtxttest" out, _, err := registry.GetTwtxt(urls, nil) @@ -203,9 +203,9 @@ func Test_compositeStatusQuery(t *testing.T) { func Benchmark_compositeStatusQuery(b *testing.B) { initTestConf() - statuses, _, _ := registry.GetTwtxt("https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", nil) - parsed, _ := registry.ParseUserTwtxt(statuses, "getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt") - _ = twtxtCache.AddUser("getwtxttest", "https://github.com/getwtxt/getwtxt/raw/master/testdata/twtxt.txt", net.ParseIP("127.0.0.1"), parsed) + statuses, _, _ := registry.GetTwtxt(testTwtxtURL, nil) + parsed, _ := registry.ParseUserTwtxt(statuses, "getwtxttest", testTwtxtURL) + _ = twtxtCache.AddUser("getwtxttest", testTwtxtURL, 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 58a804d..128aed3 100644 --- a/svc/sqlite.go +++ b/svc/sqlite.go @@ -17,14 +17,14 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "database/sql" "net" "time" - "github.com/getwtxt/registry" + "git.sr.ht/~gbmor/getwtxt/registry" _ "github.com/mattn/go-sqlite3" // for the sqlite3 driver ) diff --git a/svc/svc.go b/svc/svc.go index 8c1c63a..72ccdc3 100644 --- a/svc/svc.go +++ b/svc/svc.go @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Getwtxt. If not, see . */ -package svc // import "github.com/getwtxt/getwtxt/svc" +package svc // import "git.sr.ht/~gbmor/getwtxt/svc" import ( "fmt" -- cgit 1.4.1-2-gfad0