Skip to content

Commit

Permalink
[config] Deprecated v1
Browse files Browse the repository at this point in the history
- the original aim of config package is to support template inside YAML,
kind of like what Ansible is doing, it was invented for Xephon-B.
We first use a non standard template engine (I even forgot its name
now), and then switched to using standard library's `text/template`,
this syntax is a bit awkward when for loop is used, it's ok when using
things like `{{env KEY_NAME}}`
- however, when not writing bechmark config, the template feature is not
that useful, normally I just unmarshal the yaml to struct and that's it
- I am not sure what v2 of config would be, maybe support more format or
enforce the struct/interface of config struct. (It used to have a
validation interface that check the config and its fields manually)
or just allow downloading config file from the wire
  • Loading branch information
at15 committed Aug 8, 2018
1 parent ccdcbe6 commit 5ff6087
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKGS=./config/... ./errors/... ./generator/... ./log/... ./noodle/... ./requests/... ./structure/... ./util/...
PKGST=./cmd ./config ./errors ./generator ./log ./noodle ./requests ./structure ./util
PKGS=./errors/... ./generator/... ./log/... ./noodle/... ./requests/... ./structure/... ./util/...
PKGST=./cmd ./errors ./generator ./log ./noodle ./requests ./structure ./util
VERSION = 0.0.1
BUILD_COMMIT = $(shell git rev-parse HEAD)
BUILD_TIME = $(shell date +%Y-%m-%dT%H:%M:%S%z)
Expand Down
11 changes: 8 additions & 3 deletions generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"os"
"path/filepath"
"strings"
"io/ioutil"

"gopkg.in/yaml.v2"

"github.com/dyweb/gommon/config"
"github.com/dyweb/gommon/errors"
"github.com/dyweb/gommon/util/fsutil"
)
Expand Down Expand Up @@ -37,10 +39,13 @@ func GenerateSingle(file string) error {
segments := strings.Split(dir, string(os.PathSeparator))
pkg := segments[len(segments)-1]
cfg := NewConfig(pkg, file)
// TODO: config may remove LoadYAMLAsStruct in the future
if err = config.LoadYAMLAsStruct(file, &cfg); err != nil {
b, err := ioutil.ReadFile(file)
if err != nil {
return errors.Wrap(err, "can't read config file")
}
if err = yaml.Unmarshal(b, &cfg); err != nil {
return errors.Wrap(err, "can't decode config file as YAML")
}

// gommon logger
if rendered, err = cfg.RenderGommon(); err != nil {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5ff6087

Please sign in to comment.