chore: replace interface with any

This commit is contained in:
Florian Schade
2026-04-23 09:31:11 +02:00
committed by Ralf Haferkamp
parent 8f26149743
commit 288e67cc39
138 changed files with 933 additions and 934 deletions
@@ -26,14 +26,14 @@ import (
// FileConverter is the interface for the file converter
type FileConverter interface {
Convert(r io.Reader) (interface{}, error)
Convert(r io.Reader) (any, error)
}
// GifDecoder is a converter for the gif file
type GifDecoder struct{}
// Convert reads the gif file and returns the thumbnail image
func (i GifDecoder) Convert(r io.Reader) (interface{}, error) {
func (i GifDecoder) Convert(r io.Reader) (any, error) {
img, err := gif.DecodeAll(r)
if err != nil {
return nil, errors.Wrap(err, `could not decode the image`)
@@ -45,7 +45,7 @@ func (i GifDecoder) Convert(r io.Reader) (interface{}, error) {
type GgsDecoder struct{ thumbnailpath string }
// Convert reads the ggs file and returns the thumbnail image
func (g GgsDecoder) Convert(r io.Reader) (interface{}, error) {
func (g GgsDecoder) Convert(r io.Reader) (any, error) {
var buf bytes.Buffer
_, err := io.Copy(&buf, r)
if err != nil {
@@ -79,7 +79,7 @@ func (g GgsDecoder) Convert(r io.Reader) (interface{}, error) {
type AudioDecoder struct{}
// Convert reads the audio file and extracts the thumbnail image from the id3 tag
func (i AudioDecoder) Convert(r io.Reader) (interface{}, error) {
func (i AudioDecoder) Convert(r io.Reader) (any, error) {
b, err := io.ReadAll(r)
if err != nil {
return nil, err
@@ -108,7 +108,7 @@ type TxtToImageConverter struct {
}
// Convert reads the text file and renders it into a thumbnail image
func (t TxtToImageConverter) Convert(r io.Reader) (interface{}, error) {
func (t TxtToImageConverter) Convert(r io.Reader) (any, error) {
img := image.NewRGBA(image.Rect(0, 0, 640, 480))
imgBounds := img.Bounds()
@@ -203,7 +203,7 @@ type GGPStruct struct {
type GgpDecoder struct{}
// Convert reads the ggp file and returns the first thumbnail image
func (j GgpDecoder) Convert(r io.Reader) (interface{}, error) {
func (j GgpDecoder) Convert(r io.Reader) (any, error) {
ggp := &GGPStruct{}
err := json.NewDecoder(r).Decode(ggp)
if err != nil {
@@ -298,7 +298,7 @@ func drawWord(canvas *font.Drawer, word string, minX, maxX, incY, maxY fixed.Int
}
// ForType returns the converter for the specified mimeType
func ForType(mimeType string, opts map[string]interface{}) FileConverter {
func ForType(mimeType string, opts map[string]any) FileConverter {
// We can ignore the error here because we parse it in IsMimeTypeSupported before and if it fails
// return the service call. So we should only get here when the mimeType parses fine.
mimeType, _, _ = mime.ParseMediaType(mimeType)
@@ -13,7 +13,7 @@ import (
type ImageDecoder struct{}
// Convert reads the image file and returns the thumbnail image
func (i ImageDecoder) Convert(r io.Reader) (interface{}, error) {
func (i ImageDecoder) Convert(r io.Reader) (any, error) {
img, err := imaging.Decode(r, imaging.AutoOrientation(true))
if err != nil {
return nil, errors.Wrap(err, `could not decode the image`)
@@ -165,7 +165,7 @@ func (g Thumbnail) handleCS3Source(ctx context.Context, req *thumbnailssvc.GetTh
}
defer r.Close()
ppOpts := map[string]interface{}{
ppOpts := map[string]any{
"fontFileMap": g.preprocessorOpts.TxtFontFileMap,
}
pp := preprocessor.ForType(sRes.GetInfo().GetMimeType(), ppOpts)
@@ -261,7 +261,7 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *thumbnailssvc.Ge
return "", merrors.InternalServerError(g.serviceID, "could not get image from source: %s", err.Error())
}
defer r.Close()
ppOpts := map[string]interface{}{
ppOpts := map[string]any{
"fontFileMap": g.preprocessorOpts.TxtFontFileMap,
}
pp := preprocessor.ForType(sRes.GetInfo().GetMimeType(), ppOpts)
@@ -124,7 +124,7 @@ func (s Thumbnails) TransferTokenValidator(next http.Handler) http.Handler {
}
logger := s.logger.SubloggerWithRequestID(r.Context())
token, err := jwt.ParseWithClaims(tokenString, &tjwt.ThumbnailClaims{}, func(token *jwt.Token) (interface{}, error) {
token, err := jwt.ParseWithClaims(tokenString, &tjwt.ThumbnailClaims{}, func(token *jwt.Token) (any, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
@@ -21,7 +21,7 @@ const (
// Encoder encodes the thumbnail to a specific format.
type Encoder interface {
// Encode encodes the image to a format.
Encode(w io.Writer, img interface{}) error
Encode(w io.Writer, img any) error
// Types returns the formats suffixes.
Types() []string
// MimeType returns the mimetype used by the encoder.
@@ -32,7 +32,7 @@ type Encoder interface {
type GifEncoder struct{}
// Encode encodes the image to a gif format
func (e GifEncoder) Encode(w io.Writer, img interface{}) error {
func (e GifEncoder) Encode(w io.Writer, img any) error {
g, ok := img.(*gif.GIF)
if !ok {
return errors.ErrInvalidType
@@ -15,7 +15,7 @@ import (
type PngEncoder struct{}
// Encode encodes to png format
func (e PngEncoder) Encode(w io.Writer, img interface{}) error {
func (e PngEncoder) Encode(w io.Writer, img any) error {
m, ok := img.(image.Image)
if !ok {
return errors.ErrInvalidType
@@ -37,7 +37,7 @@ func (e PngEncoder) MimeType() string {
type JpegEncoder struct{}
// Encode encodes to jpg
func (e JpegEncoder) Encode(w io.Writer, img interface{}) error {
func (e JpegEncoder) Encode(w io.Writer, img any) error {
m, ok := img.(image.Image)
if !ok {
return errors.ErrInvalidType
@@ -13,8 +13,8 @@ import (
// Generator generates a web friendly file version.
type Generator interface {
Generate(size image.Rectangle, img interface{}) (interface{}, error)
Dimensions(img interface{}) (image.Rectangle, error)
Generate(size image.Rectangle, img any) (any, error)
Dimensions(img any) (image.Rectangle, error)
ProcessorID() string
}
@@ -38,7 +38,7 @@ func (g GifGenerator) ProcessorID() string {
}
// Generate generates a alternative gif version.
func (g GifGenerator) Generate(size image.Rectangle, img interface{}) (interface{}, error) {
func (g GifGenerator) Generate(size image.Rectangle, img any) (any, error) {
// Code inspired by https://github.com/willnorris/gifresize/blob/db93a7e1dcb1c279f7eeb99cc6d90b9e2e23e871/gifresize.go
m, ok := img.(*gif.GIF)
@@ -70,7 +70,7 @@ func (g GifGenerator) Generate(size image.Rectangle, img interface{}) (interface
return m, nil
}
func (g GifGenerator) Dimensions(img interface{}) (image.Rectangle, error) {
func (g GifGenerator) Dimensions(img any) (image.Rectangle, error) {
m, ok := img.(*gif.GIF)
if !ok {
return image.Rectangle{}, errors.ErrInvalidType
@@ -28,7 +28,7 @@ func (g SimpleGenerator) ProcessorID() string {
}
// Generate generates a alternative image version.
func (g SimpleGenerator) Generate(size image.Rectangle, img interface{}) (interface{}, error) {
func (g SimpleGenerator) Generate(size image.Rectangle, img any) (any, error) {
m, ok := img.(image.Image)
if !ok {
return nil, errors.ErrInvalidType
@@ -37,7 +37,7 @@ func (g SimpleGenerator) Generate(size image.Rectangle, img interface{}) (interf
return g.processor.Process(m, size.Dx(), size.Dy(), imaging.Lanczos), nil
}
func (g SimpleGenerator) Dimensions(img interface{}) (image.Rectangle, error) {
func (g SimpleGenerator) Dimensions(img any) (image.Rectangle, error) {
m, ok := img.(image.Image)
if !ok {
return image.Rectangle{}, errors.ErrInvalidType
@@ -22,7 +22,7 @@ type Request struct {
type Manager interface {
// Generate creates a thumbnail and stores it.
// The function returns a key with which the actual file can be retrieved.
Generate(r Request, img interface{}) (string, error)
Generate(r Request, img any) (string, error)
// CheckThumbnail checks if a thumbnail with the requested attributes exists.
// The function will return a status if the file exists and the key to the file.
CheckThumbnail(r Request) (string, bool)
@@ -49,7 +49,7 @@ type SimpleManager struct {
}
// Generate creates a thumbnail and stores it
func (s SimpleManager) Generate(r Request, img interface{}) (string, error) {
func (s SimpleManager) Generate(r Request, img any) (string, error) {
var match image.Rectangle
inputDimensions, err := r.Generator.Dimensions(img)