Skip to content

Commit

Permalink
fix routing for Garden
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Jul 24, 2019
1 parent 29a399f commit 6e64d7d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
6 changes: 5 additions & 1 deletion microservices-rest/links/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ services:
- name: http
containerPort: 8080
ingresses:
- path: /db
- path: /test
port: http
# Needs an id to work. E.g garden call links/link/1
# Returns 404 if no link with that id but you'll see the call is being received if you do garden logs links
- path: /link
port: http
env:
REPOSITORY_ADDRESS: ":8080"
6 changes: 4 additions & 2 deletions microservices-rest/links/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"encoding/json"
"fmt"
"log"
"math/rand"
"net/http"
"time"
"fmt"

"github.com/campoy/links/microservices-rest/repository"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -35,7 +35,8 @@ func main() {
mux.HandleFunc("/link/", newLink).Methods("POST")
mux.HandleFunc("/link/{id}", getLink).Methods("GET")
mux.HandleFunc("/link/{id}", countVisit).Methods("POST")
// mux.HandleFunc("/db/test/", test)
// This works if there's no forward slash at the end of /test
mux.HandleFunc("/test", test).Methods("GET")
// mux.HandleFunc("/db/link/", newLink).Methods("POST")
// mux.HandleFunc("/db/link/{id}", getLink).Methods("GET")
// mux.HandleFunc("/db/link/{id}", countVisit).Methods("POST")
Expand Down Expand Up @@ -69,6 +70,7 @@ func newLink(w http.ResponseWriter, r *http.Request) {

func getLink(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
log.Printf("getting link: %v", id)
link, err := links.Get(id)
if err != nil {
if err == repository.ErrNoSuchLink {
Expand Down
6 changes: 4 additions & 2 deletions microservices-rest/router/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ services:
- name: http
containerPort: 8085
ingresses:
- path: /router
- path: /l
port: http
- path: /s
port: http
env:
ROUTER_ADDRESS: ":8085"
REPOSITORY_ADDRESS: "http://garden.local/db/"
ROUTER_REPOSITORY: "http://links:8080"

8 changes: 6 additions & 2 deletions microservices-rest/web/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ services:
port: http
env:
WEB_ADDRESS: ":8090"
WEB_REPOSITORY: "http://garden.local/db/"
WEB_ROUTER: "http://garden.local/router/"
# Use http://<svc_name>:<servicePort> to talk to other services in the cluster.
# servicePort defaults to containerPort if not specified.
WEB_REPOSITORY: "http://links:8080"
# Here we're using the external hostname since we're accessing the router
# from the web UI
WEB_ROUTER: "http://garden.local"
2 changes: 1 addition & 1 deletion microservices-rest/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {

s := server{links: client.New(config.Repository),
router: config.Router,
}
}

http.HandleFunc("/", s.handleNew)
log.Fatal(http.ListenAndServe(config.Address, nil))
Expand Down

0 comments on commit 6e64d7d

Please sign in to comment.