Example #1
0
func main() {
	flag.Parse()
	// to see what happens in the package, uncomment the following
	//restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))

	wsContainer := NewHandlerContainer()

	var application app.Application
	var err error

	// Check configuration file was given
	if configfile == "" {
		fmt.Fprintln(os.Stderr, "Please provide configuration file")
		os.Exit(1)
	}

	// Setup a new applications for common APIs

	appCollection := conf.LoadAppConfiguration(configfile)
	fmt.Println(appCollection)

	for _, element := range appCollection.Apps {
		fmt.Println("Initializing..", element)
		application, err = app.InitApp(element.Name, element.ConfigFilePath)

		err = application.SetRoutes(wsContainer)
		if err != nil {
			fmt.Println("Unable to create http server endpoints")
			os.Exit(1)
		}
	}

	// Install the Swagger Service which provides a nice Web UI on your REST API
	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
	// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.
	//fmt.Println("appCollection.Swagger.Status", appCollection.Swagger.Status)
	if appCollection.Swagger.Status {

		config := swagger.Config{}
		config.WebServices = wsContainer.RegisteredWebServices()
		config.WebServicesUrl = appCollection.Swagger.WebServicesUrl
		config.ApiPath = appCollection.Swagger.ApiPath
		config.SwaggerPath = appCollection.Swagger.SwaggerPath
		config.SwaggerFilePath = appCollection.Swagger.SwaggerFilePath

		swagger.RegisterSwaggerService(config, wsContainer)
	}
	log.Printf("start listening on localhost:8080")
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}
Example #2
0
func main() {
	flag.Parse()
	defer glog.Flush()

	var application app.Application
	var err error

	// Check configuration file was given
	if configfile == "" {
		fmt.Fprintln(os.Stderr, "Please provide configuration file")
		os.Exit(1)
	}

	appCollection := conf.LoadAppConfiguration(configfile)

	//Initialize the logging
	util.InitLogs(appCollection.Logging)

	application = skyring.NewApp(appCollection.Config.ConfigFilePath)

	if application == nil {
		glog.Errorf("Unable to start application")
		os.Exit(1)
	}
	// Create a router and do not allow any routes
	// unless defined.
	router := mux.NewRouter().StrictSlash(true)
	err = application.SetRoutes(router)
	if err != nil {
		glog.Errorf("Unable to create http server endpoints")
		os.Exit(1)
	}

	glog.Info("start listening on localhost:", strconv.Itoa(appCollection.Config.HttpPort))

	glog.Fatalf("Error", http.ListenAndServe(":"+strconv.Itoa(appCollection.Config.HttpPort), router))
}