コード例 #1
0
ファイル: serve.go プロジェクト: erasche/gologme
func ServeFromGolog(g *gologme.Golog, url string) {
	golog = g

	router := mux.NewRouter()
	RegisterRoutes(router)

	// Listen and serve
	fmt.Printf("Listening on %s ...\n", url)
	log.Fatal(http.ListenAndServe(url,
		handlers.CORS(
			handlers.AllowedOrigins([]string{"http://localhost:3000"}),
			handlers.AllowedMethods([]string{"POST", "GET", "HEAD", "OPTIONS"}),
			handlers.AllowedHeaders([]string{"Authorization", "Content-Type"}),
			handlers.AllowCredentials(),
		)(router)))
}
コード例 #2
0
func main() {

	flag.Parse()

	config, err := infrastructure.GetConfiguration(*confFilePath)
	if err != nil {
		fmt.Println(err.Error())
		panic("Cannot parse configuration")
	}

	doInteractor := usecases.DOInteractor{}

	handler := interfaces.WebServiceHandler{
		Interactor:  doInteractor,
		ID:          config.ClientID,
		Secret:      config.ClientSecret,
		Scopes:      config.Scopes,
		RedirectURI: config.RedirectURI,
		APIHost:     config.APIHost,
	}

	headers := handlers.AllowedHeaders([]string{"Accept", "Content-Type", "Authorization"})
	origins := handlers.AllowedOrigins([]string{"http://localhost", "http://provision.tinkerware.io", "https://provision.tinkerware.io"})

	r := mux.NewRouter()

	subrouter := r.PathPrefix("/api/v1/cloud").Subrouter()

	subrouter.HandleFunc("/digital_ocean/", handler.Login)
	subrouter.HandleFunc("/digital_ocean/oauth", handler.DOCallback).Methods("POST")
	subrouter.HandleFunc("/digital_ocean/keys", handler.ShowKeys).Methods("GET")
	subrouter.HandleFunc("/digital_ocean/keys", handler.CreateKey).Methods("POST")
	subrouter.HandleFunc("/digital_ocean/instances", handler.CreateDroplet).Methods("POST")
	subrouter.HandleFunc("/digital_ocean/instances", handler.ListDroplets).Methods("GET")
	subrouter.HandleFunc("/digital_ocean/instance/{instanceID}", handler.GetInstance).Methods("GET")

	n := negroni.Classic()
	n.UseHandler(handlers.CORS(headers, origins)(r))

	port := bytes.Buffer{}

	port.WriteString(":")
	port.WriteString(config.Port)

	n.Run(port.String())

}