diff --git a/CHANGELOG.md b/CHANGELOG.md index b626c89..7eaa4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## v0.0.7 + +[release](https://github.com/dyweb/gommon/releases/tag/0.0.7) + +- deprecated config v1, move it to legacy folder +- move cast into util + +## v0.0.6 + +[release](https://github.com/dyweb/gommon/releases/tag/0.0.6) + +- improve doc, fix typo + ## v0.0.5 [release](https://github.com/dyweb/gommon/releases/tag/0.0.5) diff --git a/Makefile b/Makefile index 3937241..810bc5c 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ -PKGS=./cast/... ./config/... ./errors/... ./generator/... ./log/... ./noodle/... ./requests/... ./structure/... ./util/... -PKGST=./cast ./cmd ./config ./errors ./generator ./log ./noodle ./requests ./structure ./util -VERSION = 0.0.1 +PKGS=./errors/... ./generator/... ./log/... ./noodle/... ./requests/... ./structure/... ./util/... +PKGST=./cmd ./errors ./generator ./log ./noodle ./requests ./structure ./util +VERSION = 0.0.7 BUILD_COMMIT = $(shell git rev-parse HEAD) BUILD_TIME = $(shell date +%Y-%m-%dT%H:%M:%S%z) CURRENT_USER = $(USER) FLAGS = -X main.version=$(VERSION) -X main.commit=$(BUILD_COMMIT) -X main.buildTime=$(BUILD_TIME) -X main.buildUser=$(CURRENT_USER) +# TODO: define help messages + .PHONY: install install: go install -ldflags "$(FLAGS)" ./cmd/gommon @@ -52,7 +54,7 @@ update-dep: #--- docker ---# .PHONY: docker-test docker-test: - docker-compose -f scripts/docker-compose.yml run --rm golang1.9 + docker-compose -f scripts/docker-compose.yml run --rm golang1.10 docker-compose -f scripts/docker-compose.yml run --rm golanglatest .PHONY: docker-remove-all-containers diff --git a/README.md b/README.md index 3db554a..a2e2981 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ Gommon is a collection of common util libraries written in Go. It has the following components: -- [config](config) A YAML config reader with template support - [errors](errors) Typed error with context, multi error - [generator](generator) Render go template, generate methods for logger interface based on `gommon.yml` - [log](log) A Javaish logger for Go, application can set level for their dependencies based on package, struct @@ -24,6 +23,7 @@ It has the following components: Legacy +- [config v1](config) A YAML config reader with template support - [log v1](legacy/log) A logrus like structured logger - [Runner](legacy/runner) A os/exec wrapper @@ -49,38 +49,6 @@ Removed - `dep ensure` - `make test` -### Roadmap - -0.0.7 - -- [x] test coverage for multiple packages -- [ ] explain internals of some implementation -- [ ] start documenting the style for writing gommon itself, lib using gommon, app using gommon/lib using gommon -- [ ] improve Makefile and dockerized build & test - -0.0.8 - -- [ ] more complex error interface, error code -- [ ] organized error types -- [ ] extension for collecting errors using third party services -- [ ] init go mod support, not sure if it will be compatible with dep - -0.0.9 - -- [ ] tree of loggers in use -- [ ] benchmark against other loggers -- [ ] support better logging for errors - -0.0.10 - -- [ ] simplify config package, no more template and get value by string path -- [ ] move cast into util - -0.0.11 - -- [ ] httputil package, merge part of current requests package unix domain sock etc. -- [ ] requests, download and upload file, a curl like example - ## License MIT diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..0d0981f --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,26 @@ +# Roadmap + +## 0.0.8 + +- [x] test coverage for multiple packages +- [ ] explain internals of some implementation +- [ ] start documenting the style for writing gommon itself, lib using gommon, app using gommon/lib using gommon +- [ ] improve Makefile and dockerized build & test + +## 0.0.9 + +- [ ] more complex error interface, error code +- [ ] organized error types +- [ ] extension for collecting errors using third party services +- [ ] init go mod support, not sure if it will be compatible with dep + +## 0.0.10 + +- [ ] tree of loggers in use +- [ ] benchmark against other loggers +- [ ] support better logging for errors + +## 0.0.11 + +- [ ] httputil package, merge part of current requests package unix domain sock etc. +- [ ] requests, download and upload file, a curl like example \ No newline at end of file diff --git a/directory.md b/directory.md new file mode 100644 index 0000000..72f9eaa --- /dev/null +++ b/directory.md @@ -0,0 +1,21 @@ +# Directory + +## Project Layout + +- [cmd/gommon](cmd/gommon) the command line application +- [doc](doc) documentation +- [errors](errors) error wrapping and multi error +- [generator](generator) generating interface methods, render go template, protobuf etc. +- [legacy](legacy) legacy code base +- [noodle](noodle) embed static assets for go binary with .ignore file support +- [playground](playground) test library and replay issues +- [requests](requests) ~~http util~~ +- [scripts](scripts) test scripts +- [structure](structure) data structure +- [util](util) small packages + +## Package Layout + +- README.md +- doc + - history.md verbose log about the evolve of the package, important decision made and the reason behind it \ No newline at end of file diff --git a/doc/README.md b/doc/README.md index f66c06d..a11d6bd 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,2 +1,7 @@ # Gommon Documentation +- Style + - [General](style.md) + - [Application using Gommon](style-application.md) + - [Library using Gommon](style-library.md) + - [Writing Gommon](style-gommon.md) diff --git a/doc/directory.md b/doc/directory.md deleted file mode 100644 index 33dc528..0000000 --- a/doc/directory.md +++ /dev/null @@ -1,15 +0,0 @@ -# Directory - -- [cmd/gommon](../cmd/gommon) the command line application -- [cast](../cast) converter needed for config -- [config](../config) config file reader -- [doc](.) documentation -- [errors](../errors) error wrapping and multi error -- [generator](../generator) generating interface methods, render go template, protobuf etc. -- [legacy](../legacy) legacy code base -- [noodle](../noodle) embed static assets for go binary with .ignore file support -- [playground](../playground) test library and replay issues -- [requests](../requests) http util -- [scripts](../scripts) test scripts -- [structure](../structure) data structure -- [util](../util) util packages for public use, they are too small to be top level package \ No newline at end of file diff --git a/doc/style-gommon.md b/doc/style-gommon.md new file mode 100644 index 0000000..e312cbc --- /dev/null +++ b/doc/style-gommon.md @@ -0,0 +1,18 @@ +# Gommon Style + +Style for writing gommon itself, see [library](style-library.md) and [application](style-application.md) for using gommon. + +## Folder structure + +see [directory](../directory.md) + +- [ ] TODO: add how to structure file inside a package etc. + +## Documentation + +MUST cover the following + +- [ ] convention, i.e. variable names, error handling etc. +- [ ] internal, a basic walk through of import parts +- define canonical import path in `pkg.go` https://golang.org/doc/go1.4#canonicalimports +- [ ] survey diff --git a/doc/style.md b/doc/style.md index 69856ee..5b21074 100644 --- a/doc/style.md +++ b/doc/style.md @@ -1,20 +1,4 @@ # Coding Style -Style for writing gommon itself, see [library](style-library.md) and [application](style-application.md) for using gommon. - -## Folder structure - -see [directory](directory.md) - -- [ ] TODO: add how to structure file inside a package etc. - -## Documentation - -MUST cover the following - -- [ ] convention, i.e. variable names, error handling etc. -- [ ] internal, a basic walk through of import parts -- define canonical import path in `pkg.go` https://golang.org/doc/go1.4#canonicalimports -- [ ] survey - +General coding style diff --git a/generator/generate.go b/generator/generate.go index 6e5a07f..817a4fd 100644 --- a/generator/generate.go +++ b/generator/generate.go @@ -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" ) @@ -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 { diff --git a/config/README.md b/legacy/config/README.md similarity index 100% rename from config/README.md rename to legacy/config/README.md diff --git a/config/gommon.yml b/legacy/config/gommon.yml similarity index 100% rename from config/gommon.yml rename to legacy/config/gommon.yml diff --git a/config/gommon_generated.go b/legacy/config/gommon_generated.go similarity index 100% rename from config/gommon_generated.go rename to legacy/config/gommon_generated.go diff --git a/config/pkg.go b/legacy/config/pkg.go similarity index 87% rename from config/pkg.go rename to legacy/config/pkg.go index c437621..8c131db 100644 --- a/config/pkg.go +++ b/legacy/config/pkg.go @@ -1,5 +1,5 @@ // Package config supports go text/template, environment and self defined variables -package config // import "github.com/dyweb/gommon/config" +package config import ( "github.com/dyweb/gommon/util/logutil" diff --git a/config/testdata/multi_doc_multi_vars.yml b/legacy/config/testdata/multi_doc_multi_vars.yml similarity index 100% rename from config/testdata/multi_doc_multi_vars.yml rename to legacy/config/testdata/multi_doc_multi_vars.yml diff --git a/config/testdata/multi_doc_single_vars.yml b/legacy/config/testdata/multi_doc_single_vars.yml similarity index 100% rename from config/testdata/multi_doc_single_vars.yml rename to legacy/config/testdata/multi_doc_single_vars.yml diff --git a/config/testdata/single_doc_no_vars.yml b/legacy/config/testdata/single_doc_no_vars.yml similarity index 100% rename from config/testdata/single_doc_no_vars.yml rename to legacy/config/testdata/single_doc_no_vars.yml diff --git a/config/testdata/single_doc_vars.yml b/legacy/config/testdata/single_doc_vars.yml similarity index 100% rename from config/testdata/single_doc_vars.yml rename to legacy/config/testdata/single_doc_vars.yml diff --git a/config/testdata/structured.yml b/legacy/config/testdata/structured.yml similarity index 100% rename from config/testdata/structured.yml rename to legacy/config/testdata/structured.yml diff --git a/config/yaml.go b/legacy/config/yaml.go similarity index 99% rename from config/yaml.go rename to legacy/config/yaml.go index dbe1ec4..bfaca9f 100644 --- a/config/yaml.go +++ b/legacy/config/yaml.go @@ -12,10 +12,10 @@ import ( "gopkg.in/yaml.v2" - "github.com/dyweb/gommon/cast" "github.com/dyweb/gommon/errors" dlog "github.com/dyweb/gommon/log" "github.com/dyweb/gommon/util" + "github.com/dyweb/gommon/util/cast" ) // YAMLConfig is a thread safe struct for parse YAML file and get value diff --git a/config/yaml_test.go b/legacy/config/yaml_test.go similarity index 100% rename from config/yaml_test.go rename to legacy/config/yaml_test.go diff --git a/requests/doc/history.md b/requests/doc/history.md new file mode 100644 index 0000000..e69de29 diff --git a/scripts/docker-compose.yml b/scripts/docker-compose.yml index d23876f..4ba56ba 100644 --- a/scripts/docker-compose.yml +++ b/scripts/docker-compose.yml @@ -2,7 +2,7 @@ version: '2' services: # FIXME: there should be a way of reusing command, I am just copying stuff around, there is extend keyword, but removed in v3 golang1.9: - image: golang:1.9 + image: golang:1.10 command: go test -v -cover ./cast/... ./config/... ./generator/... ./log/... ./playground/... ./requests/... ./structure/... ./util/... working_dir: /go/src/github.com/dyweb/gommon volumes: diff --git a/cast/README.md b/util/cast/README.md similarity index 100% rename from cast/README.md rename to util/cast/README.md diff --git a/cast/cast.go b/util/cast/cast.go similarity index 100% rename from cast/cast.go rename to util/cast/cast.go diff --git a/cast/cast_test.go b/util/cast/cast_test.go similarity index 100% rename from cast/cast_test.go rename to util/cast/cast_test.go diff --git a/cast/pkg.go b/util/cast/pkg.go similarity index 69% rename from cast/pkg.go rename to util/cast/pkg.go index 5da9965..4484829 100644 --- a/cast/pkg.go +++ b/util/cast/pkg.go @@ -1,4 +1,4 @@ // Package cast convert types safely and drop incompatible types during conversion // // it is inspired by https://github.com/spf13/cast -package cast // import "github.com/dyweb/gommon/cast" +package cast // import "github.com/dyweb/gommon/util/cast"