コード例 #1
0
ファイル: main.go プロジェクト: gitter-badger/nedomi
//!TODO: implement some "unit" tests for this :)
func run() int {
	if cpuprofile != "" {
		f, err := os.Create(cpuprofile)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Could not create cpuprofile file: %s\n", err)
			return 1
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	if showVersion {
		fmt.Printf("nedomi version %s\n", Version)
		return 0
	}

	cfg, err := config.Get()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error parsing config: %s\n", err)
		return 2
	}

	if testConfig {
		return 0
	}

	//!TODO: simplify and encapsulate application startup:
	// Move/encapsulate SetupEnv/CleanupEnv, New, Start, Wait, etc.
	// Leave only something like return App.Run(cfg)
	// This will possibly simplify configuration reloading and higher contexts as well
	defer app.CleanupEnv(cfg)
	if err := app.SetupEnv(cfg); err != nil {
		fmt.Fprintf(os.Stderr, "Could setup nedomi environment: %s\n", err)
		return 3
	}

	appInstance, err := app.New(cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could initialize nedomi: %s\n", err)
		return 4
	}

	if err := appInstance.Start(); err != nil {
		fmt.Fprintf(os.Stderr, "Could start nedomi: %s\n", err)
		return 5
	}

	if err := appInstance.Wait(); err != nil {
		fmt.Fprintf(os.Stderr, "Error stopping the app : %s\n", err)
		return 6
	}

	return 0
}
コード例 #2
0
ファイル: main.go プロジェクト: na--/nedomi
//!TODO: implement some "unit" tests for this :)
func run() int {
	if cpuprofile != "" {
		f, err := os.Create(cpuprofile)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Could not create cpuprofile file: %s\n", err)
			return 1
		}
		if err := pprof.StartCPUProfile(f); err != nil {
			panic(err)
		}
		defer pprof.StopCPUProfile()
	}
	// error probably means this is not build with make
	n, _ := strconv.ParseInt(BuildTime, 10, 64)
	buildTime := time.Unix(n, 0)
	var appVersion = types.AppVersion{
		Version:   Version,
		GitHash:   GitHash,
		GitTag:    GitTag,
		BuildTime: buildTime,
		Dirty:     Dirty == "true",
	}

	if showVersion {
		fmt.Printf("nedomi version %s\n", appVersion)
		return 0
	}

	appInstance, err := app.New(appVersion, config.Get)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't initialize nedomi: %s\n", err)
		return 4
	}

	if err := upTheLimits(); err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't up the limits: %s\n", err)
		return 6
	}

	if testConfig {
		return 0 // still doesn't work :)
	}

	if err := appInstance.Run(); err != nil {
		fmt.Fprintf(os.Stderr, "Nedomi exit with error: %s\n", err)
		return 5
	}

	return 0
}