Skip to content

Commit

Permalink
inserting into DB
Browse files Browse the repository at this point in the history
  • Loading branch information
gagarinfan committed Dec 20, 2018
1 parent 90c553d commit 1b48c8e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions SQL4/sqljson.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func GetPeopleEndpoint(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(people)
}
func CreatePersonEndpoint(w http.ResponseWriter, r *http.Request) {
cnstr := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;database=%s;", server, user, password, port, database)
params := mux.Vars(r)
var person Person
_ = json.NewDecoder(r.Body).Decode(&person)
Expand All @@ -232,6 +233,10 @@ func CreatePersonEndpoint(w http.ResponseWriter, r *http.Request) {
person.Location = params["location"]
people = append(people, person)
json.NewEncoder(w).Encode(people)
_, errnew := dodaj(cnstr, person.Name, person.Location)
if errnew != nil {
log.Fatal("Cannot save. Caused by: ", errnew)
}
}
func DeletePersonEndpoint(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
Expand Down

0 comments on commit 1b48c8e

Please sign in to comment.