예제 #1
0
파일: main.go 프로젝트: iwat/sftpsync
func main() {
	flag.Parse()
	if flag.NArg() != 1 && flag.NArg() != 2 {
		flag.Usage()
		fmt.Fprintf(os.Stderr, "Usage: %s <remote> [<local>]\n", os.Args[0])
		os.Exit(2)
	}

	handler := ext.FatalHandler(log15.CallerFileHandler(log15.StderrHandler))
	if flagVeryVerbose {
		handler = log15.LvlFilterHandler(log15.LvlDebug, handler)
	} else if flagVerbose {
		handler = log15.LvlFilterHandler(log15.LvlInfo, handler)
	}
	log15.Root().SetHandler(handler)

	local := "."
	if flag.NArg() == 2 {
		local = flag.Arg(1)
	}

	m := sftpsync.SyncManager{
		Local:     local,
		Remote:    flag.Arg(0),
		SkipFiles: skipFiles,
		SkipDirs:  skipDirs,
		Append:    flagAppend,
		DryRun:    flagDryRun,
	}
	err := m.Run()
	if err != nil {
		log.Crit("run error", "err", err)
		return
	}
}
예제 #2
0
파일: before.go 프로젝트: go-xiaohei/pugo
// Before set before handler when start run cli.App
func Before(ctx *cli.Context) error {
	lv := log15.LvlInfo
	if ctx.Bool("debug") {
		lv = log15.LvlDebug
	}
	log15.Root().SetHandler(log15.LvlFilterHandler(lv, ext.FatalHandler(log15.StreamHandler(os.Stderr, helper.LogfmtFormat()))))
	return nil
}
예제 #3
0
파일: pugo.go 프로젝트: cnhans/pugo-static
func init() {
	app.Name = "pugo"
	app.Usage = "a beautiful site generator"
	app.Author = "fuxiaohei"
	app.Email = "*****@*****.**"
	app.Version = VERSION + "(" + VER_DATE + ")"
	opt.SrcDir = SRC_DIR
	opt.TplDir = TPL_DIR
	opt.MediaDir = path.Join(SRC_DIR, MEDIA_DIR)
	opt.Version = VERSION
	opt.VerDate = VER_DATE

	log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlInfo, ext.FatalHandler(log15.StderrHandler)))
}
예제 #4
0
파일: pugo.go 프로젝트: jazzsun/pugo-static
func init() {
	app.Name = "pugo"
	app.Usage = "a beautiful site generator"
	app.Author = "https://github.com/fuxiaohei"
	app.Email = "*****@*****.**"
	app.Version = VERSION + "(" + VER_DATE + ")"
	opt.SrcDir = SRC_DIR
	opt.TplDir = TPL_DIR
	opt.UploadDir = UPLOAD_DIR
	opt.Version = VERSION
	opt.VerDate = VER_DATE

	log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlInfo, ext.FatalHandler(log15.StderrHandler)))
}
예제 #5
0
파일: app.go 프로젝트: go-xiaohei/pucore
func init() {
	// set log settings
	log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlDebug, ext.FatalHandler(log15.StderrHandler)))

	// close tidb debug
	log.SetLevelByString("error")
	tidb.Debug = false

	// init global vars
	var (
		config   *Config = NewConfig()
		database *Db     = NewDB(config.Db.Driver, config.Db.DSN)
		server   *Web    = NewWeb(config.Http.Host, config.Http.Port, config.Http.Protocol)
	)
	Injector = pucore.NewInjector(config, database, server)
	Behavior = pucore.NewBehaviors()
	Modular = pucore.NewModular(Injector, Behavior)
}
예제 #6
0
파일: server.go 프로젝트: hxdyxd/pugo
func Server(ctx *cli.Context) {
	// change logger level
	if ctx.Bool("debug") {
		log15.Root().SetHandler(ext.FatalHandler(log15.StderrHandler))
	}

	opt := service.BootstrapInitOption{true, false, false}
	if err := service.Call(service.Bootstrap.Init, opt); err != nil {
		log15.Crit("Server.start.fail", "error", err)
	}
	// if not installed,try to install
	if core.Cfg.Install == "0" {
		Install(ctx)
	}

	// re-init all things
	opt = service.BootstrapInitOption{true, true, true}
	if err := service.Call(service.Bootstrap.Init, opt); err != nil {
		log15.Crit("Server.start.fail", "error", err)
	}
	// bootstrap service, preload data
	opt2 := service.BootstrapOption{true, true, true}
	if err := service.Call(service.Bootstrap.Bootstrap, opt2); err != nil {
		log15.Crit("Server.start.fail", "error", err)
	}
	log15.Info("Server.prepare")

	// set middleware and routers
	core.Server.ErrHandler = new(middle.RecoveryHandler)
	core.Server.Use(
		middle.Recover(),
		middle.Logger(),
		middle.Themer(),
		middle.Responser(),
		middle.Authorizor())

	adminGroup := tango.NewGroup()
	adminGroup.Any("/login", new(admin.LoginController))
	adminGroup.Route([]string{"GET:Logout"}, "/logout", new(admin.LoginController))

	adminGroup.Any("/write/article", new(admin.ArticleWriteController))
	adminGroup.Get("/manage/article", new(admin.ArticleManageController))
	adminGroup.Get("/public/article", new(admin.ArticlePublicController))
	adminGroup.Get("/delete/article", new(admin.ArticleDeleteController))

	adminGroup.Any("/write/page", new(admin.PageWriteController))
	adminGroup.Get("/manage/page", new(admin.PageManageController))
	adminGroup.Get("/delete/page", new(admin.PageDeleteController))

	adminGroup.Get("/manage/comment", new(admin.CommentController))
	adminGroup.Route([]string{"GET:Approve"}, "/approve/comment", new(admin.CommentController))
	adminGroup.Route([]string{"GET:Delete"}, "/delete/comment", new(admin.CommentController))
	adminGroup.Route([]string{"POST:Reply"}, "/reply/comment", new(admin.CommentController))

	adminGroup.Any("/profile", new(admin.ProfileController))
	adminGroup.Route([]string{"POST:Password"}, "/password", new(admin.ProfileController))

	adminGroup.Any("/option/general", new(admin.SettingGeneralController))
	adminGroup.Route([]string{"POST:PostMedia"}, "/option/media", new(admin.SettingGeneralController))
	adminGroup.Get("/option/theme", new(admin.SettingThemeController))
	adminGroup.Any("/option/content", new(admin.SettingContentController))
	adminGroup.Any("/option/comment", new(admin.SettingCommentController))
	adminGroup.Any("/option/menu", new(admin.SettingMenuController))

	adminGroup.Get("/manage/media", new(admin.MediaController))
	adminGroup.Route([]string{"POST:Upload"}, "/upload/media", new(admin.MediaController))
	adminGroup.Get("/delete/media", new(admin.MediaDeleteController))

	adminGroup.Get("/advance/backup", new(admin.AdvBackupController))
	adminGroup.Route([]string{"POST:Backup"}, "/advance/backup", new(admin.AdvBackupController))
	adminGroup.Route([]string{"GET:Delete"}, "/delete/backup", new(admin.AdvBackupController))

	adminGroup.Get("/advance/import", new(admin.AdvImportController))
	adminGroup.Post("/import/:type", new(admin.AdvImportController))

	adminGroup.Get("/", new(admin.IndexController))
	core.Server.Group("/admin", adminGroup)

	core.Server.Get("/article/page/:page", new(public.IndexController))
	core.Server.Get("/article/:id/:link.html", new(public.ArticleController))
	core.Server.Get("/page/:id/:link.html", new(public.PageController))
	core.Server.Post("/comment/:type/:id", new(public.CommentController))
	core.Server.Get("/feed.xml", new(public.RssController))
	core.Server.Get("/archive", new(public.ArchiveController))
	core.Server.Get("/:link.html", new(public.PageController))
	core.Server.Get("/", new(public.IndexController))

	// start server
	log15.Info("Server.start." + core.Cfg.Http.Host + ":" + core.Cfg.Http.Port)
	core.Server.Run(core.Cfg.Http.Host + ":" + core.Cfg.Http.Port)
}
예제 #7
0
파일: flag.go 프로젝트: cnhans/pugo-static
func setDebugMode(ctx *cli.Context) error {
	if ctx.Bool("debug") {
		log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlDebug, ext.FatalHandler(log15.StderrHandler)))
	}
	return nil
}