Files
playerservice/nbaservice/rest/rest.go
T
2020-08-14 10:21:12 +08:00

24 lines
691 B
Go

package rest
import (
"fmt"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"nbarest/lib/persistence"
"net/http"
)
func ServeAPI(endpoint string,dbhandler persistence.DatabaseHandler) error{
handler:=NewPlayerServiceHandler(dbhandler)
r:=mux.NewRouter()
playersrouter:=r.PathPrefix("/players").Subrouter()
playersrouter.Path("/{SearchCriteria}/{search}").HandlerFunc(handler.FindPlayerHandler).Methods("GET")
playersrouter.Path("/").HandlerFunc(handler.FindAllPlayerHandler).Methods("GET")
playersrouter.Path("/").HandlerFunc(handler.NewPlayerHandler).Methods("POST")
fmt.Println("listen")
server := handlers.CORS()(r)
return http.ListenAndServe(endpoint, server)
}