Skip to content

Commit

Permalink
chore(deps): Bumping deps
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Dec 2, 2023
1 parent fc95698 commit b5016d9
Show file tree
Hide file tree
Showing 32 changed files with 122 additions and 118 deletions.
2 changes: 1 addition & 1 deletion cmd/fibr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

type client struct {
redis redis.Client
telemetry telemetry.Service
amqp *amqp.Client
health *health.Service
telemetry telemetry.Service
}

func newClient(ctx context.Context, config configuration) (client, error) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/fibr/fibr.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ func main() {

clients, err := newClient(ctx, config)
if err != nil {
slog.Error("clients", "err", err)
slog.ErrorContext(ctx, "clients", "err", err)
os.Exit(1)
}

defer clients.Close(ctx)

adapters, err := newAdapters(config, clients)
if err != nil {
slog.Error("adapters", "err", err)
slog.ErrorContext(ctx, "adapters", "err", err)
os.Exit(1)
}

endCtx := clients.health.EndCtx()

services, err := newServices(endCtx, config, clients, adapters)
if err != nil {
slog.Error("services", "err", err)
slog.ErrorContext(ctx, "services", "err", err)
os.Exit(1)
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.21
toolchain go1.21.0

require (
github.com/ViBiOh/ChatPotte v0.3.3
github.com/ViBiOh/ChatPotte v0.4.0
github.com/ViBiOh/absto v1.7.4
github.com/ViBiOh/auth/v2 v2.16.1
github.com/ViBiOh/auth/v2 v2.17.0
github.com/ViBiOh/exas v0.7.1
github.com/ViBiOh/flags v1.4.1
github.com/ViBiOh/httputils/v4 v4.69.0
github.com/ViBiOh/httputils/v4 v4.69.3
github.com/ViBiOh/vith v0.6.0
github.com/rabbitmq/amqp091-go v1.9.0
github.com/redis/go-redis/v9 v9.3.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
github.com/ViBiOh/ChatPotte v0.3.3 h1:WoOAmSSiuXVpcz1X3iDSpvCmJF5IA2a38Hqm0klZUMk=
github.com/ViBiOh/ChatPotte v0.3.3/go.mod h1:hK71q8Yufgo+BVJvn9SmyLP5/ZktuaOj+AcmtoUn+RM=
github.com/ViBiOh/ChatPotte v0.4.0 h1:SfFOhKqrJShi5E9y2tgpdSSnD6XXeZprWC8LGlrFrJg=
github.com/ViBiOh/ChatPotte v0.4.0/go.mod h1:jNab+Xjgh+OOmIuzDeH1TywO5nLgdO3uo85/dn6gbX4=
github.com/ViBiOh/absto v1.7.4 h1:OSHot3kdWXtM9Brjwth3ZgmlXHq2ZUU3L+PmZVrbaLs=
github.com/ViBiOh/absto v1.7.4/go.mod h1:wWKqd0pH9fqxWDZdKhLBnpKFORMdMQJ3tZuu+v3hTrk=
github.com/ViBiOh/auth/v2 v2.16.1 h1:june68lfZ7gZJ3AX/AzMDN5506s1QR6LTZyj0xjjOpc=
github.com/ViBiOh/auth/v2 v2.16.1/go.mod h1:t93zD/GbHiFcqV+cqidCzulnq67iLYGe/aVrP/NHq5E=
github.com/ViBiOh/auth/v2 v2.17.0 h1:g2XJW2R6kP7Ss39H429O50I7rVF+2dK6u9u8ilAB4eM=
github.com/ViBiOh/auth/v2 v2.17.0/go.mod h1:t85ivqXzje7OtmK9koS0Kzcj5HMTWk1i4ua+ILG5b8k=
github.com/ViBiOh/exas v0.7.1 h1:nzh6E1668OFRgoTIJZJa1RybCW64Gd918qi0Z+0Q4WA=
github.com/ViBiOh/exas v0.7.1/go.mod h1:MvIWQZXpWgg45Vsde9bMV48Kb0J8frya8vimmrkQ04E=
github.com/ViBiOh/flags v1.4.1 h1:qEAO70rWTYcVlU9BgCuz0SgMjth12oi502cq3SHDudg=
github.com/ViBiOh/flags v1.4.1/go.mod h1:Ocgx/QhY7WYNfGokFT3kw5C05pDooQyLbI/9ZWwylI4=
github.com/ViBiOh/httputils/v4 v4.69.0 h1:wW5s/Dwzrm2pNQgk9D806UTNtuSHtOJ+/pF9LNVwHIQ=
github.com/ViBiOh/httputils/v4 v4.69.0/go.mod h1:/LwgtwtEHSBpFdnJJCAx/Q7QlyqHQ7c6z68TD0wbY74=
github.com/ViBiOh/httputils/v4 v4.69.3 h1:t3RrCEB4VJqAbZ0IlvavfNc7faJoq7c3CF5BphNC2GY=
github.com/ViBiOh/httputils/v4 v4.69.3/go.mod h1:/LwgtwtEHSBpFdnJJCAx/Q7QlyqHQ7c6z68TD0wbY74=
github.com/ViBiOh/vith v0.6.0 h1:bdLmwgqUEWi3ivShtAhtM9gOZlWQzvZi2Z5b0BRSB1U=
github.com/ViBiOh/vith v0.6.0/go.mod h1:eRqtDU2uB8g85vll4spbnCV93DHyHNAYwXCMIBH1GuQ=
github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
Expand Down
4 changes: 2 additions & 2 deletions pkg/crud/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s Service) browse(ctx context.Context, request provider.Request, item abst
var err error
metadata, err = s.metadata.GetMetadataFor(ctx, item)
if err != nil && !absto.IsNotExist(err) {
slog.Error("load metadata", "err", err, "item", item.Pathname)
slog.ErrorContext(ctx, "load metadata", "err", err, "item", item.Pathname)
}
})

Expand Down Expand Up @@ -73,7 +73,7 @@ func (s Service) getFilesPreviousAndNext(ctx context.Context, item absto.Item, r
var err error
items, err = s.storage.List(ctx, item.Dir())
if err != nil {
slog.Error("list neighbors files", "err", err, "item", item.Pathname)
slog.ErrorContext(ctx, "list neighbors files", "err", err, "item", item.Pathname)
return
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s Service) serveFile(w http.ResponseWriter, r *http.Request, item absto.It
return fmt.Errorf("get reader for `%s`: %w", item.Pathname, err)
}

defer provider.LogClose(file, "crud.serveFile", item.Pathname)
defer provider.LogClose(ctx, file, "crud.serveFile", item.Pathname)

w.Header().Add("Etag", etag)

Expand Down Expand Up @@ -190,7 +190,7 @@ func (s Service) serveGeoJSON(w http.ResponseWriter, r *http.Request, request pr
if query.GetBool(r, "search") {
hash = s.exifHash(ctx, items)
} else if exifs, err := s.metadata.ListDir(ctx, item); err != nil {
slog.Error("list exifs", "err", err, "item", item.Pathname)
slog.ErrorContext(ctx, "list exifs", "err", err, "item", item.Pathname)
} else {
hash = provider.RawHash(exifs)
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func (s Service) generateGeoJSON(ctx context.Context, w io.Writer, request provi
var commaNeeded bool
encoder := json.NewEncoder(w)

provider.SafeWrite(w, `{"type":"FeatureCollection","features":[`)
provider.SafeWrite(ctx, w, `{"type":"FeatureCollection","features":[`)

point := geo.NewPoint(geo.NewPosition(0, 0))
feature := geo.NewFeature(&point, map[string]any{})
Expand All @@ -249,7 +249,7 @@ func (s Service) generateGeoJSON(ctx context.Context, w io.Writer, request provi
}

if commaNeeded {
provider.DoneWriter(isDone, w, ",")
provider.DoneWriter(ctx, isDone, w, ",")
} else {
commaNeeded = true
}
Expand All @@ -261,11 +261,11 @@ func (s Service) generateGeoJSON(ctx context.Context, w io.Writer, request provi
feature.Properties["date"] = exif.Date.Format(time.RFC850)

if err := encoder.Encode(feature); err != nil {
slog.Error("encode feature", "err", err, "item", item.Pathname)
slog.ErrorContext(ctx, "encode feature", "err", err, "item", item.Pathname)
}
}

provider.SafeWrite(w, "]}")
provider.SafeWrite(ctx, w, "]}")
}

func dichotomicFind(items []absto.Item, id string) absto.Item {
Expand Down
19 changes: 10 additions & 9 deletions pkg/crud/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s Service) list(ctx context.Context, request provider.Request, message ren

directoryAggregate, err = s.metadata.GetAggregateFor(ctx, item)
if err != nil && !absto.IsNotExist(err) {
listLogger(item.Pathname).Error("get aggregate", "err", err)
listLogger(item.Pathname).ErrorContext(ctx, "get aggregate", "err", err)
}
})

Expand All @@ -48,7 +48,7 @@ func (s Service) list(ctx context.Context, request provider.Request, message ren

aggregates, err = s.metadata.GetAllAggregateFor(ctx, files...)
if err != nil {
listLogger(item.Pathname).Error("list aggregates", "err", err)
listLogger(item.Pathname).ErrorContext(ctx, "list aggregates", "err", err)
}
})

Expand All @@ -58,7 +58,7 @@ func (s Service) list(ctx context.Context, request provider.Request, message ren

metadatas, err = s.metadata.GetAllMetadataFor(ctx, files...)
if err != nil {
listLogger(item.Pathname).Error("list metadatas", "err", err)
listLogger(item.Pathname).ErrorContext(ctx, "list metadatas", "err", err)
}
})

Expand All @@ -71,7 +71,7 @@ func (s Service) list(ctx context.Context, request provider.Request, message ren

thumbnails, err = s.thumbnail.ListDir(ctx, item)
if err != nil {
listLogger(item.Pathname).Error("list thumbnail", "err", err)
listLogger(item.Pathname).ErrorContext(ctx, "list thumbnail", "err", err)
return
}
}()
Expand All @@ -85,7 +85,7 @@ func (s Service) list(ctx context.Context, request provider.Request, message ren

savedSearches, err = s.searchService.List(ctx, item)
if err != nil {
listLogger(item.Pathname).Error("list saved searches", "err", err)
listLogger(item.Pathname).ErrorContext(ctx, "list saved searches", "err", err)
return
}
}()
Expand Down Expand Up @@ -160,9 +160,12 @@ func (s Service) enrichThumbnail(ctx context.Context, directoryAggregate provide

func (s Service) Download(w http.ResponseWriter, r *http.Request, request provider.Request, items []absto.Item) {
zipWriter := zip.NewWriter(w)

ctx := r.Context()

defer func() {
if closeErr := zipWriter.Close(); closeErr != nil {
slog.Error("close zip", "err", closeErr)
slog.ErrorContext(ctx, "close zip", "err", closeErr)
}
}()

Expand All @@ -173,8 +176,6 @@ func (s Service) Download(w http.ResponseWriter, r *http.Request, request provid

w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s.zip", filename))

ctx := r.Context()

if err := s.zipItems(ctx, ctx.Done(), request, zipWriter, items); err != nil {
s.error(w, r, request, err)
}
Expand All @@ -184,7 +185,7 @@ func (s Service) zipItems(ctx context.Context, done <-chan struct{}, request pro
for _, item := range items {
select {
case <-done:
slog.Error("context is done for zipping files")
slog.ErrorContext(ctx, "context is done for zipping files")
return nil
default:
relativeURL := request.RelativeURL(item)
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/regenerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s Service) regenerate(w http.ResponseWriter, r *http.Request, request prov
return nil
})
if err != nil {
slog.Error("regenerate", "err", err, "pathname", pathname)
slog.ErrorContext(ctx, "regenerate", "err", err, "pathname", pathname)
}

for _, directory := range directories {
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (s Service) search(r *http.Request, request provider.Request, item absto.It

metadatas, err := s.metadata.GetAllMetadataFor(ctx, files...)
if err != nil {
listLogger(item.Pathname).Error("list metadatas: %s", err)
listLogger(item.Pathname).ErrorContext(ctx, "list metadatas: %s", err)
}

items := make([]provider.RenderItem, len(files))
Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s Service) createShare(w http.ResponseWriter, r *http.Request, request pro

if r.Header.Get("Accept") == "text/plain" {
w.WriteHeader(http.StatusCreated)
provider.SafeWrite(w, id)
provider.SafeWrite(ctx, w, id)

return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/crud/story.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s Service) story(r *http.Request, request provider.Request, item absto.Ite

directoryAggregate, err = s.metadata.GetAggregateFor(ctx, item)
if err != nil && !absto.IsNotExist(err) {
slog.Error("get aggregate", "err", err, "fn", "crud.story", "item", request.Path)
slog.ErrorContext(ctx, "get aggregate", "err", err, "fn", "crud.story", "item", request.Path)
}
})

Expand All @@ -40,7 +40,7 @@ func (s Service) story(r *http.Request, request provider.Request, item absto.Ite

exifs, err = s.metadata.GetAllMetadataFor(ctx, files...)
if err != nil {
slog.Error("list exifs", "err", err, "item", request.Path, "fn", "crud.story")
slog.ErrorContext(ctx, "list exifs", "err", err, "item", request.Path, "fn", "crud.story")
}
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/crud/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s Service) saveUploadedFile(ctx context.Context, request provider.Request,
if err == nil {
go func(ctx context.Context) {
if info, infoErr := s.storage.Stat(ctx, filePath); infoErr != nil {
slog.Error("get info for upload event", "err", infoErr)
slog.ErrorContext(ctx, "get info for upload event", "err", infoErr)
} else {
s.pushEvent(ctx, provider.NewUploadEvent(ctx, request, info, s.bestSharePath(filePath), s.renderer))
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func (s Service) upload(w http.ResponseWriter, r *http.Request, request provider
func (s Service) postUpload(w http.ResponseWriter, r *http.Request, request provider.Request, fileName string) {
if r.Header.Get("Accept") == "text/plain" {
w.WriteHeader(http.StatusCreated)
provider.SafeWrite(w, fileName)
provider.SafeWrite(r.Context(), w, fileName)

return
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/crud/upload_chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (s Service) uploadChunk(w http.ResponseWriter, r *http.Request, request pro

defer func() {
if closeErr := writer.Close(); closeErr != nil {
slog.Error("close chunk writer", "err", closeErr)
slog.ErrorContext(r.Context(), "close chunk writer", "err", closeErr)
}

if err == nil {
return
}

if removeErr := os.Remove(tempFile); removeErr != nil {
slog.Error("remove chunk file", "err", removeErr, "file", tempFile)
slog.ErrorContext(r.Context(), "remove chunk file", "err", removeErr, "file", tempFile)
}
}()

Expand All @@ -79,7 +79,7 @@ func (s Service) mergeChunk(w http.ResponseWriter, r *http.Request, request prov
tempFolder := filepath.Join(s.temporaryFolder, provider.Hash(fileName))
tempFile := filepath.Join(tempFolder, fileName)

if err := s.mergeChunkFiles(tempFolder, tempFile); err != nil {
if err := s.mergeChunkFiles(ctx, tempFolder, tempFile); err != nil {
s.error(w, r, request, model.WrapInternal(err))
return
}
Expand Down Expand Up @@ -113,47 +113,47 @@ func (s Service) mergeChunk(w http.ResponseWriter, r *http.Request, request prov

go func(ctx context.Context) {
if info, infoErr := s.storage.Stat(ctx, filePath); infoErr != nil {
slog.Error("get info for upload event", "err", infoErr)
slog.ErrorContext(ctx, "get info for upload event", "err", infoErr)
} else {
s.pushEvent(ctx, provider.NewUploadEvent(ctx, request, info, s.bestSharePath(filePath), s.renderer))
}
}(cntxt.WithoutDeadline(ctx))

if err = os.RemoveAll(tempFolder); err != nil {
slog.Error("delete chunk folder", "err", err, "folder", tempFolder)
slog.ErrorContext(ctx, "delete chunk folder", "err", err, "folder", tempFolder)
}

s.postUpload(w, r, request, fileName)
}

func (s Service) mergeChunkFiles(directory, destination string) error {
func (s Service) mergeChunkFiles(ctx context.Context, directory, destination string) error {
writer, err := os.OpenFile(destination, os.O_RDWR|os.O_CREATE|os.O_TRUNC, absto.RegularFilePerm)
if err != nil {
return fmt.Errorf("open destination file `%s`: %w", destination, err)
}

defer func() {
if closeErr := writer.Close(); closeErr != nil {
slog.Error("close chunk's destination", "err", closeErr)
slog.ErrorContext(ctx, "close chunk's destination", "err", closeErr)
}

if err == nil {
return
}

if removeErr := os.Remove(destination); removeErr != nil {
slog.Error("remove chunk's destination", "err", removeErr, "destination", destination)
slog.ErrorContext(ctx, "remove chunk's destination", "err", removeErr, "destination", destination)
}
}()

if err = browseChunkFiles(directory, destination, writer); err != nil {
if err = browseChunkFiles(ctx, directory, destination, writer); err != nil {
return fmt.Errorf("walk chunks in `%s`: %w", directory, err)
}

return nil
}

func browseChunkFiles(directory, destination string, writer io.Writer) error {
func browseChunkFiles(ctx context.Context, directory, destination string, writer io.Writer) error {
return filepath.WalkDir(directory, func(path string, info fs.DirEntry, err error) error {
if err != nil {
return err
Expand All @@ -170,7 +170,7 @@ func browseChunkFiles(directory, destination string, writer io.Writer) error {

defer func() {
if closeErr := reader.Close(); closeErr != nil {
slog.Error("close chunk", "err", err, "path", path)
slog.ErrorContext(ctx, "close chunk", "err", err, "path", path)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion pkg/crud/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s Service) createWebhook(w http.ResponseWriter, r *http.Request, request p

if r.Header.Get("Accept") == "text/plain" {
w.WriteHeader(http.StatusCreated)
provider.SafeWrite(w, id)
provider.SafeWrite(ctx, w, id)

return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fibr/fibr.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ func convertAuthenticationError(err error) error {
}

func logRequest(r *http.Request) {
slog.Warn("Unauthenticated request", "method", r.Method, "url", r.URL.String(), "ip", provider.GetIP(r))
slog.WarnContext(r.Context(), "Unauthenticated request", "method", r.Method, "url", r.URL.String(), "ip", provider.GetIP(r))
}
2 changes: 1 addition & 1 deletion pkg/metadata/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s Service) AMQPHandler(ctx context.Context, message amqp.Delivery) error {
}

if resp.Exif.IsZero() {
slog.Debug("no exif", "item", resp.Item.Pathname)
slog.DebugContext(ctx, "no exif", "item", resp.Item.Pathname)
return nil
}

Expand Down
Loading

0 comments on commit b5016d9

Please sign in to comment.