Ejemplo n.º 1
0
func main() {
	defer db.Close()
	godotenv.Load()

	if os.Getenv("ENV") != "production" {
		factory.AutoMigrate()
		s3s.Test()
	} else {
		log.Println("Production")
	}

	log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), api_srv.New()))
}
Ejemplo n.º 2
0
func main() {
	defer db.Close()
	godotenv.Load()

	if os.Getenv("ENV") != "production" {
		factory.AutoMigrate()
		s3s.Test()
	} else {
		log.Println("Production")
	}

	// Route settings
	router := mux.NewRouter().StrictSlash(true)

	router.
		HandleFunc("/user", handlers.Register).
		Methods("POST")

	router.
		HandleFunc("/user/login", handlers.Login).
		Methods("GET")

	router.
		HandleFunc("/user/{userId}", handlers.GetUserById).
		Methods("GET")

	router.
		HandleFunc("/user/{userId}/photos", handlers.GetPhotosByUserId).
		Methods("GET")

	router.
		HandleFunc("/user/{userId}", handlers.UpdateUser).
		Methods("POST")

	router.
		HandleFunc("/photos", handlers.GetPhotos).
		Methods("GET")

	router.
		HandleFunc("/photo", handlers.PostPhoto).
		Methods("POST")

	router.
		HandleFunc("/photo/{photoId}/comment", handlers.CreateComment).
		Methods("POST")

	// Bind to a port and pass our router in
	http.Handle("/", &MyServer{router})

	log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}