package main

import (
	"fmt"
	"net/http"
	"golias/handlers"
	"time"
)

// TODO: add config as param
func ListenToRequests(port string) error{
	mux := http.NewServeMux()
	server := &http.Server{
		Handler:      mux,
		Addr:         port,
		ReadTimeout:  time.Second * 5,
		WriteTimeout: time.Second * 5,
	}

	fs := http.FileServer(http.Dir("assets/"))
	mux.Handle("GET /assets/", http.StripPrefix("/assets/", fs))

	mux.HandleFunc("GET /ping", handlers.HandlePing)
	mux.HandleFunc("GET /", handlers.HandleHome)
	fmt.Println("Listening", "addr", port)
	return server.ListenAndServe()
}

func main() {
	port := ":3000"
	fmt.Printf("Starting server on %s\n", port)
	err := ListenToRequests(port)
	if err != nil {
		panic(err)
	}
}
