Skip to content

Commit

Permalink
modified: go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
zoelabbb committed Nov 13, 2023
1 parent 72de171 commit d92caac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go-crud-postgres

go 1.20
go 1.20.0

require (
github.com/gorilla/mux v1.8.1
Expand Down
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (
"go-crud-postgres/routes"
"log"
"net/http"
"os"
)

func main() {
r := router.Router()
// fs := http.FileServer(http.Dir("build"))
// http.Handle("/", fs)
fmt.Println("Server dijalankan pada port 8080...")
// Use the router from the imported package
r := routes.Router()

log.Fatal(http.ListenAndServe(":8080", r))
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}

fmt.Printf("Server is running on port %s...\n", port)
log.Fatal(http.ListenAndServe(":"+port, r))
}
8 changes: 4 additions & 4 deletions routes/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package router
package routes

import (
"go-crud-postgres/controllers"
"go-crud-postgres/controllers" // Update the import path to match your project structure

"github.com/gorilla/mux"
)
Expand All @@ -10,11 +10,11 @@ func Router() *mux.Router {

router := mux.NewRouter()

router.HandleFunc("/api/buku", controller.AmbilSemuaBuku).Methods("GET", "OPTIONS")
router.HandleFunc("/api/buku", controller.AmbilSemuaBuku).Methods("GET", "OPTIONS") // Update the controller reference
router.HandleFunc("/api/buku/{id}", controller.AmbilBuku).Methods("GET", "OPTIONS")
router.HandleFunc("/api/buku", controller.TmbhBuku).Methods("POST", "OPTIONS")
router.HandleFunc("/api/buku/{id}", controller.UpdateBuku).Methods("PUT", "OPTIONS")
router.HandleFunc("/api/buku/{id}", controller.HapusBuku).Methods("DELETE", "OPTIONS")

return router
}
}

0 comments on commit d92caac

Please sign in to comment.