From 8ea3f5fef1b7e1c38a74e1d162159b49ccd70c5d Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Fri, 26 Apr 2024 16:02:14 -0700 Subject: [PATCH] renamed the main go file to server --- cmd/{main.go => server.go} | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) rename cmd/{main.go => server.go} (58%) diff --git a/cmd/main.go b/cmd/server.go similarity index 58% rename from cmd/main.go rename to cmd/server.go index 5cbdc34..c028d1d 100644 --- a/cmd/main.go +++ b/cmd/server.go @@ -6,9 +6,12 @@ import ( "fmt" "net/http" + _ "github.com/glebarez/go-sqlite" + "github.com/pressly/goose/v3" + "git.jamestombleson.com/jtom38/newsbot-api/docs" "git.jamestombleson.com/jtom38/newsbot-api/internal/database" - v1 "git.jamestombleson.com/jtom38/newsbot-api/internal/handler/v1" + "git.jamestombleson.com/jtom38/newsbot-api/internal/handler/v1" "git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron" ) @@ -17,12 +20,24 @@ import ( // @version 0.1 // @BasePath /api func main() { + ctx := context.Background() + cfg := services.NewConfig() + configs := services.GetEnvConfig() address := cfg.GetConfig(services.ServerAddress) docs.SwaggerInfo.Host = fmt.Sprintf("%v:8081", address) - ctx := context.Background() - db, err := sql.Open("postgres", cfg.GetConfig(services.Sql_Connection_String)) + db, err := sql.Open("sqlite", "newsbot.db") + if err != nil { + panic(err) + } + + err = goose.SetDialect("sqlite3") + if err != nil { + panic(err) + } + + err = goose.Up(db, "../internal/database/migrations") if err != nil { panic(err) } @@ -32,11 +47,11 @@ func main() { c := cron.NewScheduler(ctx) c.Start() - server := v1.NewServer(ctx, queries) + server := v1.NewServer(ctx, queries, configs, db) fmt.Println("API is online and waiting for requests.") - fmt.Printf("API: http://%v:8081/api\r\n", address) - fmt.Printf("Swagger: http://%v:8081/swagger/index.html\r\n", address) + fmt.Printf("API: http://%v:8081/api\r\n", configs.ServerAddress) + fmt.Printf("Swagger: http://%v:8081/swagger/index.html\r\n", configs.ServerAddress) err = http.ListenAndServe(":8081", server.Router) if err != nil {