Initial commit: wb-mock skeleton
This commit is contained in:
22
internal/handlers/handlers.go
Normal file
22
internal/handlers/handlers.go
Normal file
@ -0,0 +1,22 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
|
||||
func decodeBody(r *http.Request, v any) error {
|
||||
defer r.Body.Close()
|
||||
return json.NewDecoder(r.Body).Decode(v)
|
||||
}
|
||||
|
||||
func logRequest(r *http.Request) {
|
||||
log.Printf("[wb-mock] %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
Reference in New Issue
Block a user