2020-12-26 07:47:10 +00:00
|
|
|
package common
|
|
|
|
|
2021-11-11 15:27:07 +00:00
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-12-26 07:47:10 +00:00
|
|
|
type NewDecoderFunc func([]byte) Decoder
|
|
|
|
|
|
|
|
var decoderRegistry = make(map[string][]NewDecoderFunc)
|
|
|
|
|
|
|
|
func RegisterDecoder(ext string, dispatchFunc NewDecoderFunc) {
|
|
|
|
decoderRegistry[ext] = append(decoderRegistry[ext], dispatchFunc)
|
|
|
|
}
|
2021-11-11 15:27:07 +00:00
|
|
|
func GetDecoder(filename string) []NewDecoderFunc {
|
|
|
|
ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), "."))
|
2020-12-26 07:47:10 +00:00
|
|
|
return decoderRegistry[ext]
|
|
|
|
}
|