Skip to content

Commit

Permalink
update codebase to compatible with docker
Browse files Browse the repository at this point in the history
Signed-off-by: viveksahu26 <vivekkumarsahu650@gmail.com>
  • Loading branch information
viveksahu26 committed Sep 15, 2022
1 parent 2377818 commit 4db12af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
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 = "3000"
}
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 4db12af

Please sign in to comment.