package main import ( "log" "fmt" "net/http" "wyo.town/netzah/models" "wyo.town/netzah/handlers" "github.com/gorilla/mux" "gorm.io/driver/postgres" "gorm.io/gorm" ) func init() { dsn := "host=localhost user=_postgresql password=postGRES dbname=netzah port=5432 sslmode=disable TimeZone=US/Mountain client_encoding=UTF8" db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) if err != nil { panic("failed to connect database") } db.AutoMigrate(&models.User{}) db.AutoMigrate(&models.Blog{}) db.AutoMigrate(&models.Comment{}) } func main() { r := mux.NewRouter() r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte("Hello, World!")) }) // Blog endpoints r.HandleFunc("/blogs", handlers.CreateBlog).Methods("GET") r.HandleFunc("/blogs", handlers.StoreBlog).Methods("POST") r.HandleFunc("/blogs/{id}", handlers.GetBlog).Methods("GET") // r.HandleFunc("/blogs/{id}", handlers.UpdateBlog).Methods("PUT") // r.HandleFunc("/blogs/{id}", handlers.DeleteBlog).Methods("DELETE") // Also consider adding to handle a form submission for deletion fmt.Println("Starting server on :8090") if err := http.ListenAndServe(":8090", r); err != nil { log.Fatal(err) } }