Skip to content

Commit

Permalink
Merge pull request #6 from viveksahu26/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
viveksahu26 authored Sep 15, 2022
2 parents 2377818 + 3b17c17 commit f886a0f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,31 @@ The advantage of saving Short URL and Long URL in the file is to retrieved that

Enter your URL after *http://localhost:8080/sort-url?longURL=*

And let's say your Long URL: *http://google.com/1346461234567890123456789/get/vivekkumarsahu*
And let's say your Long URL: *http://google.com/1346461234567890123456789/get/viveksahu26*

Finally you complete URL in the browser will look like:

http://localhost:8080/enterLongURL?longURL=http://google.com/1346461234567890123456789/get/vivekkumarsahu
http://localhost:8080/short-url?longURL=http://google.com/1346461234567890123456789/get/viveksahu26

3) You will get output

```
{"originalURL":"http://google.com/1346461234567890123456789/get/vivekkumarsahu","shortURL":"http://localhost:8080/RpP^goh8"}
{"originalURL":"http://google.com/1346461234567890123456789/get/viveksahu26","shortURL":"http://localhost:8080/xtNFxaBwCG"}
```

## Steps to reproduce Using Docker Image
### Step:1
Docker Image: viveksahu26/shortingurl:v3.0.0

Pull docker image:

`docker pull viveksahu26/shortingurl:v3.0.0`

### Step:2
Run container in non-interactive mode

`docker run -d --name vivek -p 3000:8080 viveksahu26/shortingurl:v3.0.0`

Run container in interactive mode

`docker run --name vivek -p 3000:8080 viveksahu26/shortingurl:v3.0.0`
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module github.com/viveksahu26/url_shortner

go 1.19

require gotest.tools v2.2.0+incompatible

require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
26 changes: 12 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,26 @@ func healthCheckUp(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<h1>Health of Server is UP & Running... !!</h1>"))
}

const addr = "localhost:8080"
// const addr = "localhost:8080"

func main() {
fmt.Println("URL Shorten Service Starts ...")

// multiplexer: It provides seperate server interface for each request.
serveMux := http.NewServeMux()
srv := http.Server{
Handler: serveMux,
Addr: addr,
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
fmt.Println("PORT is: ", port)

// handleShortUrl function mapped to /enterLongURL
serveMux.HandleFunc("/sort-url", handleShortURL)
// /health endpoint is mapped to healthCheckUp
http.HandleFunc("/health", healthCheckUp)

// healthCheckUp function mapped to /health
serveMux.HandleFunc("/health", healthCheckUp)
// /short-url endpoint is mapped to handleShortURL
http.HandleFunc("/short-url", handleShortURL)

// Server Listing on "localhost:8080"
err := srv.ListenAndServe()
// Server Listening on localhost:8080
err := http.ListenAndServe(":"+port, nil)
if err != nil {
fmt.Println("Could not serve.")
os.Exit(1)
panic(err)
}
}

0 comments on commit f886a0f

Please sign in to comment.