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

53 lines
1.1 KiB
Go
Raw Normal View History

2023-05-22 11:08:08 +00:00
package main
import (
"context"
2023-05-24 14:05:27 +00:00
"e621_to_neo4j/api"
"e621_to_neo4j/database"
neo4j "e621_to_neo4j/database/neo4j"
2023-05-24 14:05:27 +00:00
"e621_to_neo4j/e621"
2023-05-22 11:08:08 +00:00
"e621_to_neo4j/utils"
"log"
2023-05-24 14:05:27 +00:00
"net/http"
"strings"
2023-05-22 11:08:08 +00:00
)
func main() {
var graphConnection database.GraphConnection
ctx := context.Background()
2023-05-24 14:05:27 +00:00
// Loads Config
2023-05-22 11:08:08 +00:00
config, err := utils.LoadConfig()
if err != nil {
log.Println(err)
}
switch strings.ToLower(config.DBType) {
case "neo4j":
log.Println("Setup Neo4J Connection")
graphConnection = neo4j.NewNeo4JConnection()
err = graphConnection.Connect(ctx, config.DBEndpoint, config.Neo4jUsername, config.Neo4jPassword)
if err != nil {
panic(err)
}
log.Println("Connection successful")
default:
panic("No Database was selected!")
}
2023-05-22 11:08:08 +00:00
2023-05-24 14:05:27 +00:00
// Initialize the e621API
e621Client := e621.NewClient(config.E621APIKey, config.E621Username)
2023-05-22 11:08:08 +00:00
log.Printf("Im ready!")
2023-05-24 14:05:27 +00:00
// Register the UserHandler with the "/user" route
http.HandleFunc("/user", api.UserHandler(ctx, graphConnection, e621Client))
2023-05-22 11:08:08 +00:00
2023-05-24 14:05:27 +00:00
// Start the HTTP server
err = http.ListenAndServe(":8080", nil)
if err != nil {
2023-05-24 14:05:27 +00:00
return
}
}