This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/main.go
2023-05-24 23:11:20 +02:00

51 lines
986 B
Go

package main
import (
"context"
"e621_to_neo4j/api"
"e621_to_neo4j/e621"
"e621_to_neo4j/neo4jAPI"
"e621_to_neo4j/utils"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"log"
"net/http"
)
func main() {
// Loads Config
config, err := utils.LoadConfig()
if err != nil {
log.Println(err)
}
// Connect to Neo4j DB
driver, err := neo4jAPI.NewConnection(config.Neo4jURL, config.Neo4jUsername, config.Neo4jPassword)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
defer func(driver neo4j.DriverWithContext, ctx context.Context) {
err := driver.Close(ctx)
if err != nil {
log.Fatal(err)
}
}(driver, ctx)
// Initialize the e621API
e621Client := e621.NewClient(config.E621APIKey, config.E621Username)
log.Printf("Im ready!")
// Register the UserHandler with the "/user" route
http.HandleFunc("/user", api.UserHandler(ctx, driver, e621Client))
// Start the HTTP server
err = http.ListenAndServe(":8080", nil)
if err != nil {
return
}
}