very basic thoughts on module and file structure
basic configuration basic logger
This commit is contained in:
parent
2568d9dd1a
commit
326fdcae6e
1
api/api.go
Normal file
1
api/api.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package api
|
32
config/config.go
Normal file
32
config/config.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config contains the configuration of the Pterodactyl Daemon
|
||||||
|
type Config struct {
|
||||||
|
|
||||||
|
// Log contains configuration related to logging
|
||||||
|
Log struct {
|
||||||
|
|
||||||
|
// DeleteAfterDays is the time in days after which logfiles are deleted
|
||||||
|
// If set to <= 0 logs are kept forever
|
||||||
|
DeleteAfterDays int
|
||||||
|
} `json:"log"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadConfiguration() error {
|
||||||
|
viper.SetConfigName("config")
|
||||||
|
viper.AddConfigPath(".")
|
||||||
|
// Find and read the config file
|
||||||
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func setDefaults() {
|
||||||
|
|
||||||
|
}
|
18
environments/docker.go
Normal file
18
environments/docker.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package environments
|
||||||
|
|
||||||
|
type DockerEnvironment struct {
|
||||||
|
BaseEnvironment
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDockerEnvironment() *DockerEnvironment {
|
||||||
|
return &DockerEnvironment{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (env *DockerEnvironment) Exec() error {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (env *DockerEnvironment) Create() error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
43
environments/environment.go
Normal file
43
environments/environment.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package environments
|
||||||
|
|
||||||
|
// Environment provides abstraction of different environments
|
||||||
|
type Environment interface {
|
||||||
|
// Execute a command in the environment
|
||||||
|
Exec() error
|
||||||
|
|
||||||
|
// Create creates the environment
|
||||||
|
Create() error
|
||||||
|
|
||||||
|
// Destroy destroys the environment
|
||||||
|
Destroy() error
|
||||||
|
|
||||||
|
// Exists checks wether the Environment exists or not
|
||||||
|
Exists() bool
|
||||||
|
|
||||||
|
// ReCreate recreates the environment by first Destroying and then Creating
|
||||||
|
ReCreate() error
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseEnvironment struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (env *BaseEnvironment) Create() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (env *BaseEnvironment) Destroy() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (env *BaseEnvironment) Exists() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (env *BaseEnvironment) ReCreate() error {
|
||||||
|
if env.Exists() {
|
||||||
|
if err := env.Destroy(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return env.Create()
|
||||||
|
}
|
0
logs/.gitkeep
Normal file
0
logs/.gitkeep
Normal file
24
main.go
Normal file
24
main.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/schrej/pterodactyld/config"
|
||||||
|
"github.com/schrej/pterodactyld/tools"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Version of pterodactyld
|
||||||
|
Version = "0.0.1-alpha"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
tools.ConfigureLogging()
|
||||||
|
|
||||||
|
log.Info("Starting pterodactyld version ", Version)
|
||||||
|
|
||||||
|
// Load configuration
|
||||||
|
log.Info("Loading configuration...")
|
||||||
|
if err := config.LoadConfiguration(); err != nil {
|
||||||
|
log.WithError(err).Fatal("Failed to find configuration file")
|
||||||
|
}
|
||||||
|
}
|
7
services/service.go
Normal file
7
services/service.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import "github.com/schrej/pterodactyld/environments"
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
Environment environments.Environment
|
||||||
|
}
|
31
tools/logging.go
Normal file
31
tools/logging.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
rotatelogs "github.com/lestrrat/go-file-rotatelogs"
|
||||||
|
"github.com/rifflock/lfshook"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ConfigureLogging() {
|
||||||
|
|
||||||
|
log.SetFormatter(&log.TextFormatter{
|
||||||
|
DisableTimestamp: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
path := "logs/"
|
||||||
|
writer := rotatelogs.New(
|
||||||
|
path+"pterodactyld.%Y%m%d-%H%M.log",
|
||||||
|
rotatelogs.WithLinkName(path),
|
||||||
|
rotatelogs.WithMaxAge(time.Duration(86400)*time.Second),
|
||||||
|
rotatelogs.WithRotationTime(time.Duration(604800)*time.Second),
|
||||||
|
)
|
||||||
|
|
||||||
|
log.AddHook(lfshook.NewHook(lfshook.WriterMap{
|
||||||
|
log.InfoLevel: writer,
|
||||||
|
log.ErrorLevel: writer,
|
||||||
|
log.FatalLevel: writer,
|
||||||
|
log.PanicLevel: writer,
|
||||||
|
}))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user