add project first skeleton
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,7 +1,7 @@
|
|||||||
# Makefile
|
# Makefile
|
||||||
|
|
||||||
NAME = tsctl
|
NAME = tsctl
|
||||||
ENTRY = ./cmd/$(NAME)/main.go
|
ENTRY = ./main.go
|
||||||
BIN_DIR = bin
|
BIN_DIR = bin
|
||||||
BINARY = ${BIN_DIR}/$(NAME)
|
BINARY = ${BIN_DIR}/$(NAME)
|
||||||
CHECK_LINTER = command -v golangci-lint >/dev/null 2>&1
|
CHECK_LINTER = command -v golangci-lint >/dev/null 2>&1
|
||||||
|
|||||||
17
cmd/root.go
Normal file
17
cmd/root.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "tsctl",
|
||||||
|
Short: "Tool for managing TriggerSmith",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func Execute() error {
|
||||||
|
return rootCmd.Execute()
|
||||||
|
}
|
||||||
41
cmd/serve.go
Normal file
41
cmd/serve.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"git.oblat.lv/alex/triggerssmith/internal/config"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var opts = struct {
|
||||||
|
ConfigPath *string
|
||||||
|
Debug *bool
|
||||||
|
}{}
|
||||||
|
|
||||||
|
|
||||||
|
var serveCmd = &cobra.Command{
|
||||||
|
Use: "serve",
|
||||||
|
Short: "Start the server",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if *opts.Debug {
|
||||||
|
slog.SetDefault(slog.New(slog.NewTextHandler(cmd.OutOrStdout(), &slog.HandlerOptions{Level: slog.LevelDebug})))
|
||||||
|
} else {
|
||||||
|
slog.SetDefault(slog.New(slog.NewTextHandler(cmd.OutOrStdout(), &slog.HandlerOptions{Level: slog.LevelInfo})))
|
||||||
|
}
|
||||||
|
slog.Debug("Starting server")
|
||||||
|
slog.Debug("Reading configuration", slog.String("path", *opts.ConfigPath))
|
||||||
|
config, err := config.LoadConfig(*opts.ConfigPath)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to load configuration", slog.String("path", *opts.ConfigPath), slog.String("error", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
slog.Debug("Configuration loaded", slog.Any("config", config))
|
||||||
|
slog.Info("Server started", slog.Int("port", config.Server.Port), slog.String("address", config.Server.Addr))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
opts.Debug = serveCmd.Flags().BoolP("debug", "d", false, "Enable debug logs")
|
||||||
|
opts.ConfigPath = serveCmd.Flags().StringP("config", "c", "config.yaml", "Path to configuration file")
|
||||||
|
rootCmd.AddCommand(serveCmd)
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package tsctl
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("tsctl main function")
|
|
||||||
}
|
|
||||||
6
internal/app/app.go
Normal file
6
internal/app/app.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
// Application state and configurations can be added here
|
||||||
|
}
|
||||||
9
internal/app/errors.go
Normal file
9
internal/app/errors.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNilPointerWarn = errors.New("nil pointer dereference warning")
|
||||||
|
)
|
||||||
26
internal/config/config.go
Normal file
26
internal/config/config.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/akyaiy/GSfass/core/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServerConfig struct {
|
||||||
|
Port int `mapstructure:"port"`
|
||||||
|
Addr string `mapstructure:"address"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Server ServerConfig `mapstructure:"server"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadConfig(path string) (*Config, error) {
|
||||||
|
var cfg Config
|
||||||
|
err := config.Read().Config().FilePath(path).SetBy(&cfg).SetDefaults(map[string]any{
|
||||||
|
"server.port": 8080,
|
||||||
|
"server.address": "127.0.0.0",
|
||||||
|
}).End()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user