39 lines
839 B
Go
39 lines
839 B
Go
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))
|
|
}
|