diff --git a/filestore.go b/files/filestore.go similarity index 96% rename from filestore.go rename to files/filestore.go index c3843bf..fdf1978 100644 --- a/filestore.go +++ b/files/filestore.go @@ -1,4 +1,4 @@ -package gpaste +package files import ( "io" diff --git a/filestore_fs.go b/files/filestore_fs.go similarity index 99% rename from filestore_fs.go rename to files/filestore_fs.go index da71566..ce19995 100644 --- a/filestore_fs.go +++ b/files/filestore_fs.go @@ -1,4 +1,4 @@ -package gpaste +package files import ( "encoding/json" diff --git a/filestore_fs_test.go b/files/filestore_fs_test.go similarity index 64% rename from filestore_fs_test.go rename to files/filestore_fs_test.go index c473e44..08cf765 100644 --- a/filestore_fs_test.go +++ b/files/filestore_fs_test.go @@ -1,22 +1,22 @@ -package gpaste_test +package files_test import ( "testing" - "git.t-juice.club/torjus/gpaste" + "git.t-juice.club/torjus/gpaste/files" ) func TestFSFileStore(t *testing.T) { dir := t.TempDir() - s, err := gpaste.NewFSFileStore(dir) + s, err := files.NewFSFileStore(dir) if err != nil { t.Fatalf("Error creating store: %s", err) } RunFilestoreTest(s, t) persistentDir := t.TempDir() - newFunc := func() gpaste.FileStore { - s, err := gpaste.NewFSFileStore(persistentDir) + newFunc := func() files.FileStore { + s, err := files.NewFSFileStore(persistentDir) if err != nil { t.Fatalf("Error creating store: %s", err) } diff --git a/filestore_memory.go b/files/filestore_memory.go similarity index 98% rename from filestore_memory.go rename to files/filestore_memory.go index 3011796..0dd7e76 100644 --- a/filestore_memory.go +++ b/files/filestore_memory.go @@ -1,4 +1,4 @@ -package gpaste +package files import ( "bytes" diff --git a/filestore_memory_test.go b/files/filestore_memory_test.go similarity index 50% rename from filestore_memory_test.go rename to files/filestore_memory_test.go index f0cd698..7e2b9d8 100644 --- a/filestore_memory_test.go +++ b/files/filestore_memory_test.go @@ -1,13 +1,13 @@ -package gpaste_test +package files_test import ( "testing" - "git.t-juice.club/torjus/gpaste" + "git.t-juice.club/torjus/gpaste/files" ) func TestMemoryFileStore(t *testing.T) { - s := gpaste.NewMemoryFileStore() + s := files.NewMemoryFileStore() RunFilestoreTest(s, t) } diff --git a/filestore_test.go b/files/filestore_test.go similarity index 92% rename from filestore_test.go rename to files/filestore_test.go index aef18c6..6c7c52f 100644 --- a/filestore_test.go +++ b/files/filestore_test.go @@ -1,4 +1,4 @@ -package gpaste_test +package files_test import ( "bytes" @@ -7,12 +7,12 @@ import ( "testing" "time" - "git.t-juice.club/torjus/gpaste" + "git.t-juice.club/torjus/gpaste/files" "github.com/google/go-cmp/cmp" "github.com/google/uuid" ) -func RunFilestoreTest(s gpaste.FileStore, t *testing.T) { +func RunFilestoreTest(s files.FileStore, t *testing.T) { t.Run("Basic", func(t *testing.T) { // Create dataString := "TEST_LOL_OMG" @@ -20,7 +20,7 @@ func RunFilestoreTest(s gpaste.FileStore, t *testing.T) { bodyBuf := &bytes.Buffer{} bodyBuf.Write([]byte(dataString)) body := io.NopCloser(bodyBuf) - f := &gpaste.File{ + f := &files.File{ ID: id, MaxViews: 0, Body: body, @@ -78,15 +78,15 @@ func RunFilestoreTest(s gpaste.FileStore, t *testing.T) { }) } -func RunPersistentFilestoreTest(newStoreFunc func() gpaste.FileStore, t *testing.T) { +func RunPersistentFilestoreTest(newStoreFunc func() files.FileStore, t *testing.T) { s := newStoreFunc() files := []struct { - File *gpaste.File + File *files.File ExpectedData string }{ { - File: &gpaste.File{ + File: &files.File{ ID: uuid.NewString(), OriginalFilename: "testfile.txt", MaxViews: 5, @@ -96,7 +96,7 @@ func RunPersistentFilestoreTest(newStoreFunc func() gpaste.FileStore, t *testing ExpectedData: "cocks!", }, { - File: &gpaste.File{ + File: &files.File{ ID: uuid.NewString(), OriginalFilename: "testfile2.txt", MaxViews: 5, diff --git a/http.go b/http.go index cbf214a..f9e6461 100644 --- a/http.go +++ b/http.go @@ -6,6 +6,7 @@ import ( "net/http" "strings" + "git.t-juice.club/torjus/gpaste/files" "git.t-juice.club/torjus/gpaste/users" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" @@ -14,7 +15,7 @@ import ( ) type HTTPServer struct { - Files FileStore + Files files.FileStore Users users.UserStore Auth *AuthService config *ServerConfig @@ -29,7 +30,7 @@ func NewHTTPServer(cfg *ServerConfig) *HTTPServer { Logger: zap.NewNop().Sugar(), AccessLogger: zap.NewNop().Sugar(), } - srv.Files = NewMemoryFileStore() + srv.Files = files.NewMemoryFileStore() srv.Users = users.NewMemoryUserStore() srv.Auth = NewAuthService(srv.Users, []byte(srv.config.SigningSecret)) @@ -59,7 +60,7 @@ func (s *HTTPServer) HandlerIndex(w http.ResponseWriter, r *http.Request) { } func (s *HTTPServer) HandlerAPIFilePost(w http.ResponseWriter, r *http.Request) { - f := &File{ + f := &files.File{ ID: uuid.Must(uuid.NewRandom()).String(), Body: r.Body, } @@ -134,7 +135,7 @@ func (s *HTTPServer) processMultiPartFormUpload(w http.ResponseWriter, r *http.R s.Logger.Warnw("Error reading file from multipart form.", "req_id", reqID, "error", err) return } - f := &File{ + f := &files.File{ ID: uuid.Must(uuid.NewRandom()).String(), OriginalFilename: fh.Filename, Body: ff,