2022-04-02 12:05:32 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-06-08 21:17:08 -07:00
|
|
|
"context"
|
2023-01-22 10:12:55 -08:00
|
|
|
"database/sql"
|
2022-06-19 22:02:44 -07:00
|
|
|
"fmt"
|
2022-04-02 12:05:32 -07:00
|
|
|
"net/http"
|
2022-07-14 09:59:55 -07:00
|
|
|
|
2023-01-22 10:12:55 -08:00
|
|
|
"github.com/jtom38/newsbot/collector/database"
|
2022-07-14 09:59:55 -07:00
|
|
|
"github.com/jtom38/newsbot/collector/docs"
|
2022-04-02 12:05:32 -07:00
|
|
|
"github.com/jtom38/newsbot/collector/routes"
|
2022-07-14 09:59:55 -07:00
|
|
|
"github.com/jtom38/newsbot/collector/services/config"
|
2022-05-15 21:48:23 -07:00
|
|
|
"github.com/jtom38/newsbot/collector/services/cron"
|
2022-04-02 12:05:32 -07:00
|
|
|
)
|
|
|
|
|
2022-06-19 22:02:44 -07:00
|
|
|
// @title NewsBot collector
|
|
|
|
// @version 0.1
|
|
|
|
// @BasePath /api
|
2022-04-02 12:05:32 -07:00
|
|
|
func main() {
|
2022-07-14 09:59:55 -07:00
|
|
|
cfg := config.New()
|
|
|
|
address := cfg.GetConfig(config.ServerAddress)
|
|
|
|
docs.SwaggerInfo.Host = fmt.Sprintf("%v:8081", address)
|
|
|
|
|
2022-06-08 21:17:08 -07:00
|
|
|
ctx := context.Background()
|
2023-01-22 10:12:55 -08:00
|
|
|
db, err := sql.Open("postgres", cfg.GetConfig(config.Sql_Connection_String))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
queries := database.New(db)
|
|
|
|
|
2022-06-19 22:02:44 -07:00
|
|
|
c := cron.New(ctx)
|
|
|
|
c.Start()
|
2022-06-08 21:17:08 -07:00
|
|
|
|
2023-01-22 10:12:55 -08:00
|
|
|
server := routes.NewServer(ctx, queries)
|
2022-04-02 12:05:32 -07:00
|
|
|
|
2022-06-19 22:02:44 -07:00
|
|
|
fmt.Println("API is online and waiting for requests.")
|
2022-07-14 09:59:55 -07:00
|
|
|
fmt.Printf("API: http://%v:8081/api\r\n", address)
|
|
|
|
fmt.Printf("Swagger: http://%v:8081/swagger/index.html\r\n", address)
|
|
|
|
|
2023-01-22 10:12:55 -08:00
|
|
|
err = http.ListenAndServe(":8081", server.Router)
|
2022-12-04 08:49:17 -08:00
|
|
|
if err != nil {
|
2022-07-13 21:31:53 -07:00
|
|
|
panic(err)
|
|
|
|
}
|
2022-12-04 08:49:17 -08:00
|
|
|
}
|