features/added-user-tables #3

Merged
jtom38 merged 7 commits from features/added-user-tables into main 2024-04-26 16:06:36 -07:00
Showing only changes of commit 8ea3f5fef1 - Show all commits

View File

@ -6,9 +6,12 @@ import (
"fmt" "fmt"
"net/http" "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/docs"
"git.jamestombleson.com/jtom38/newsbot-api/internal/database" "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"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/cron"
) )
@ -17,12 +20,24 @@ import (
// @version 0.1 // @version 0.1
// @BasePath /api // @BasePath /api
func main() { func main() {
ctx := context.Background()
cfg := services.NewConfig() cfg := services.NewConfig()
configs := services.GetEnvConfig()
address := cfg.GetConfig(services.ServerAddress) address := cfg.GetConfig(services.ServerAddress)
docs.SwaggerInfo.Host = fmt.Sprintf("%v:8081", address) docs.SwaggerInfo.Host = fmt.Sprintf("%v:8081", address)
ctx := context.Background() db, err := sql.Open("sqlite", "newsbot.db")
db, err := sql.Open("postgres", cfg.GetConfig(services.Sql_Connection_String)) if err != nil {
panic(err)
}
err = goose.SetDialect("sqlite3")
if err != nil {
panic(err)
}
err = goose.Up(db, "../internal/database/migrations")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -32,11 +47,11 @@ func main() {
c := cron.NewScheduler(ctx) c := cron.NewScheduler(ctx)
c.Start() c.Start()
server := v1.NewServer(ctx, queries) server := v1.NewServer(ctx, queries, configs, db)
fmt.Println("API is online and waiting for requests.") fmt.Println("API is online and waiting for requests.")
fmt.Printf("API: http://%v:8081/api\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", address) fmt.Printf("Swagger: http://%v:8081/swagger/index.html\r\n", configs.ServerAddress)
err = http.ListenAndServe(":8081", server.Router) err = http.ListenAndServe(":8081", server.Router)
if err != nil { if err != nil {