Exemple #1
0
// 运行路由,执行监听程序。
func (cfg *Config) run() error {
	if err := cfg.init(); err != nil {
		return err
	}

	// 在其它之前调用
	if err := cfg.buildStaticModule(); err != nil {
		return err
	}

	h := cfg.buildHandler(defaultServeMux)

	if cfg.HTTPS {
		switch cfg.HTTPState {
		case HTTPStateListen:
			logs.Infof("开始监听%v端口", httpPort)
			go getServer(cfg, httpPort, h).ListenAndServe()
		case HTTPStateRedirect:
			logs.Infof("开始监听%v端口", httpPort)
			go cfg.httpRedirectListenAndServe()
		}

		logs.Infof("开始监听%v端口", cfg.Port)
		return getServer(cfg, cfg.Port, h).ListenAndServeTLS(cfg.CertFile, cfg.KeyFile)
	}

	logs.Infof("开始监听%v端口", cfg.Port)
	return getServer(cfg, cfg.Port, h).ListenAndServe()
}
Exemple #2
0
func writeLastLogs(r *http.Request) error {
	ls := make([]*login, 0, maxLoginLogs)
	if err := json.Unmarshal([]byte(opt.Last), &ls); err != nil {
		return err
	}

	l := &login{
		IP:    r.RemoteAddr,
		Agent: r.UserAgent(),
		Time:  time.Now().Format("2006-01-02 15:04:05"),
	}

	if len(ls) >= maxLoginLogs { // 去掉最后一条记录
		ls = ls[:maxLoginLogs-1]
	}
	//lss := make([]*login, 0, maxLoginLogs)
	//lss = append(lss, l)
	lss := []*login{l}
	lss = append(lss, ls...)
	bs, err := json.Marshal(lss)
	if err != nil {
		return err
	}

	if err := app.SetOption("last", string(bs), true); err != nil {
		return err
	}
	logs.Infof("登录信息:IP:%v;Agent:%v;Time:%v\n", l.IP, l.Agent, l.Time)

	return nil
}
Exemple #3
0
// @api put /admin/api/modules/{name}/stop 停止一个模块
// @apiParam name string 模块名称
// @apiGroup admin
//
// @apiRequest json
// @apiHeader Authorization xxx
//
// @apiSuccess 204 OK
func adminPutModuleStop(w http.ResponseWriter, r *http.Request) {
	m := getModule(w, r)
	if m == nil {
		return
	}

	m.Stop()
	logs.Infof("options:停止了[%v]模块的运行\n", m.Name)
	util.RenderJSON(w, http.StatusNoContent, nil, nil)
}