Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing default admin listen address
Improve handling of environment based defaults in packages Improve documentation Fixes #307
- Loading branch information
Showing
19 changed files
with
339 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright 2015-2016 Jason Woods. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/fatih/camelcase" | ||
) | ||
|
||
const platformHeader = `// THIS IS A GO GENERATED FILE | ||
/* | ||
* Copyright 2014-2016 Jason Woods. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
` | ||
|
||
// Generate platform.go | ||
// It should contain platform specific defaults, such as the default | ||
// configuration location and persist directory. | ||
// Useful for package maintainers | ||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatalf("Usage: go run <path-to-lc-lib>/config/generate.go <package-name> <configs>...") | ||
} | ||
|
||
platformFile := platformHeader | ||
platformFile += fmt.Sprintf("package %s\n\n", os.Args[1]) | ||
|
||
config := parseConfigArgs(os.Args[2:]) | ||
platformFile += generatePackageImports(config) | ||
platformFile += generateInit(config) | ||
|
||
platformFileBytes := []byte(os.ExpandEnv(platformFile)) | ||
if err := ioutil.WriteFile("platform.go", platformFileBytes, 0644); err != nil { | ||
log.Fatalf("Failed to write platform.go: %s", err) | ||
} | ||
} | ||
|
||
func parseConfigArgs(args []string) map[string][]string { | ||
config := map[string][]string{} | ||
|
||
for _, v := range args { | ||
envSplit := strings.SplitN(v, ".", 2) | ||
if len(envSplit) != 2 { | ||
log.Fatalf("Config variable needs package specifier: %s", v) | ||
} | ||
|
||
config[envSplit[0]] = append(config[envSplit[0]], envSplit[1]) | ||
} | ||
|
||
return config | ||
} | ||
|
||
func generatePackageImports(config map[string][]string) string { | ||
platformFile := "import (\n" | ||
for pkg := range config { | ||
platformFile += fmt.Sprintf("\t\"github.com/driskell/log-courier/lc-lib/%s\"\n", pkg) | ||
} | ||
platformFile += ")\n\n" | ||
return platformFile | ||
} | ||
|
||
func generateInit(config map[string][]string) string { | ||
first := true | ||
platformFile := "func init() {\n" | ||
for pkg, nameArr := range config { | ||
for _, name := range nameArr { | ||
if !first { | ||
platformFile += "\n" | ||
} else { | ||
first = false | ||
} | ||
platformFile += generateInitSegment(pkg, name) | ||
} | ||
} | ||
platformFile += "}\n" | ||
return platformFile | ||
} | ||
|
||
func generateInitSegment(pkg, name string) string { | ||
envArr := camelcase.Split(name) | ||
for i := range envArr { | ||
envArr[i] = strings.ToUpper(envArr[i]) | ||
} | ||
|
||
envName := "LC_" + strings.Join(envArr, "_") | ||
platformFile := fmt.Sprintf("\t// %s\n", envName) | ||
platformFile += fmt.Sprintf("\t%s.%s = \"${%s}\"\n", pkg, name, envName) | ||
return platformFile | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.