Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
[[constraint]]
name = "github.com/rakyll/statik"
version = "0.1.1"

[[constraint]]
name = "github.com/ghodss/yaml"
version = "1.0.0"
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
func init() {
rootCmd.AddCommand(serveCmd)

serveCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "config.json", "Path to the configuration filename")
serveCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "api2html.conf", "Path to the configuration filename")
serveCmd.PersistentFlags().BoolVarP(&devel, "devel", "d", false, "Enable the devel")
serveCmd.PersistentFlags().IntVarP(&port, "port", "p", 8080, "Listen port")
}
Expand Down
25 changes: 22 additions & 3 deletions engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ package engine

import (
"encoding/json"
"bytes"
"io"
"os"

"github.com/ghodss/yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package github.com/ghodss/yaml should be added to the Gopkg.toml file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


)


// ParseConfigFromFile creates a Config with the contents of the received filepath
func ParseConfigFromFile(path string) (Config, error) {
configFile, err := os.Open(path)
Expand All @@ -20,10 +25,24 @@ func ParseConfigFromFile(path string) (Config, error) {
// ParseConfig parses the content of the reader into a Config
func ParseConfig(r io.Reader) (Config, error) {
var cfg Config
err := json.NewDecoder(r).Decode(&cfg)
if err != nil {
return cfg, err
var buf bytes.Buffer

buf.ReadFrom(r)
cb := buf.Bytes()

switch {
case bytes.HasPrefix(bytes.TrimSpace(cb), []byte("{")):
err := json.Unmarshal(cb, &cfg)
if err != nil {
return cfg, err
}
default:
err := yaml.Unmarshal(cb, &cfg)
if err != nil {
return cfg, err
}
}

for p, page := range cfg.Pages {
if len(page.Extra) == 0 {
cfg.Pages[p].Extra = cfg.Extra
Expand Down