40 lines
		
	
	
		
			940 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			940 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"golias/handlers"
 | |
| 	"log/slog"
 | |
| 	"net/http"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| // TODO: add config as param
 | |
| func ListenToRequests(port string) error {
 | |
| 	mux := http.NewServeMux()
 | |
| 	server := &http.Server{
 | |
| 		Handler:      handlers.LogRequests(handlers.GetSession(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)
 | |
| 	mux.HandleFunc("POST /login", handlers.HandleFrontLogin)
 | |
| 	//elements
 | |
| 	mux.HandleFunc("GET /room/createform", handlers.HandleShowCreateForm)
 | |
| 	mux.HandleFunc("GET /room/hideform", handlers.HandleHideCreateForm)
 | |
| 	slog.Info("Listening", "addr", port)
 | |
| 	return server.ListenAndServe()
 | |
| }
 | |
| 
 | |
| func main() {
 | |
| 	port := ":3000"
 | |
| 	err := ListenToRequests(port)
 | |
| 	if err != nil {
 | |
| 		panic(err)
 | |
| 	}
 | |
| }
 | 
