package main import ( "context" "database/sql" "fmt" "net/http" "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/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron" ) // @title NewsBot collector // @version 0.1 // @BasePath /api func main() { cfg := services.NewConfig() 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)) if err != nil { panic(err) } queries := database.New(db) c := cron.NewScheduler(ctx) c.Start() server := v1.NewServer(ctx, queries) 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) err = http.ListenAndServe(":8081", server.Router) if err != nil { panic(err) } }