| 123456789101112131415161718192021222324252627282930313233343536 |
- package handler
- import (
- "fmt"
- "path/filepath"
- "strings"
- "time"
- )
- // generateRequestId generates a unique request ID
- func generateRequestId() string {
- return fmt.Sprintf("%d-%d", time.Now().Unix(), time.Now().Nanosecond())
- }
- // getContentType returns the MIME type for a file based on its extension
- func getContentType(filename string) string {
- ext := strings.ToLower(filepath.Ext(filename))
- switch ext {
- case ".txt":
- return "text/plain"
- case ".html", ".htm":
- return "text/html"
- case ".json":
- return "application/json"
- case ".xml":
- return "application/xml"
- case ".jpg", ".jpeg":
- return "image/jpeg"
- case ".png":
- return "image/png"
- case ".pdf":
- return "application/pdf"
- default:
- return "application/octet-stream"
- }
- }
|