feat: modularize the code.

This commit is contained in:
CronyAkatsuki 2025-11-07 18:16:45 +01:00
parent 6f4757a1e9
commit a59c892087
7 changed files with 293 additions and 243 deletions

34
misc.go Normal file
View file

@ -0,0 +1,34 @@
package main
import (
"errors"
"log"
"net/http"
"os"
)
// Miscelaneous functions
// Create directory if it doesn't exist
func CreateDirIfNotExisting(d string) {
if _, err := os.Stat(d); errors.Is(err, os.ErrNotExist) {
err := os.Mkdir(d, os.ModePerm)
if err != nil {
log.Println(err)
}
}
}
// Get the file content type
func GetFileContentType(ouput *os.File) (string, error) {
buf := make([]byte, 512)
_, err := ouput.Read(buf)
if err != nil {
return "", err
}
contentType := http.DetectContentType(buf)
return contentType, nil
}