overflow_discovery/server/server_handlers.go
crusader c4e482999b ing
2017-11-01 15:35:03 +09:00

77 lines
1.4 KiB
Go

package server
import (
"io"
"net"
"os"
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/rpc/protocol/json"
"git.loafle.net/commons_go/rpc/server"
)
func NewServerHandler(addr string, registry rpc.Registry) *ServerHandlers {
sh := &ServerHandlers{}
sh.RPCRegistry = registry
sh.addr = addr
sh.RegisterCodec(json.NewServerCodec(), "json")
return sh
}
type ServerHandlers struct {
server.ServerHandlers
addr string
}
func (sh *ServerHandlers) OnStart() {
// no op
}
func (sh *ServerHandlers) OnStop() {
// no op
}
func (sh *ServerHandlers) Listen() (net.Listener, error) {
os.Remove(sh.addr)
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: sh.addr, Net: "unix"})
if nil == err {
os.Chmod(sh.addr, 0777)
}
return l, err
}
func (sh *ServerHandlers) OnAccept(conn net.Conn) (net.Conn, error) {
return conn, nil
}
func (sh *ServerHandlers) GetContentType(r io.Reader) string {
return "json"
}
func (sh *ServerHandlers) OnPreRead(r io.Reader) {
// no op
}
func (sh *ServerHandlers) OnPostRead(r io.Reader) {
// no op
}
func (sh *ServerHandlers) OnPreWriteResult(w io.Writer, result interface{}) {
// no op
}
func (sh *ServerHandlers) OnPostWriteResult(w io.Writer, result interface{}) {
// no op
}
func (sh *ServerHandlers) OnPreWriteError(w io.Writer, err error) {
// no op
}
func (sh *ServerHandlers) OnPostWriteError(w io.Writer, err error) {
// no op
}