33 lines
733 B
Go
33 lines
733 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"GoStart/src/api"
|
||
|
"GoStart/src/routes"
|
||
|
"GoStart/src/util"
|
||
|
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
|
||
|
func main() {
|
||
|
// Load Configurations
|
||
|
cfg, err := util.LoadConfig()
|
||
|
if err != nil {
|
||
|
fmt.Printf("Failed to load config: %v\n", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
mux := http.NewServeMux()
|
||
|
// Initialize Home View
|
||
|
mux.HandleFunc("/", routes.RootHandler)
|
||
|
// Serve Static Files
|
||
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
||
|
// Example view
|
||
|
mux.HandleFunc("/example", routes.ExampleHandler)
|
||
|
// API endpoint
|
||
|
mux.HandleFunc("/api/example", api.ExampleHandler)
|
||
|
|
||
|
fmt.Printf("Server is running on http://localhost:%d\n", cfg.Port)
|
||
|
http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), mux)
|
||
|
}
|