22 lines
624 B
Go
22 lines
624 B
Go
package rest
|
|
|
|
import (
|
|
"fmt"
|
|
"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")
|
|
return http.ListenAndServe(endpoint,r)
|
|
}
|
|
|