From fde96673d0ebb5318a1e1efdd2110241b35192b8 Mon Sep 17 00:00:00 2001 From: "hui.wang" Date: Wed, 5 Jan 2022 12:50:27 +0800 Subject: [PATCH] refactor: secconf chain support --- secconf/codec.go | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/secconf/codec.go b/secconf/codec.go index 5a11261..64df8d8 100644 --- a/secconf/codec.go +++ b/secconf/codec.go @@ -1,7 +1,5 @@ package secconf -import "errors" - type Codec interface { Apply(data []byte) ([]byte, error) } @@ -22,29 +20,3 @@ func (c CodecFuncChain) Apply(data []byte) (out []byte, err error) { type CodecFunc func(data []byte) ([]byte, error) func (f CodecFunc) Apply(data []byte) ([]byte, error) { return f(data) } - -func newInvalidCodec(name string) Codec { - return CodecFunc(func(data []byte) ([]byte, error) { - return data, errors.New("invalid codec func for " + name) - }) -} - -var decoderRegister = make(map[string]Codec) -var encoderRegister = make(map[string]Codec) - -func RegisterDecoder(name string, cf Codec) { decoderRegister[name] = cf } -func RegisterEncoder(name string, cf Codec) { encoderRegister[name] = cf } - -func Decoder(name string) Codec { - if cf, ok := decoderRegister[name]; ok { - return cf - } - return newInvalidCodec(name) -} - -func Encoder(name string) Codec { - if cf, ok := encoderRegister[name]; ok { - return cf - } - return newInvalidCodec(name) -}