Add empty server implementation
Change-Id: Ieeee07a18d91d0c429a15c5eb0f1f96aed9393c6
diff --git a/server/cmd/commands/root.go b/server/cmd/commands/root.go
new file mode 100644
index 0000000..088e7ff
--- /dev/null
+++ b/server/cmd/commands/root.go
@@ -0,0 +1,62 @@
+package commands
+
+import (
+ "log/slog"
+ "os"
+ "os/signal"
+ "syscall"
+
+ "github.com/iomodo/staff/server"
+ "github.com/spf13/cobra"
+)
+
+// Command is an abstraction of the cobra Command
+type Command = cobra.Command
+
+// Run function starts the application
+func Run(args []string) error {
+ rootCmd.SetArgs(args)
+ return rootCmd.Execute()
+}
+
+// rootCmd is a command to run the server.
+var rootCmd = &cobra.Command{
+ Use: "server",
+ Short: "Runs a server",
+ Long: `Runs a server. Killing the process will stop the server`,
+ RunE: serverCmdF,
+}
+
+func serverCmdF(_ *cobra.Command, _ []string) error {
+ srv, err := runServer()
+ if err != nil {
+ return err
+ }
+ defer srv.Shutdown()
+
+ // wait for kill signal before attempting to gracefully shutdown
+ // the running service
+ interruptChan := make(chan os.Signal, 1)
+ signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+ <-interruptChan
+ return nil
+}
+
+func runServer() (*server.Server, error) {
+ logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
+ Level: slog.LevelDebug,
+ }))
+
+ srv, err := server.NewServer(logger)
+ if err != nil {
+ logger.Error(err.Error())
+ return nil, err
+ }
+
+ serverErr := srv.Start()
+ if serverErr != nil {
+ logger.Error(serverErr.Error())
+ return nil, serverErr
+ }
+ return srv, nil
+}
diff --git a/server/cmd/main.go b/server/cmd/main.go
new file mode 100644
index 0000000..4316dfd
--- /dev/null
+++ b/server/cmd/main.go
@@ -0,0 +1,13 @@
+package main
+
+import (
+ "os"
+
+ "github.com/iomodo/staff/cmd/commands"
+)
+
+func main() {
+ if err := commands.Run(os.Args[1:]); err != nil {
+ os.Exit(1)
+ }
+}
diff --git a/server/go.mod b/server/go.mod
new file mode 100644
index 0000000..621072a
--- /dev/null
+++ b/server/go.mod
@@ -0,0 +1,13 @@
+module github.com/iomodo/staff
+
+go 1.24.4
+
+require (
+ github.com/joho/godotenv v1.5.1
+ github.com/spf13/cobra v1.9.1
+)
+
+require (
+ github.com/inconshreveable/mousetrap v1.1.0 // indirect
+ github.com/spf13/pflag v1.0.6 // indirect
+)
diff --git a/server/go.sum b/server/go.sum
new file mode 100644
index 0000000..d2f5463
--- /dev/null
+++ b/server/go.sum
@@ -0,0 +1,12 @@
+github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
+github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
+github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
+github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
+github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
+github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
+github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
+github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
+github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/server/server/server.go b/server/server/server.go
new file mode 100644
index 0000000..9f95f10
--- /dev/null
+++ b/server/server/server.go
@@ -0,0 +1,38 @@
+package server
+
+import (
+ "log/slog"
+ "os"
+
+ "github.com/joho/godotenv"
+)
+
+// Server type defines application global state
+type Server struct {
+ logger *slog.Logger
+}
+
+// NewServer creates new Server
+func NewServer(logger *slog.Logger) (*Server, error) {
+ _ = godotenv.Load()
+
+ a := &Server{
+ logger: logger,
+ }
+
+ pwd, _ := os.Getwd()
+ a.logger.Info("Current working directory", slog.String("path", pwd))
+ return a, nil
+}
+
+// Start method starts an app
+func (a *Server) Start() error {
+ a.logger.Info("Server is starting...")
+ return nil
+}
+
+// Shutdown method shuts server down
+func (a *Server) Shutdown() {
+ a.logger.Info("Stoping Server...")
+ a.logger.Info("Server stopped")
+}