package main import ( "nickiel.net/recount_server/db" "nickiel.net/recount_server/tests" "nickiel.net/recount_server/web" "net/http" "flag" "fmt" "os" //"github.com/shopspring/decimal" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/rs/zerolog" "github.com/rs/zerolog/log" ) var DB_TYPE = "postgres" var DB_SCHEMA = "rcnt." var DB_CONNECTION_STRING string = "user=rcntuser password=Devel@pmentPa$$w0rd host=10.0.0.183 dbname=Borealis sslmode=disable" func hello(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "hello\n") } func headers(w http.ResponseWriter, req *http.Request) { for name, headers := range req.Header { for _, h := range headers { fmt.Fprintf(w, "%v: %v\n", name, h) } } } func main() { zerolog.TimeFieldFormat = zerolog.TimeFormatUnix zerolog.SetGlobalLevel(zerolog.InfoLevel) log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) var debugFlag = flag.Bool("d", false, "whether to enable debug mode") var traceFlag = flag.Bool("t", false, "whether to trace logging") flag.Parse() if *traceFlag { zerolog.SetGlobalLevel(zerolog.TraceLevel) log.Debug().Msg("Enabling trace level debugging") } if *debugFlag { if !*traceFlag { zerolog.SetGlobalLevel(zerolog.DebugLevel) } log.Debug().Msg("Is debugging") DB_TYPE = "sqlite3" DB_SCHEMA = "" DB_CONNECTION_STRING = "test.db" debug_mode.Init_testdb(DB_TYPE, DB_CONNECTION_STRING) } db.SetConstants(DB_TYPE, DB_SCHEMA, DB_CONNECTION_STRING) debug_mode.SetLogLevel(zerolog.GlobalLevel()) log.Info().Msg("starting server") r := chi.NewRouter() // A good base middleware stack r.Use(middleware.RequestID) r.Use(middleware.RealIP) r.Use(middleware.Recoverer) r.Use(middleware.Logger) // Set a timeout value on the request context (ctx), that will signal // through ctx.Done() that the request has timed out and further // processing should be stopped. //r.Use(middleware.Timeout(60 * time.Second)) r.Get("/headers", headers) r.Mount("/", web.WebRouter()) r.Mount("/api", apiRouter()) err := http.ListenAndServe(":8090", r) if err != nil { log.Fatal(). Err(err). Msg("Could not open server connection") } //fmt.Println("Hello World") }