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

70 lines
1.5 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"
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"
"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.
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
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.DBUsername, config.DBPassword)
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
}
}