first commit
This commit is contained in:
47
internal/server/routes.go
Normal file
47
internal/server/routes.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
datapoliklinikHandler "api-poliklinik/pkg/handlers/Poliklinik"
|
||||
datapractitionerHandler "api-poliklinik/pkg/handlers/Practitioner"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (s *Server) RegisterRoutes() http.Handler {
|
||||
r := gin.Default()
|
||||
|
||||
r.GET("/", s.HelloWorldHandler)
|
||||
|
||||
r.GET("/health", s.healthHandler)
|
||||
|
||||
v1 := r.Group("/api")
|
||||
|
||||
Poliklinik := v1.Group("/poliklinik")
|
||||
{
|
||||
Poliklinik.GET("/getdata/statuspelayanan/:statuspelayanan", datapoliklinikHandler.GetDataPoliklinik)
|
||||
}
|
||||
Practitioner := v1.Group("/practitioner")
|
||||
{
|
||||
Practitioner.GET("/getdata", datapractitionerHandler.GetDataPractitioner)
|
||||
}
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*"}, // or specific domains like "http://example.com"
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type"},
|
||||
AllowCredentials: true,
|
||||
}))
|
||||
return r
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) HelloWorldHandler(c *gin.Context) {
|
||||
resp := make(map[string]string)
|
||||
resp["message"] = "Hello World"
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (s *Server) healthHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, s.db.Health())
|
||||
}
|
||||
Reference in New Issue
Block a user