diff --git a/challenge-1/submissions/brenoamin/solution-template.go b/challenge-1/submissions/brenoamin/solution-template.go new file mode 100644 index 000000000..479c17741 --- /dev/null +++ b/challenge-1/submissions/brenoamin/solution-template.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" +) + +func main() { + var a, b int + // Read two integers from standard input + _, err := fmt.Scanf("%d, %d", &a, &b) + if err != nil { + fmt.Println("Error reading input:", err) + return + } + + // Call the Sum function and print the result + result := Sum(a, b) + fmt.Println(result) +} + +// Sum returns the sum of a and b. +func Sum(a int, b int) int { + return a + b +} diff --git a/challenge-5/solution-template.go b/challenge-5/solution-template.go index b915a164c..0ce6302f0 100644 --- a/challenge-5/solution-template.go +++ b/challenge-5/solution-template.go @@ -12,11 +12,16 @@ const validToken = "secret" // Otherwise, respond with 401 Unauthorized. func AuthMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // TODO: Implement the logic: - // 1) Grab the "X-Auth-Token" header - // 2) Compare against validToken - // 3) If mismatch or missing, respond with 401 - // 4) Otherwise pass to next handler + authHeader := r.Header.Get("X-Auth-Token") + if authHeader == "" { + w.WriteHeader(http.StatusUnauthorized) + return + } + + if authHeader == validToken { + next.ServeHTTP(w, r) + } + w.WriteHeader(http.StatusUnauthorized) }) } @@ -47,5 +52,8 @@ func SetupServer() http.Handler { func main() { // Optional: you can run a real server for local testing - // http.ListenAndServe(":8080", SetupServer()) + err := http.ListenAndServe(":8080", SetupServer()) + if err != nil { + fmt.Println(err) + } }