mirror of
https://github.com/pyihe/go-pkg.git
synced 2025-09-27 12:22:14 +08:00
24 lines
323 B
Go
24 lines
323 B
Go
package serialize
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type Codec interface {
|
|
Name() string
|
|
Marshal(interface{}) ([]byte, error)
|
|
Unmarshal([]byte, interface{}) error
|
|
}
|
|
|
|
var (
|
|
m = make(map[string]Codec)
|
|
)
|
|
|
|
func Register(c Codec) {
|
|
m[strings.ToLower(c.Name())] = c
|
|
}
|
|
|
|
func Get(name string) Codec {
|
|
return m[strings.ToLower(name)]
|
|
}
|