diff --git a/server_handler.go b/server_handler.go index c228a73..6308760 100644 --- a/server_handler.go +++ b/server_handler.go @@ -7,8 +7,8 @@ import ( ) type ServerHandler interface { - RegisterCodec(codec protocol.ServerCodec, contentType string) - GetCodec(contentType string) (protocol.ServerCodec, error) + Init() error + OnStart() OnPreRead(r io.Reader) OnPostRead(r io.Reader) @@ -18,4 +18,11 @@ type ServerHandler interface { OnPreWriteError(w io.Writer, err error) OnPostWriteError(w io.Writer, err error) + + OnStop() + + Validate() + + RegisterCodec(codec protocol.ServerCodec, contentType string) + GetCodec(contentType string) (protocol.ServerCodec, error) } diff --git a/server_handlers.go b/server_handlers.go index 4a6c506..30c6e72 100644 --- a/server_handlers.go +++ b/server_handlers.go @@ -8,20 +8,23 @@ import ( "git.loafle.net/commons_go/rpc/protocol" ) +func NewServerHandler() ServerHandler { + sh := &ServerHandlers{} + + return sh +} + type ServerHandlers struct { codecs map[string]protocol.ServerCodec } -// RegisterCodec adds a new codec to the server. -// -// Codecs are defined to process a given serialization scheme, e.g., JSON or -// XML. A codec is chosen based on the "Content-Type" header from the request, -// excluding the charset definition. -func (sh *ServerHandlers) RegisterCodec(codec protocol.ServerCodec, contentType string) { - if nil == sh.codecs { - sh.codecs = make(map[string]protocol.ServerCodec) - } - sh.codecs[strings.ToLower(contentType)] = codec +func (sh *ServerHandlers) Init() error { + + return nil +} + +func (sh *ServerHandlers) OnStart() { + // no op } func (sh *ServerHandlers) OnPreRead(r io.Reader) { @@ -48,9 +51,25 @@ func (sh *ServerHandlers) OnPostWriteError(w io.Writer, err error) { // no op } +func (sh *ServerHandlers) OnStop() { + // no op +} + func (sh *ServerHandlers) Validate() { } +// RegisterCodec adds a new codec to the server. +// +// Codecs are defined to process a given serialization scheme, e.g., JSON or +// XML. A codec is chosen based on the "Content-Type" header from the request, +// excluding the charset definition. +func (sh *ServerHandlers) RegisterCodec(codec protocol.ServerCodec, contentType string) { + if nil == sh.codecs { + sh.codecs = make(map[string]protocol.ServerCodec) + } + sh.codecs[strings.ToLower(contentType)] = codec +} + func (sh *ServerHandlers) GetCodec(contentType string) (protocol.ServerCodec, error) { var codec protocol.ServerCodec if contentType == "" && len(sh.codecs) == 1 {