Introduction
Introduction Statistics Contact Development Disclaimer Help
config.go - fingered - Fingerd protocol daemon, allowing custom responses.
git clone git://jay.scot/fingered
Log
Files
Refs
README
LICENSE
---
config.go (1302B)
---
1 package config
2
3 import (
4 "flag"
5 "fmt"
6 "log"
7 )
8
9 const (
10 maxPort = 65535
11 minPort = 1
12 minThreads = 1
13 )
14
15 type Config struct {
16 Threads int
17 Port int
18 Dir string
19 Index string
20 }
21
22 func defaultConfig() Config {
23 return Config{
24 Threads: 10,
25 Port: 79,
26 Dir: "/srv/fingered",
27 Index: "default",
28 }
29 }
30
31 func displayUsage() {
32 flagSet := flag.CommandLine
33 flag.Usage = func() {
34 fmt.Printf("Usage:\n")
35 flagSet.VisitAll(func(flag *flag.Flag) {
36 fmt.Printf("\t-%s: %s (default: %s)\n", flag.Nam…
37 })
38 }
39 }
40
41 func addFlags(cfg *Config) {
42 flag.IntVar(&cfg.Threads, "t", cfg.Threads, "Number of worker th…
43 flag.IntVar(&cfg.Port, "p", cfg.Port, "Port for incoming connect…
44 flag.StringVar(&cfg.Dir, "d", cfg.Dir, "Directory containing use…
45 flag.StringVar(&cfg.Index, "f", cfg.Index, "Filename for empty r…
46 }
47
48 func ParseFlags() Config {
49 cfg := defaultConfig()
50 addFlags(&cfg)
51 displayUsage()
52 flag.Parse()
53
54 if cfg.Threads < minThreads {
55 log.Fatal("Invalid number of threads: must be greater th…
56 }
57
58 if cfg.Port < minPort || cfg.Port > maxPort {
59 log.Fatal("Invalid port value: must be between 1 and 655…
60 }
61
62 if cfg.Dir == "" {
63 log.Fatal("Invalid path value: directory cannot be empty…
64 }
65
66 return cfg
67 }
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.