All checks were successful
PR Check / check-and-test (pull_request) Successful in 11s
- Enhanced .goreleaser.yaml for improved build configuration, including static linking and ARM64 support. - Updated logging in root.go to include version date during startup. - Modified version.go to initialize and expose the build date alongside the version. - Adjusted version command output to display both version and date for better clarity.
114 lines
3.6 KiB
Go
114 lines
3.6 KiB
Go
// cmd/root.go
|
|
package cmd
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"s1d3sw1ped/SteamCache2/steamcache"
|
|
"s1d3sw1ped/SteamCache2/steamcache/logger"
|
|
"s1d3sw1ped/SteamCache2/version"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
threads int
|
|
|
|
memory string
|
|
disk string
|
|
diskpath string
|
|
upstream string
|
|
|
|
memoryGC string
|
|
diskGC string
|
|
|
|
logLevel string
|
|
logFormat string
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "SteamCache2",
|
|
Short: "SteamCache2 is a caching solution for Steam game updates and installations",
|
|
Long: `SteamCache2 is a caching solution designed to optimize the delivery of Steam game updates and installations.
|
|
It reduces bandwidth usage and speeds up the download process by caching game files locally.
|
|
This tool is particularly useful for environments with multiple Steam users, such as gaming cafes or households with multiple gamers.
|
|
By caching game files, SteamCache2 ensures that subsequent downloads of the same files are served from the local cache,
|
|
significantly improving download times and reducing the load on the internet connection.`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
// Configure logging
|
|
switch logLevel {
|
|
case "debug":
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
case "error":
|
|
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
|
case "info":
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
default:
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel) // Default to info level if not specified
|
|
}
|
|
var writer zerolog.ConsoleWriter
|
|
if logFormat == "json" {
|
|
writer = zerolog.ConsoleWriter{Out: os.Stderr, NoColor: true}
|
|
} else {
|
|
writer = zerolog.ConsoleWriter{Out: os.Stderr}
|
|
}
|
|
logger.Logger = zerolog.New(writer).With().Timestamp().Logger()
|
|
|
|
logger.Logger.Info().
|
|
Msg("SteamCache2 " + version.Version + " " + version.Date + " starting...")
|
|
|
|
address := ":80"
|
|
|
|
if runtime.GOMAXPROCS(-1) != threads {
|
|
runtime.GOMAXPROCS(threads)
|
|
logger.Logger.Info().
|
|
Int("threads", threads).
|
|
Msg("Maximum number of threads set")
|
|
}
|
|
|
|
sc := steamcache.New(
|
|
address,
|
|
memory,
|
|
disk,
|
|
diskpath,
|
|
upstream,
|
|
memoryGC,
|
|
diskGC,
|
|
)
|
|
|
|
logger.Logger.Info().
|
|
Msg("SteamCache2 " + version.Version + " started on " + address)
|
|
|
|
sc.Run()
|
|
|
|
logger.Logger.Info().Msg("SteamCache2 stopped")
|
|
os.Exit(0)
|
|
},
|
|
}
|
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
func Execute() {
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.Flags().IntVarP(&threads, "threads", "t", runtime.GOMAXPROCS(-1), "Number of worker threads to use for processing requests")
|
|
|
|
rootCmd.Flags().StringVarP(&memory, "memory", "m", "0", "The size of the memory cache")
|
|
rootCmd.Flags().StringVarP(&disk, "disk", "d", "0", "The size of the disk cache")
|
|
rootCmd.Flags().StringVarP(&diskpath, "disk-path", "p", "", "The path to the disk cache")
|
|
|
|
rootCmd.Flags().StringVarP(&upstream, "upstream", "u", "", "The upstream server to proxy requests overrides the host header from the client but forwards the original host header to the upstream server")
|
|
|
|
rootCmd.Flags().StringVarP(&memoryGC, "memory-gc", "", "lru", "Memory cache GC algorithm: lru, lfu, fifo, largest, smallest, hybrid")
|
|
rootCmd.Flags().StringVarP(&diskGC, "disk-gc", "", "lru", "Disk cache GC algorithm: lru, lfu, fifo, largest, smallest, hybrid")
|
|
|
|
rootCmd.Flags().StringVarP(&logLevel, "log-level", "l", "info", "Logging level: debug, info, error")
|
|
rootCmd.Flags().StringVarP(&logFormat, "log-format", "f", "console", "Logging format: json, console")
|
|
}
|