Skip to content

Commit

Permalink
add endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
matassp committed Nov 8, 2019
1 parent 4b29816 commit 4ac79eb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/tcentric/cloud-lab/internal/controller"
"github.com/matassp/cloud-lab/internal/controller"
"log"
"net/http"
"os"
Expand All @@ -24,6 +24,7 @@ func server() {
r.HandleFunc("/username", controller.GithubUsernameHandler).Methods("GET")

// TODO. Add a handler here which will use controller.Sha256Handler function for HTTP "GET" method. Use curly brackets for path matching, like this: /{username}
r.HandleFunc("/{username}", controller.Sha256Handler).Methods("GET")

// serve static files - DO NOT CHANGE THIS!
r.PathPrefix("/ui/css").Handler(http.StripPrefix("/ui/css", http.FileServer(http.Dir("static/css"))))
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/tcentric/cloud-lab
module github.com/matassp/cloud-lab

go 1.12

require (
github.com/gorilla/mux v1.7.3
github.com/spf13/cobra v0.0.5
github.com/tcentric/cloud-lab v0.0.0-20191107221551-dbe5168258a5
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/tcentric/cloud-lab v0.0.0-20191107221551-dbe5168258a5 h1:3KMROzqpiRswH4IqxIRQwNpRdLsaUb7IgZzZhh21Ziw=
github.com/tcentric/cloud-lab v0.0.0-20191107221551-dbe5168258a5/go.mod h1:RVwtfFlOS5EN1ENduUXDSJQFnxFksbjAVXi6hq/uv+w=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
6 changes: 3 additions & 3 deletions infrastructure/k8s/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: lab
namespace: # TODO. Add your kubernetes namespace here. You can find your kubernetes namespace by running command: kubectl config view | grep namespace
namespace: ktu-stud-matassp
labels:
lab: microservices
spec:
Expand All @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: app
image: tcentric/cloud-lab:0.1 # TODO. Change this to your image from your Docker Hub repo
image: mat2s/cloud-lab:v0.1
ports:
- name: http
containerPort: 8080
Expand All @@ -30,4 +30,4 @@ spec:
cpu: "50m"
env:
- name: GITHUB_USERNAME
value: tcentric # TODO. Change this to your username
value: matassp
2 changes: 1 addition & 1 deletion infrastructure/k8s/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: lab
namespace: # TODO. Add your kubernetes namespace here. You can find your kubernetes namespace by running command: kubectl config view | grep namespace
namespace: ktu-stud-matassp
spec:
selector:
app: lab
Expand Down
13 changes: 5 additions & 8 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import (
"fmt"
"net/http"
"os"
"github.com/matassp/cloud-lab/internal/hashes"
"github.com/gorilla/mux"
)

func Sha256Handler(w http.ResponseWriter, r *http.Request) {
// to get the username, use the following:
//username := mux.Vars(r)["username"]

// to calculate sha256 hash of a string, use internal/hashes package and function GetHash

// to send the response, use the following:
// fmt.Fprint(w, "your response here")

username := mux.Vars(r)["username"]
h, _ := hashes.GetHash("Sha256", username)
fmt.Fprint(w, h)
w.WriteHeader(http.StatusOK)
}

Expand Down

0 comments on commit 4ac79eb

Please sign in to comment.