Skip to content

Commit

Permalink
convert response into JSON bytes as well handling errors
Browse files Browse the repository at this point in the history
Signed-off-by: viveksahu26 <vivekkumarsahu650@gmail.com>
  • Loading branch information
viveksahu26 committed Sep 14, 2022
1 parent 31b79e7 commit 77dee47
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"net/http"

Expand All @@ -24,6 +25,14 @@ func handleShortUrl(writer http.ResponseWriter, req *http.Request) {
// build Response
resp := src.BuildURLResponse(host, shortURL, originalURL)
fmt.Println("response: ", resp)

// Converting response JSON form
jsonBytes, err := json.Marshal(resp)
fmt.Println("jsonBytes: ", jsonBytes)

if err != nil {
writer.Write([]byte("Failed to generate response"))
}
}

func main() {
Expand Down

0 comments on commit 77dee47

Please sign in to comment.