newsbot-api/main.go
James Tombleson ada453e08a
Features/delete source and first dto (#36)
* updated db, added dto for ListSources, and added delete source

* updated from model > models

* updated to models

* sources now sends back a standard message

* updated subscription routes to have beter logid and swagger details

* moved the dto objects back to modles given they are not bound to the database

* cleaned up how we return the error

* cleaned up swag and updated models to take from the base apistatusmodel. less human errors this way

* cleaned up swag and updated models

* swag updated

* updated queue to return a router and also renamed it as it will hold all queue info later on

* removed config tag

* added subscription details route

* article routes have been moved to support dto

* updated discordwebhooks to use dto

* updated discordwebhookqueue to return details on the items via dto

* removed the example routes

* updated sources to use dto

* subscriptions moved to dto

* generated swag
2023-01-22 10:12:55 -08:00

46 lines
1.0 KiB
Go

package main
import (
"context"
"database/sql"
"fmt"
"net/http"
"github.com/jtom38/newsbot/collector/database"
"github.com/jtom38/newsbot/collector/docs"
"github.com/jtom38/newsbot/collector/routes"
"github.com/jtom38/newsbot/collector/services/config"
"github.com/jtom38/newsbot/collector/services/cron"
)
// @title NewsBot collector
// @version 0.1
// @BasePath /api
func main() {
cfg := config.New()
address := cfg.GetConfig(config.ServerAddress)
docs.SwaggerInfo.Host = fmt.Sprintf("%v:8081", address)
ctx := context.Background()
db, err := sql.Open("postgres", cfg.GetConfig(config.Sql_Connection_String))
if err != nil {
panic(err)
}
queries := database.New(db)
c := cron.New(ctx)
c.Start()
server := routes.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)
}
}