Initial commit: wb-mock skeleton

This commit is contained in:
root
2026-07-23 19:02:03 +03:00
commit 93ebcf4406
9 changed files with 217 additions and 0 deletions

38
cmd/server/main.go Normal file
View File

@ -0,0 +1,38 @@
package main
import (
"log"
"net/http"
"github.com/rinat/wb-mock/internal/config"
"github.com/rinat/wb-mock/internal/middleware"
)
func main() {
cfg := config.Load()
mux := http.NewServeMux()
auth := func(h http.HandlerFunc) http.HandlerFunc {
return middleware.Auth(cfg.APIKey, h)
}
// Health
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"status":"ok"}`))
})
_ = auth
// 404 handler
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(`{"code":404,"message":"not found"}`))
})
addr := ":" + cfg.Port
log.Printf("Starting wb-mock on %s", addr)
log.Fatal(http.ListenAndServe(addr, mux))
}