Esempio n. 1
0
func main() {
	// Get current binary path
	binPath, _ := filepath.Abs(filepath.Dir(os.Args[0]))

	// Viper settings
	viper.SupportedExts = []string{"json"}

	// Initialize Config
	config := viper.New()
	config.SetConfigName("config")
	config.AddConfigPath("./")
	config.AddConfigPath(binPath)
	config.AddConfigPath("$HOME/.helios")

	// Read config file
	err := config.ReadInConfig()
	if err != nil {
		log.Fatalln("No valid config.json file found.", err)
		os.Exit(1)
	}

	// Set Config Defaults
	config.SetDefault("port", "8989")

	// Initialize Helios
	h := helios.New()
	h.SetConfig(config)

	// Register http handler for sending the client config
	h.HTTPEngine.GET("/config", func(c *gin.Context) {
		c.JSON(200, config.GetStringMap("client"))
	})

	// Register Services
	h.Use("static", static.Service())

	if config.GetBool("enableCors") {
		h.Use("cors", cors.Service())
	}

	if config.IsSet("forecastio.apiKey") {
		h.Use("weather", weather.Service())
	}

	if config.IsSet("github.apiKey") && config.IsSet("github.apiSecret") {
		h.Use("github", github.Service())
	}

	if config.IsSet("slack.apiKey") {
		h.Use("slack", slack.Service())
	}

	// Start helios
	h.Run(config.GetString("port"))
}
Esempio n. 2
0
func main() {
	// Initialize command line args
	flag.StringVar(&port, "port", "8989", "Port to run the server on")

	// Use env variables if they are defined
	if len(os.Getenv("PORT")) > 0 {
		port = os.Getenv("PORT")
	}

	flag.Parse()

	h := helios.New()

	h.Use(cors.Service())
	h.Use(static.Service())
	h.Use(weather.Service())
	h.Use(github.Service())
	h.Use(slack.Service())

	// Initialize helios
	h.Run(port)
}