Skip to content

Commit

Permalink
how does it cast to handler???
Browse files Browse the repository at this point in the history
  • Loading branch information
ale8k committed Nov 27, 2021
1 parent 2319e54 commit ce44c15
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/handlers/healthz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package handlers

import (
"net/http"
)

func GetServerHealth(resp http.ResponseWriter, req http.Request) {

}
32 changes: 31 additions & 1 deletion internal/server.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
package internal

import (
"fmt"
"log"
"net/http"
)

var Handler *http.ServeMux

func logg(h http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Before")
h.ServeHTTP(w, r) // call original
fmt.Println("After")
})
}

func StartServer() {
k := logg(nil)
fmt.Println(k)
Handler := http.NewServeMux()

// type HandlerFunc func(ResponseWriter, *Request)
// internal mux call just casts our func to this ^
// func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
// if handler == nil {
// panic("http: nil handler")
// }
// mux.Handle(pattern, HandlerFunc(handler))
// }

// type Handler interface {
// ServeHTTP(ResponseWriter, *Request)
// }

server := &http.Server{
Addr: ":9000",
Handler: nil,
Handler: Handler,
}

log.Println("Starting server on port 9000...")
log.Fatalf("Server failed to start: %v", server.ListenAndServe())
}

0 comments on commit ce44c15

Please sign in to comment.