26 lines
584 B
Go
26 lines
584 B
Go
package main
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
"pokedex/pokemon"
|
|
"pokedex/rest"
|
|
)
|
|
|
|
func magda(db *gorm.DB, fn func(db *gorm.DB, w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
auth := r.Header.Get("authorization")
|
|
if auth != "Jefklak is cool" {
|
|
rest.Unauthorized(w)
|
|
return
|
|
}
|
|
|
|
fn(db, w, r)
|
|
}
|
|
}
|
|
|
|
func routes(db *gorm.DB) {
|
|
http.HandleFunc("GET /pokemon/", magda(db, pokemon.HandleFindAll))
|
|
http.HandleFunc("GET /pokemon/{name}", magda(db, pokemon.HandleFindSingle))
|
|
}
|