fix #18: support upper case extension

This commit is contained in:
Emmm Monster
2021-11-11 23:27:07 +08:00
parent 0a13671df2
commit 6fd5bd5863
3 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,10 @@
package common
import (
"path/filepath"
"strings"
)
type NewDecoderFunc func([]byte) Decoder
var decoderRegistry = make(map[string][]NewDecoderFunc)
@ -7,6 +12,7 @@ var decoderRegistry = make(map[string][]NewDecoderFunc)
func RegisterDecoder(ext string, dispatchFunc NewDecoderFunc) {
decoderRegistry[ext] = append(decoderRegistry[ext], dispatchFunc)
}
func GetDecoder(ext string) []NewDecoderFunc {
func GetDecoder(filename string) []NewDecoderFunc {
ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), "."))
return decoderRegistry[ext]
}