2023-05-22 11:08:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-05-24 14:05:27 +00:00
|
|
|
"e621_to_neo4j/api"
|
2023-06-20 08:38:36 +00:00
|
|
|
"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"
|
2023-06-21 11:29:23 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2023-05-24 14:05:27 +00:00
|
|
|
"net/http"
|
2023-06-21 11:29:23 +00:00
|
|
|
"os"
|
2023-06-20 08:38:36 +00:00
|
|
|
"strings"
|
2023-05-22 11:08:08 +00:00
|
|
|
)
|
|
|
|
|
2023-06-21 11:29:23 +00:00
|
|
|
func init() {
|
|
|
|
// Log as JSON instead of the default ASCII formatter.
|
|
|
|
//log.SetFormatter(&log.JSONFormatter{})
|
|
|
|
|
|
|
|
// Output to stdout instead of the default stderr
|
|
|
|
// Can be any io.Writer, see below for File example
|
|
|
|
log.SetOutput(os.Stdout)
|
|
|
|
|
|
|
|
// Only log the warning severity or above.
|
2023-06-22 09:00:08 +00:00
|
|
|
log.SetLevel(log.DebugLevel)
|
2023-06-21 11:29:23 +00:00
|
|
|
|
|
|
|
// Logging Method Name
|
|
|
|
//log.SetReportCaller(true)
|
|
|
|
}
|
|
|
|
|
2023-05-22 11:08:08 +00:00
|
|
|
func main() {
|
2023-06-21 11:29:23 +00:00
|
|
|
|
2023-06-20 08:38:36 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-06-20 08:38:36 +00:00
|
|
|
switch strings.ToLower(config.DBType) {
|
|
|
|
case "neo4j":
|
|
|
|
log.Println("Setup Neo4J Connection")
|
|
|
|
graphConnection = neo4j.NewNeo4JConnection()
|
2023-06-22 09:00:08 +00:00
|
|
|
err = graphConnection.Connect(ctx, config.DBEndpoint, config.DBUsername, config.DBPassword)
|
2023-05-22 19:01:59 +00:00
|
|
|
if err != nil {
|
2023-06-20 08:38:36 +00:00
|
|
|
panic(err)
|
2023-05-22 19:01:59 +00:00
|
|
|
}
|
2023-06-20 08:38:36 +00:00
|
|
|
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
|
|
|
|
2023-05-24 21:11:20 +00:00
|
|
|
log.Printf("Im ready!")
|
|
|
|
|
2023-05-24 14:05:27 +00:00
|
|
|
// Register the UserHandler with the "/user" route
|
2023-06-20 08:38:36 +00:00
|
|
|
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)
|
2023-05-22 20:10:05 +00:00
|
|
|
if err != nil {
|
2023-05-24 14:05:27 +00:00
|
|
|
return
|
2023-05-22 20:10:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|