import sources from develop/0.1.0
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func main() {
|
||||
connectionString := "kontor:kontor@tcp(127.0.0.1:3306)/kontor?parseTime=true"
|
||||
db, err := sql.Open("mysql", connectionString)
|
||||
if err != nil {
|
||||
log.Printf("setup database error: %v", err)
|
||||
return
|
||||
}
|
||||
db.SetConnMaxLifetime(time.Minute * 3)
|
||||
db.SetMaxOpenConns(10)
|
||||
db.SetMaxIdleConns(10)
|
||||
log.Println("Database connected")
|
||||
|
||||
rows, err := db.Query("SELECT id, created_date, last_modified_date, version, url, title, review FROM media_file")
|
||||
if err != nil {
|
||||
log.Fatal((err.Error()))
|
||||
}
|
||||
defer rows.Close()
|
||||
var rec MediaFile
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&rec.ID, &rec.CreatedDate, &rec.LastModifiedDate, &rec.Version, &rec.Url, &rec.Title, &rec.Review)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
log.Println(rec, string(rec.Url), string(rec.Title))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type AbstractEntity struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key" json:"id"`
|
||||
Version uint `json:"version"`
|
||||
CreatedDate time.Time `json:"createdDate"`
|
||||
LastModifiedDate time.Time `json:"lastModifiedDate"`
|
||||
}
|
||||
|
||||
type MediaFile struct {
|
||||
AbstractEntity
|
||||
Url []byte `json:"url"`
|
||||
Review []uint8 `json:"review"`
|
||||
ShouldDownload []uint8 `json:"shouldDownload"`
|
||||
Title []byte `json:"title"`
|
||||
CloudLink string `json:"cloudLink"`
|
||||
FileName string `json:"fileName"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gitlab.thpeetz.de/kontor/kontor-go/pkg/properties"
|
||||
"gitlab.thpeetz.de/kontor/kontor-go/pkg/setup"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
// Verbose defines the parameter verbose.
|
||||
Verbose bool
|
||||
// Version defines the version of the web application.
|
||||
Version string
|
||||
// Debug defines the debug parameter.
|
||||
Debug bool
|
||||
// Port defines the parameter port.
|
||||
Port int
|
||||
// TemplatesDir defines the root directory of template files.
|
||||
TemplatesDir string
|
||||
router *gin.Engine
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "kontor",
|
||||
Short: "kontor",
|
||||
Long: `kontor`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Set Gin to production mode
|
||||
if Debug {
|
||||
gin.SetMode(gin.DebugMode)
|
||||
} else {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
log.SetOutput(gin.DefaultWriter)
|
||||
|
||||
// Set the router as the default one provided by Gin
|
||||
router = gin.Default()
|
||||
|
||||
// Process the templates at the start so that they don't have to be loaded
|
||||
// from the disk again. This makes serving HTML pages very fast.
|
||||
templatesDir := fmt.Sprintf("%s/**/*", TemplatesDir)
|
||||
log.Printf("load template files from %v", templatesDir)
|
||||
router.LoadHTMLGlob(templatesDir)
|
||||
|
||||
// Use Middleware logger
|
||||
router.Use(gin.Logger())
|
||||
|
||||
// Initialize the routes
|
||||
setup.InitializeRoutes(router)
|
||||
|
||||
// Clean up SetSessionStatus
|
||||
setup.CleanupSessions()
|
||||
|
||||
// Check if at least one user configured
|
||||
setup.CheckUserList()
|
||||
|
||||
// Check if data for TradeYourSportsCards is available
|
||||
setup.CheckTradeYourSportsCardsData()
|
||||
|
||||
//properties.SetVersion(Version)
|
||||
|
||||
// Start serving the application
|
||||
server := fmt.Sprintf("127.0.0.1:%d", Port)
|
||||
router.Run(server)
|
||||
},
|
||||
}
|
||||
|
||||
// Execute parses the commandline and calls Execute on rootCmd.
|
||||
func Execute(version string) {
|
||||
rootCmd.Version = version
|
||||
properties.SetVersion(version)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
|
||||
rootCmd.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug modus")
|
||||
rootCmd.PersistentFlags().IntVarP(&Port, "port", "p", 8500, "port number")
|
||||
rootCmd.PersistentFlags().StringVarP(&TemplatesDir, "templates", "t", "templates", "path for template files")
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/joho/godotenv"
|
||||
application "gitlab.com/tpeetz-kontor/kontor-go/pkg/infrastructure/app"
|
||||
"gitlab.com/tpeetz-kontor/kontor-go/pkg/infrastructure/kernel"
|
||||
)
|
||||
|
||||
// init is invoked before main()
|
||||
func init() {
|
||||
// loads values from .env into the system
|
||||
if err := godotenv.Load(); err != nil {
|
||||
panic("No .env file found")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Create our application
|
||||
app := kernel.Boot()
|
||||
|
||||
// Build our services
|
||||
//ping.BuildPingService(app)
|
||||
|
||||
// Run our Application in a coroutine
|
||||
go func() {
|
||||
app.Run()
|
||||
}()
|
||||
|
||||
// Wait for termination signals and shut down gracefully
|
||||
application.WaitForShutdown(app)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user