(Feat): Initial Commit
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled

This commit is contained in:
2026-07-03 19:41:31 +05:30
commit 7e940c83a7
461 changed files with 45002 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package mime
import "github.com/gabriel-vasile/mimetype"
var _ MIME = (*mimetype.MIME)(nil)
// MIME interface enables to use either *mimetype.MIME or KnownMIME as mimetype.
type MIME interface {
String() string
Extension() string
Is(expectedMIME string) bool
}
// KnownMIME implements the MIME interface to be able to pass a *mimetype.MIME
// compatible value if the mimetype is already known so mimetype detection is not
// needed. It is therefore possible to skip mimetype detection if the mimetype is known
// or it is not possible to use a readSeeker but a mimetype is required.
type KnownMIME struct {
MimeType string
FileExtension string
}
func (m *KnownMIME) String() string {
return m.MimeType
}
func (m *KnownMIME) Extension() string {
return m.FileExtension
}
func (m *KnownMIME) Is(expectedMIME string) bool {
return expectedMIME == m.MimeType
}

View File

@@ -0,0 +1,30 @@
package mime_test
import (
"path/filepath"
"testing"
"allaboutapps.dev/aw/go-starter/internal/util"
"allaboutapps.dev/aw/go-starter/internal/util/mime"
"github.com/gabriel-vasile/mimetype"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestKnownMIME(t *testing.T) {
filePath := filepath.Join(util.GetProjectRootDir(), "test", "testdata", "example.jpg")
var detectedMIME mime.MIME
var err error
detectedMIME, err = mimetype.DetectFile(filePath)
require.NoError(t, err)
var knownMIME mime.MIME = &mime.KnownMIME{
MimeType: "image/jpeg",
FileExtension: ".jpg",
}
assert.Equal(t, detectedMIME.Extension(), knownMIME.Extension())
assert.Equal(t, detectedMIME.String(), knownMIME.String())
assert.True(t, knownMIME.Is(detectedMIME.String()))
}