Add zap logger, migrate some constants up a level

This commit is contained in:
Dane Everitt 2019-03-24 14:37:05 -07:00
parent 79818f5c65
commit 75de4a412a
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
6 changed files with 98 additions and 72 deletions

29
const.go Normal file
View File

@ -0,0 +1,29 @@
package main
import "os"
const (
Version = "0.0.1"
// DefaultFilePerms are the file perms used for created files.
DefaultFilePerms os.FileMode = 0644
// DefaultFolderPerms are the file perms used for created folders.
DefaultFolderPerms os.FileMode = 0755
// ServersPath is the path of the servers within the configured DataPath.
ServersPath = "servers"
// ServerConfigFile is the filename of the server config file.
ServerConfigFile = "server.json"
// ServerDataPath is the path of the data of a single server.
ServerDataPath = "data"
// DockerContainerPrefix is the prefix used for naming Docker containers.
// It's also used to prefix the hostnames of the docker containers.
DockerContainerPrefix = "ptdl-"
// WSMaxMessages is the maximum number of messages that are sent in one transfer.
WSMaxMessages = 10
)

View File

@ -1,35 +0,0 @@
package constants
import "os"
// Version is the current wings version.
const Version = "0.0.1-alpha"
/* ---------- PATHS ---------- */
// DefaultFilePerms are the file perms used for created files.
const DefaultFilePerms os.FileMode = 0644
// DefaultFolderPerms are the file perms used for created folders.
const DefaultFolderPerms os.FileMode = 0744
// ServersPath is the path of the servers within the configured DataPath.
const ServersPath = "servers"
// ServerConfigFile is the filename of the server config file.
const ServerConfigFile = "server.json"
// ServerDataPath is the path of the data of a single server.
const ServerDataPath = "data"
/* ---------- MISC ---------- */
// JSONIndent is the indent to use with the json.MarshalIndent() function.
const JSONIndent = " "
// DockerContainerPrefix is the prefix used for naming Docker containers.
// It's also used to prefix the hostnames of the docker containers.
const DockerContainerPrefix = "ptdl-"
// WSMaxMessages is the maximum number of messages that are sent in one transfer.
const WSMaxMessages = 10

View File

@ -1,29 +0,0 @@
package constants
const IndexPage = `
<!doctype html>
<html>
<head>
<title>Pterodactly wings</title>
<style>
body {
background: #222;
color: #074cd5;
}
pre {
margin: auto;
}
</style
</head>
<body>
<pre>
____
__ Pterodactyl _____/___/_______ _______ ______
\_____\ \/\/ / / / __ / ___/
\___\ / / / / /_/ /___ /
\___/\___/___/___/___/___ /______/
/_______/
</pre>
</body>
</html>
`

3
go.mod
View File

@ -41,6 +41,9 @@ require (
github.com/spf13/viper v1.0.2
github.com/stretchr/testify v1.2.1
github.com/ugorji/go v0.0.0-20180112141927-9831f2c3ac10 // indirect
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1
golang.org/x/crypto v0.0.0-20180330210355-12892e8c234f // indirect
golang.org/x/net v0.0.0-20180330215511-b68f30494add // indirect
golang.org/x/sys v0.0.0-20180329131831-378d26f46672 // indirect

6
go.sum
View File

@ -74,6 +74,12 @@ github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go v0.0.0-20180112141927-9831f2c3ac10 h1:4zp+5ElNBLy5qmaDFrbVDolQSOtPmquw+W6EMNEpi+k=
github.com/ugorji/go v0.0.0-20180112141927-9831f2c3ac10/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180330210355-12892e8c234f h1:EDv9U2dOjZ9sVn985FJw58XWqRwhtTnd0RxCfIzqKI8=
golang.org/x/crypto v0.0.0-20180330210355-12892e8c234f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20180330215511-b68f30494add h1:oGr9qHpQTQvl/BmeWw95ZrQKahW4qdIPUiGfQkJYDsA=

View File

@ -1,15 +1,67 @@
package main
import (
"flag"
"fmt"
"os"
"github.com/pterodactyl/wings/command"
"go.uber.org/zap"
)
var (
configPath string
debug bool
)
// Entrypoint for the Wings application. Configures the logger and checks any
// flags that were passed through in the boot arguments.
func main() {
if err := command.RootCommand.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
flag.StringVar(&configPath, "config", "config.yml", "set the location for the configuration file")
flag.BoolVar(&debug, "debug", false, "pass in order to run wings in debug mode")
flag.Parse()
printLogo()
if err := configureLogging(); err != nil {
panic(err)
}
if debug {
zap.S().Debugw("running in debug mode")
}
zap.S().Infof("using configuration file: %s", configPath)
}
// Configures the global logger for Zap so that we can call it from any location
// in the code without having to pass around a logger instance.
func configureLogging() error {
cfg := zap.NewProductionConfig()
if debug {
cfg = zap.NewDevelopmentConfig()
}
cfg.Encoding = "console"
cfg.OutputPaths = []string{
"stdout",
}
logger, err := cfg.Build()
if err != nil {
return err
}
zap.ReplaceGlobals(logger)
return nil
}
// Prints the wings logo, nothing special here!
func printLogo() {
fmt.Println()
fmt.Println(` ____`)
fmt.Println(`__ Pterodactyl _____/___/_______ _______ ______`)
fmt.Println(`\_____\ \/\/ / / / __ / ___/`)
fmt.Println(` \___\ / / / / /_/ /___ /`)
fmt.Println(` \___/\___/___/___/___/___ /______/`)
fmt.Println(` /_______/ v` + Version)
fmt.Println()
}