-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,951 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,11 @@ build: | |
|
||
.PHONY: run | ||
run: | ||
go run | ||
go run ./... | ||
|
||
.PHONY: dev | ||
dev: | ||
air | ||
|
||
.PHONY: lint | ||
lint: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,53 @@ | ||
module github.com/cloudlena/s3manager | ||
|
||
go 1.23.4 | ||
go 1.23.5 | ||
|
||
require ( | ||
github.com/cloudlena/adapters v0.0.0-20250106081220-31472cba684a | ||
github.com/gofiber/fiber/v2 v2.52.6 | ||
github.com/gofiber/template/html/v2 v2.1.3 | ||
github.com/gorilla/mux v1.8.1 | ||
github.com/matryer/is v1.4.1 | ||
github.com/minio/minio-go/v7 v7.0.83 | ||
github.com/minio/minio-go/v7 v7.0.85 | ||
github.com/spf13/viper v1.19.0 | ||
) | ||
|
||
require ( | ||
github.com/andybalholm/brotli v1.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.1 // indirect | ||
github.com/fsnotify/fsnotify v1.8.0 // indirect | ||
github.com/go-ini/ini v1.67.0 // indirect | ||
github.com/goccy/go-json v0.10.4 // indirect | ||
github.com/goccy/go-json v0.10.5 // indirect | ||
github.com/gofiber/template v1.8.3 // indirect | ||
github.com/gofiber/utils v1.1.0 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/klauspost/compress v1.17.11 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.9 // indirect | ||
github.com/magiconair/properties v1.8.9 // indirect | ||
github.com/mattn/go-colorable v0.1.14 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mattn/go-runewidth v0.0.16 // indirect | ||
github.com/minio/md5-simd v1.1.2 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect | ||
github.com/rivo/uniseg v0.4.7 // indirect | ||
github.com/rs/xid v1.6.0 // indirect | ||
github.com/sagikazarmark/locafero v0.6.0 // indirect | ||
github.com/sagikazarmark/locafero v0.7.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.11.0 // indirect | ||
github.com/spf13/afero v1.12.0 // indirect | ||
github.com/spf13/cast v1.7.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/pflag v1.0.6 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/valyala/fasthttp v1.58.0 // indirect | ||
github.com/valyala/tcplisten v1.0.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
golang.org/x/crypto v0.32.0 // indirect | ||
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect | ||
golang.org/x/crypto v0.33.0 // indirect | ||
golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3 // indirect | ||
golang.org/x/net v0.34.0 // indirect | ||
golang.org/x/sys v0.29.0 // indirect | ||
golang.org/x/text v0.21.0 // indirect | ||
golang.org/x/sys v0.30.0 // indirect | ||
golang.org/x/text v0.22.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package s3manager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// HandleBucketList renders all buckets as an HTML list. | ||
func (s *S3Manager) HandleBucketList(c *fiber.Ctx) error { | ||
buckets, err := s.s3.ListBuckets(c.Context()) | ||
if err != nil { | ||
return fmt.Errorf("error listing buckets: %w", err) | ||
} | ||
|
||
return c.Render("bucket-list", fiber.Map{ | ||
"Buckets": buckets, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package s3manager_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cloudlena/s3manager/internal/s3manager" | ||
"github.com/cloudlena/s3manager/internal/s3manager/mocks" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/template/html/v2" | ||
"github.com/matryer/is" | ||
"github.com/minio/minio-go/v7" | ||
) | ||
|
||
func TestHandleBucketList(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
it string | ||
listBucketsVal []minio.BucketInfo | ||
listBucketsErr error | ||
expectedStatusCode int | ||
expectedBodyContains string | ||
}{ | ||
{ | ||
it: "renders a list of buckets", | ||
listBucketsVal: []minio.BucketInfo{{Name: "BUCKET-NAME"}}, | ||
expectedStatusCode: http.StatusOK, | ||
expectedBodyContains: "BUCKET-NAME", | ||
}, | ||
{ | ||
it: "renders placeholder if no buckets", | ||
expectedStatusCode: http.StatusOK, | ||
expectedBodyContains: "No buckets yet", | ||
}, | ||
{ | ||
it: "returns error if there is an S3 error", | ||
listBucketsErr: errors.New("mocked s3 error"), | ||
expectedStatusCode: http.StatusInternalServerError, | ||
expectedBodyContains: "mocked s3 error", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run(tc.it, func(t *testing.T) { | ||
t.Parallel() | ||
is := is.New(t) | ||
|
||
s3 := &mocks.S3Mock{ | ||
ListBucketsFunc: func(ctx context.Context) ([]minio.BucketInfo, error) { | ||
return tc.listBucketsVal, tc.listBucketsErr | ||
}, | ||
} | ||
server := s3manager.New(s3, true, "", "") | ||
|
||
engine := html.New("../../views", ".html") | ||
app := fiber.New(fiber.Config{ | ||
Views: engine, | ||
}) | ||
app.Get("/bucket-list", server.HandleBucketList) | ||
|
||
req, err := http.NewRequest(fiber.MethodGet, "/bucket-list", nil) | ||
is.NoErr(err) | ||
|
||
resp, err := app.Test(req) | ||
is.NoErr(err) | ||
defer resp.Body.Close() | ||
body, err := io.ReadAll(resp.Body) | ||
is.NoErr(err) | ||
|
||
is.Equal(resp.StatusCode, tc.expectedStatusCode) // status code | ||
is.True(strings.Contains(string(body), tc.expectedBodyContains)) // body | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package s3manager | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// HandleBucketsView renders all buckets on an HTML page. | ||
func (s *S3Manager) HandleBucketsView(c *fiber.Ctx) error { | ||
return c.Render("buckets", fiber.Map{}) | ||
} |
Oops, something went wrong.