Files
CatsOfMastodonGo/cmd/main.go

56 lines
1.6 KiB
Go

package main
import (
"CatsOfMastodonBotGo/internal/helpers"
"CatsOfMastodonBotGo/internal/models"
"CatsOfMastodonBotGo/internal/server"
"context"
"log"
"time"
"github.com/gin-gonic/gin"
)
func main() {
// Setup AppContext
var appContext = helpers.SetupAppContext()
// Get posts
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
var posts []models.Post = nil
err, posts := appContext.PostService.GetPostsFromApi(ctx, appContext.Tag, appContext.Instance)
if err != nil {
log.Fatal(err)
}
var existingPostIds = appContext.PostService.GetExistingPostIds()
var existingAccountIds = appContext.PostService.GetExistingAccountIds()
var newPosts = appContext.PostService.GetNewPosts(existingPostIds, posts)
var newAccounts = appContext.PostService.GetNewAccounts(existingAccountIds, newPosts)
// Save to database
log.Println("Number of existing posts: ", len(existingPostIds))
log.Println("Number of existing accounts: ", len(existingAccountIds))
log.Println("Number of new posts: ", len(newPosts))
log.Println("Number of new accounts: ", len(newAccounts))
// Additional logging
if newAccounts != nil {
log.Println("Number of inserted accounts: ", appContext.PostService.InsertNewAccounts(newAccounts))
} else {
log.Println("No new accounts inserted")
}
if newPosts != nil {
log.Println("Number of inserted posts: ", appContext.PostService.InsertNewPosts(newPosts))
} else {
log.Println("No new posts inserted")
}
// https://seefnasrul.medium.com/create-your-first-go-rest-api-with-jwt-authentication-in-gin-framework-dbe5bda72817
engine := gin.Default()
r := server.SetupRouter(engine)
r.Run(":8080")
}