mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
cmd/ctrld: add default value and CLI flag for cache size
This commit is contained in:
committed by
Cuong Manh Le
parent
b93970ccfd
commit
e6d77e2586
+12
-2
@@ -42,7 +42,7 @@ func initCLI() {
|
|||||||
`verbose log output, "-v" means query logging enabled, "-vv" means debug level logging enabled`,
|
`verbose log output, "-v" means query logging enabled, "-vv" means debug level logging enabled`,
|
||||||
)
|
)
|
||||||
|
|
||||||
basicModeFlags := []string{"listen", "primary_upstream", "secondary_upstream", "domains", "log"}
|
basicModeFlags := []string{"listen", "primary_upstream", "secondary_upstream", "domains", "log", "cache_size"}
|
||||||
runCmd := &cobra.Command{
|
runCmd := &cobra.Command{
|
||||||
Use: "run",
|
Use: "run",
|
||||||
Short: "Run the DNS proxy server",
|
Short: "Run the DNS proxy server",
|
||||||
@@ -73,6 +73,7 @@ func initCLI() {
|
|||||||
log.Fatalf("invalid config: %v", err)
|
log.Fatalf("invalid config: %v", err)
|
||||||
}
|
}
|
||||||
initLogging()
|
initLogging()
|
||||||
|
initCache()
|
||||||
if daemon {
|
if daemon {
|
||||||
exe, err := os.Executable()
|
exe, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -121,6 +122,7 @@ func initCLI() {
|
|||||||
runCmd.Flags().StringVarP(&secondaryUpstream, "secondary_upstream", "", "", "secondary upstream endpoint")
|
runCmd.Flags().StringVarP(&secondaryUpstream, "secondary_upstream", "", "", "secondary upstream endpoint")
|
||||||
runCmd.Flags().StringSliceVarP(&domains, "domains", "", nil, "list of domain to apply in a split DNS policy")
|
runCmd.Flags().StringSliceVarP(&domains, "domains", "", nil, "list of domain to apply in a split DNS policy")
|
||||||
runCmd.Flags().StringVarP(&logPath, "log", "", "", "path to log file")
|
runCmd.Flags().StringVarP(&logPath, "log", "", "", "path to log file")
|
||||||
|
runCmd.Flags().IntVarP(&cacheSize, "cache_size", "", 0, "Enable cache with size items")
|
||||||
|
|
||||||
rootCmd.AddCommand(runCmd)
|
rootCmd.AddCommand(runCmd)
|
||||||
|
|
||||||
@@ -211,7 +213,15 @@ func processNoConfigFlags(noConfigStart bool) {
|
|||||||
}
|
}
|
||||||
v.Set("upstream", upstream)
|
v.Set("upstream", upstream)
|
||||||
|
|
||||||
|
sc := ctrld.ServiceConfig{}
|
||||||
if logPath != "" {
|
if logPath != "" {
|
||||||
v.Set("service", ctrld.ServiceConfig{LogLevel: "debug", LogPath: logPath})
|
sc.LogLevel = "debug"
|
||||||
|
sc.LogPath = logPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cacheSize != 0 {
|
||||||
|
sc.CacheEnable = true
|
||||||
|
sc.CacheSize = cacheSize
|
||||||
|
}
|
||||||
|
v.Set("service", sc)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ var (
|
|||||||
secondaryUpstream string
|
secondaryUpstream string
|
||||||
domains []string
|
domains []string
|
||||||
logPath string
|
logPath string
|
||||||
|
cacheSize int
|
||||||
cfg ctrld.Config
|
cfg ctrld.Config
|
||||||
verbose int
|
verbose int
|
||||||
|
|
||||||
@@ -75,3 +76,12 @@ func initLogging() {
|
|||||||
}
|
}
|
||||||
zerolog.SetGlobalLevel(level)
|
zerolog.SetGlobalLevel(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initCache() {
|
||||||
|
if !cfg.Service.CacheEnable {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cfg.Service.CacheSize == 0 {
|
||||||
|
cfg.Service.CacheSize = 4096
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user