first coomit

This commit is contained in:
2020-08-10 12:58:54 +08:00
commit 5c00a2534b
16 changed files with 307 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
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)
}