Initialize is an explicit init. Enables outside use of shock-server packages. Parses config and populates the conf variables.
()
| 107 | // of shock-server packages. Parses config and populates |
| 108 | // the conf variables. |
| 109 | func Initialize() (err error) { |
| 110 | |
| 111 | for i, elem := range os.Args { |
| 112 | if strings.HasPrefix(elem, "-conf") || strings.HasPrefix(elem, "--conf") { |
| 113 | parts := strings.SplitN(elem, "=", 2) |
| 114 | if len(parts) == 2 { |
| 115 | CONFIG_FILE = parts[1] |
| 116 | } else if i+1 < len(os.Args) { |
| 117 | CONFIG_FILE = os.Args[i+1] |
| 118 | } else { |
| 119 | return errors.New("parsing command options, missing conf file") |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | var c *config.Config = nil |
| 125 | if CONFIG_FILE != "" { |
| 126 | c, err = config.ReadDefault(CONFIG_FILE) |
| 127 | if err != nil { |
| 128 | return errors.New("error reading conf file: " + err.Error()) |
| 129 | } |
| 130 | fmt.Printf("read %s\n", CONFIG_FILE) |
| 131 | } else { |
| 132 | fmt.Printf("No config file specified.\n") |
| 133 | c = config.NewDefault() |
| 134 | } |
| 135 | |
| 136 | c_store, err := getConfiguration(c) // from config file and command line arguments |
| 137 | if err != nil { |
| 138 | return errors.New("error reading conf file: " + err.Error()) |
| 139 | } |
| 140 | |
| 141 | // ####### at this point configuration variables are set ######## |
| 142 | |
| 143 | err = parseConfiguration() |
| 144 | if err != nil { |
| 145 | return errors.New("error parsing conf file: " + err.Error()) |
| 146 | } |
| 147 | |
| 148 | if FAKE_VAR == false { |
| 149 | return errors.New("config was not parsed") |
| 150 | } |
| 151 | if PRINT_HELP || SHOW_HELP { |
| 152 | c_store.PrintHelp() |
| 153 | os.Exit(0) |
| 154 | } |
| 155 | if SHOW_VERSION { |
| 156 | fmt.Printf("Shock version: %s\n", VERSION) |
| 157 | os.Exit(0) |
| 158 | } |
| 159 | |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | // Bool is a convenience wrapper around strconv.ParseBool |
| 164 | func Bool(s string) bool { |
nothing calls this directly
no test coverage detected