Exemplo n.º 1
0
func (s *Server) Start() error {

	router := NewRouter()
	if s.config.UiDir != "" {
		if assets, err := filepath.Abs(s.config.UiDir); err == nil {
			router.NotFound(http.FileServer(http.Dir(assets)))
		}
	}

	router.GET("/queue", CompatibleWarp(s.queueHandler))
	router.POST("/queue", CompatibleWarp(s.queueHandler))
	router.GET("/group", CompatibleWarp(s.groupHandler))
	router.POST("/group", CompatibleWarp(s.groupHandler))
	router.GET("/monitor", CompatibleWarp(s.monitorHandler))
	router.GET("/msg", CompatibleWarp(s.msgHandler))
	router.POST("/msg", CompatibleWarp(s.msgHandler))

	var err error
	s.listener, err = utils.Listen("tcp", fmt.Sprintf(":%s", s.config.HttpPort))
	if err != nil {
		return errors.Trace(err)
	}

	server := &http.Server{Handler: router}
	server.SetKeepAlivesEnabled(true)

	s.mc = mc.NewMcServer(s.queue, s.config)
	err = s.mc.Start()
	if err != nil {
		return errors.Trace(err)
	}

	go server.Serve(s.listener)
	return nil
}
Exemplo n.º 2
0
func (ms *McServer) Start() error {

	var err error
	ms.listener, err = utils.Listen("tcp", fmt.Sprintf(":%s", ms.port))
	if err != nil {
		return errors.Trace(err)
	}
	log.Debugf("memcached protocol server start on %s port.", ms.port)
	go ms.mainLoop()
	return nil
}