23 lines
408 B
Go
23 lines
408 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"errors"
|
|
|
|
|
|
//"github.com/charmbracelet/log"
|
|
"github.com/h2non/filetype"
|
|
)
|
|
|
|
|
|
func getExtension(filePath string) (extension string, err error) {
|
|
buf, _ := os.ReadFile(filePath)
|
|
|
|
kind, _ := filetype.Match(buf)
|
|
if kind == filetype.Unknown {
|
|
return "", errors.New(fmt.Sprintf("Unknown file type."))
|
|
}
|
|
|
|
return kind.Extension, nil
|
|
}
|