crusader db25683a3a ing
2017-08-30 19:26:32 +09:00

68 lines
1.8 KiB
Go

package file
import (
"context"
"log"
"time"
"go.uber.org/zap"
"git.loafle.net/commons_go/config"
"git.loafle.net/commons_go/logging"
"git.loafle.net/overflow/overflow_gateway_web/handler"
gws "git.loafle.net/overflow/overflow_gateway_websocket"
"git.loafle.net/overflow/overflow_gateway_websocket/protocol/jsonrpc"
)
type FileHandler interface {
handler.Handler
}
type fileHandler struct {
ctx context.Context
logger *zap.Logger
co *gws.SocketOptions
ho *jsonrpc.Options
handler gws.MessageHandler
}
func New(ctx context.Context) FileHandler {
h := &fileHandler{
ctx: ctx,
logger: logging.WithContext(ctx),
}
h.ho = &jsonrpc.Options{
OnRequest: h.onRequest,
OnNotify: h.onNotify,
}
h.handler = jsonrpc.NewHandler(ctx, h.ho)
h.co = &gws.SocketOptions{
Handler: h.handler,
MaxMessageSize: config.GetInt64("handlers.file.socket.MaxMessageSize"),
WriteTimeout: time.Duration(config.GetInt("handlers.file.socket.WriteTimeout")) * time.Second,
ReadTimeout: time.Duration(config.GetInt("handlers.file.socket.ReadTimeout")) * time.Second,
PongTimeout: time.Duration(config.GetInt("handlers.file.socket.PongTimeout")) * time.Second,
PingTimeout: time.Duration(config.GetInt("handlers.file.socket.PingTimeout")) * time.Second,
PingPeriod: time.Duration(config.GetInt("handlers.file.socket.PingPeriod")) * time.Second,
BinaryMessage: config.GetBool("handlers.file.socket.BinaryMessage"),
}
return h
}
func (h *fileHandler) GetSocketOption() *gws.SocketOptions {
return h.co
}
func (h *fileHandler) onRequest(soc gws.Socket, method string, params []string) (interface{}, error) {
log.Printf("path: %s, m: %s, params: %v", soc.Path(), method, params)
return nil, nil
}
func (h *fileHandler) onNotify(soc gws.Socket, method string, params []string) error {
return nil
}