-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Multidialogo/develop
Develop
- Loading branch information
Showing
9 changed files
with
270 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
APP_DATA_PATH="/var/lib/mailculator | ||
DRAFT_OUTPUT_PATH="/email_queues/draft" | ||
APP_DATA_PATH="/var/lib/mailculators" | ||
INPUT_PATH="/input" | ||
DRAFT_OUTPUT_PATH="/email_queues/draft" | ||
OUTBOX_PATH="/maildir/outbox" | ||
|
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,3 +1,4 @@ | ||
APP_DATA_PATH="/tmp" | ||
DRAFT_OUTPUT_PATH="/email_queues/draft" | ||
INPUT_PATH="/input" | ||
DRAFT_OUTPUT_PATH="/email_queues/draft" | ||
OUTBOX_PATH="/maildir/outbox" |
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,29 +1,30 @@ | ||
# Stage 1: Builder | ||
FROM golang:1.23 AS builder | ||
RUN mkdir -p /usr/local/go/src/mailculator | ||
WORKDIR /usr/local/go/src/mailculator | ||
FROM golang:1.23 AS mailculators-builder | ||
RUN mkdir -p /usr/local/go/src/mailculator-server | ||
WORKDIR /usr/local/go/src/mailculator-server | ||
COPY . . | ||
COPY .env.test /usr/local/go/src/mailculator/.env | ||
COPY .env.test /usr/local/go/src/mailculator-server/.env | ||
RUN go mod tidy | ||
RUN go mod download | ||
RUN go test ./... | ||
RUN go build -o /usr/local/bin/mailculator . | ||
RUN chmod +x /usr/local/bin/mailculator | ||
RUN go build -o /usr/local/bin/mailculator-server/httpd . | ||
RUN chmod +x /usr/local/bin/mailculator-server/httpd | ||
|
||
# Stage 2: Development | ||
FROM golang:1.23 AS dev | ||
WORKDIR /usr/local/go/src/mailculator | ||
COPY data /var/lib/mailculator | ||
COPY --from=builder /usr/local/bin/mailculator /usr/local/bin/mailculator/server | ||
COPY .env.dev /usr/local/bin/mailculator/.env | ||
FROM golang:1.23 AS mailculators-dev | ||
WORKDIR /usr/local/go/src/mailculator-server | ||
COPY . . | ||
COPY .env.dev /usr/local/go/src/mailculator-server/.env | ||
RUN go mod tidy | ||
RUN go mod download | ||
RUN go install github.com/air-verse/air@latest | ||
EXPOSE 8080 | ||
CMD ["air"] | ||
|
||
# Stage 3: Production | ||
FROM gcr.io/distroless/base-debian12 AS prod | ||
WORKDIR /usr/local/go/src/mailculator | ||
COPY --from=builder /usr/local/bin/mailculator /usr/local/bin/mailculator/server | ||
COPY .env.prod /usr/local/bin/mailculator/.env | ||
FROM gcr.io/distroless/base-debian12 AS mailculators-prod | ||
WORKDIR /usr/local/bin/mailculator/server | ||
COPY --from=mailculators-builder /usr/local/bin/mailculator-server/httpd /usr/local/bin/mailculator-server/httpd | ||
COPY .env.prod /usr/local/bin/mailculator-server/.env | ||
EXPOSE 8080 | ||
CMD ["mailcalculator"] | ||
CMD ["httpd"] |
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
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,90 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"github.com/h2non/filetype" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"io" | ||
) | ||
|
||
// DetectFileMime detects the MIME type of a file using file signature and extension | ||
func DetectFileMime(path string) (string, error) { | ||
// Open the file | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return "", fmt.Errorf("Error opening file: %w", err) | ||
} | ||
defer file.Close() | ||
|
||
// Read the first few bytes to detect content type using filetype | ||
buffer := make([]byte, 261) // Read first 261 bytes, larger buffer for better detection | ||
_, err = file.Read(buffer) | ||
if err != nil { | ||
return "", fmt.Errorf("Error reading file: %w", err) | ||
} | ||
|
||
// Use the filetype package to detect the MIME type based on file signature | ||
kind, _ := filetype.Match(buffer) | ||
if kind == filetype.Unknown || kind.MIME.Value == "application/octet-stream" { | ||
// Fallback to extension-based detection for known types | ||
return DetectFileMimeFromKnownExtension(filepath.Ext(path)), nil | ||
} | ||
|
||
// If MIME type is found via file signature, return it | ||
return kind.MIME.Value, nil | ||
} | ||
|
||
func DetectFileMimeFromKnownExtension(extension string) string { | ||
switch strings.ToLower(extension) { | ||
case ".jpg", ".jpeg": | ||
return "image/jpeg" | ||
case ".png": | ||
return "image/png" | ||
case ".gif": | ||
return "image/gif" | ||
case ".txt": | ||
return "text/plain" | ||
default: | ||
return "application/octet-stream" | ||
} | ||
} | ||
|
||
// CopyFile copies a file from src to dest, ensuring the destination path exists | ||
func CopyFile(src, dest string) error { | ||
// Ensure the destination directory exists | ||
destDir := filepath.Dir(dest) | ||
if err := os.MkdirAll(destDir, os.ModePerm); err != nil { | ||
return fmt.Errorf("failed to create destination directory: %w", err) | ||
} | ||
|
||
// Open the source file | ||
srcFile, err := os.Open(src) | ||
if err != nil { | ||
return fmt.Errorf("failed to open source file: %w", err) | ||
} | ||
defer srcFile.Close() | ||
|
||
// Create the destination file | ||
destFile, err := os.Create(dest) | ||
if err != nil { | ||
return fmt.Errorf("failed to create destination file: %w", err) | ||
} | ||
defer destFile.Close() | ||
|
||
// Copy the contents of the source file to the destination file | ||
if _, err := io.Copy(destFile, srcFile); err != nil { | ||
return fmt.Errorf("failed to copy file contents: %w", err) | ||
} | ||
|
||
// Optionally, set the destination file permissions to match the source file | ||
srcInfo, err := os.Stat(src) | ||
if err == nil { | ||
if err := os.Chmod(dest, srcInfo.Mode()); err != nil { | ||
return fmt.Errorf("failed to set file permissions: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.