package Api import ( "errors" "log" "net/http" "git.tovijaeschke.xyz/tovi/SuddenImpactRecords/Database" "git.tovijaeschke.xyz/tovi/SuddenImpactRecords/Models" "github.com/gorilla/mux" ) func getUserId(r *http.Request) (string, error) { var ( urlVars map[string]string id string ok bool ) urlVars = mux.Vars(r) id, ok = urlVars["userID"] if !ok { return id, errors.New("Could not get id") } return id, nil } func getUserById(w http.ResponseWriter, r *http.Request) (Models.User, error) { var ( postData Models.User id string err error ) id, err = getUserId(r) if err != nil { log.Printf("Error encountered getting id\n") JsonReturn(w, 500, "An error occured") return postData, err } postData, err = Database.GetUserById(id) if err != nil { log.Printf("Could not find pet with id %s\n", id) JsonReturn(w, 404, "Not found") return postData, err } return postData, nil }