Skip to content

Commit

Permalink
Created response function, will return shorten URL
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 507580a commit 31b79e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func handleShortUrl(writer http.ResponseWriter, req *http.Request) {

// save short and long URL to file
src.SaveToFile(shortURL, originalURL)

host := req.Host

// build Response
resp := src.BuildURLResponse(host, shortURL, originalURL)
fmt.Println("response: ", resp)
}

func main() {
Expand Down
15 changes: 15 additions & 0 deletions src/buildURLresponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package src

type URLResponse struct {
OriginalURL string `json:"originalURL"`
ShortURL string `json:"shortURL"`
}

// It returns short URL as response
func BuildURLResponse(host string, shortURL string, originalURL string) *URLResponse {
resp := &URLResponse{
OriginalURL: originalURL,
ShortURL: "http://" + host + "/" + shortURL,
}
return resp
}

0 comments on commit 31b79e7

Please sign in to comment.