@@ -3,19 +3,18 @@ package main
33import (
44 "flag"
55 "log"
6- "net/http"
76 "os"
87 "strconv"
98
10- "github.com/brianvoe/gofakeit/v6"
11- "github.com/paqstd-team/fake-cli/config"
12- "github.com/paqstd-team/fake-cli/handler"
9+ "github.com/paqstd-team/fake-cli/app"
1310)
1411
1512func main () {
16- // Seed the random number generator for reproducibility
17- gofakeit . Seed ( 0 )
13+ Main ()
14+ }
1815
16+ // Main is the exported entrypoint to allow external tests to exercise startup logic.
17+ func Main () {
1918 // Define command-line flags
2019 port := flag .Int ("p" , 8080 , "port number" )
2120 configPath := flag .String ("c" , "config.json" , "path to config file" )
@@ -37,19 +36,18 @@ func main() {
3736 * configPath = envConfig
3837 }
3938
40- config , err := config . LoadConfigFromFile (* configPath )
39+ server , err := app . Run (* configPath , * port )
4140 if err != nil {
42- log .Fatalf ("Error loading config : %v" , err )
41+ log .Fatalf ("Error starting server : %v" , err )
4342 }
4443
45- server := & http. Server {
46- Addr : ":" + strconv . Itoa ( * port ),
47- Handler : handler . MakeHandler ( config ),
44+ // Allow tests to execute main without blocking
45+ if os . Getenv ( "TESTING" ) == "1" {
46+ return
4847 }
4948
50- log .Printf ("Starting server on %v" , server .Addr )
51- err = server .ListenAndServe ()
52- if err != nil {
49+ // Block in production run
50+ if err := server .ListenAndServe (); err != nil {
5351 log .Fatalf ("Error starting server: %v" , err )
5452 }
5553}
0 commit comments