Skip to content

Commit

Permalink
Merge pull request #111 from dyweb/log/simplify-registry
Browse files Browse the repository at this point in the history
[log] Fix #110 simplify log registry
  • Loading branch information
at15 authored Apr 28, 2019
2 parents eccec10 + 39b9fe5 commit 3c94dcd
Show file tree
Hide file tree
Showing 107 changed files with 558 additions and 3,481 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This Dockerfile is a demo of using go-dev to build a go binary using multi stage build
# It is based on
# https://docs.docker.com/v17.09/engine/userguide/eng-image/dockerfile_best-practices/#use-multi-stage-builds
FROM dyweb/go-dev:1.11.4 as builder
#
# The builder-image go-dev can be found in hack/go-dev
# Versions can be found on https://hub.docker.com/r/dyweb/go-dev/tags
FROM dyweb/go-dev:1.12.4 as builder

LABEL maintainer="[email protected]"

Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ test unit test
generate generate code using gommon
loc lines of code (cloc required, brew install cloc)

Dev first time:
dep-install install dependencies based on lock file
dep-update update dependency based on spec and code

Build:
install install all binaries under ./cmd to $$GOPATH/bin
build compile all binary to ./build for current platform
Expand All @@ -37,8 +33,8 @@ help:

GO = GO111MODULE=on go
# -- build vars ---
PKGS =./errors/... ./generator/... ./log/... ./noodle/... ./structure/... ./util/...
PKGST =./cmd ./errors ./generator ./log ./noodle ./structure ./util
PKGS =./errors/... ./generator/... ./log/... ./noodle/... ./util/...
PKGST =./cmd ./errors ./generator ./log ./noodle ./util
VERSION = 0.0.10
BUILD_COMMIT := $(shell git rev-parse HEAD)
BUILD_TIME := $(shell date +%Y-%m-%dT%H:%M:%S%z)
Expand Down
37 changes: 8 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,21 @@

Gommon is a collection of common util libraries written in Go.

It has the following components:

- [errors](errors) error wrapping, inspection, multi error (error list), common error types
- [log](log) fine grained level control and reasonable performance
- [log](log) per package logger with [reasonable performance](log/_benchmarks/README.md)
- [noodle](noodle) embed static assets for web application with `.noodleignore` support
- [generator](generator) render go template, generate methods for logger interface based on `gommon.yml`
- [structure](structure) data structure like Set etc. to go
- [util](util) small utils over standard libraries utils

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
- [requests](requests) A pythonic wrapper for `net/http`, HTTP for Gopher

## Dependencies

Currently we only have one non standard library dependencies (cmd and examples are not considered), see [Gopkg.lock](Gopkg.lock)

- [go-yaml/yaml](https://github.com/go-yaml/yaml) for read config written in YAML
- we don't need most feature of YAML, and want to have access to the parser directly to report which line has incorrect semantic (after checking it in application).
- might write one in [ANTLR](https://github.com/antlr/antlr4)
- we also have a DSL work in progress [RCL: Reika Configuration Language](https://github.com/at15/reika/issues/49), which is like [HCL](https://github.com/hashicorp/hcl2)

Removed
- [util](util) wrappers for standard libraries

- [pkg/errors](https://github.com/pkg/errors) for including context in error, removed in [#59](https://github.com/dyweb/gommon/pull/59)
replaced by `gommon/errors`
It has little third party dependencies, only [go-yaml/yaml](https://github.com/go-yaml/yaml) in [util/cast](util/cast),
[go-shellquote](github.com/kballard/go-shellquote) in [generator](generator),
other dependencies like cobra are only for cli, see [go.mod](go.mod).

## Development

- install go https://golang.org/
- install dep https://github.com/golang/dep
- `make dep-install`
- `make test`
- requires go1.12+. go1.11.x should work as well, the Makefile set `GO111MODULE=on` so you can use in GOPATH
- `make help`
- [Directory layout](directory.md)

## License

Expand Down
11 changes: 5 additions & 6 deletions cmd/gommon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"github.com/dyweb/gommon/log/handlers/cli"
"github.com/dyweb/gommon/noodle"
"github.com/dyweb/gommon/util/fsutil"
"github.com/dyweb/gommon/util/logutil"
)

var log, logReg = dlog.NewApplicationLoggerAndRegistry("gommon")
var logReg = dlog.NewRegistry()
var log = logReg.Logger()

var verbose = false
var (
Expand All @@ -40,8 +40,8 @@ func main() {
Long: "Generate go files for gommon",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if verbose {
dlog.SetLevel(logReg, dlog.DebugLevel)
dlog.EnableSource(logReg)
dlog.SetLevel(dlog.DebugLevel)
dlog.EnableSource()
}
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -195,6 +195,5 @@ func addBuildIgnoreCmd() *cobra.Command {
}

func init() {
logReg.AddRegistry(logutil.Registry())
dlog.SetHandler(logReg, cli.New(os.Stderr, true))
dlog.SetHandler(cli.New(os.Stderr, true))
}
1 change: 0 additions & 1 deletion directory.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
- [doc](doc) style guide and developer log
- [errors](errors) error wrapping, multi error and error inspection
- [generator](generator) generating interface methods, render go template, execute shell command.
- [legacy](legacy) legacy code base
- [noodle](noodle) embed static assets for go binary with .ignore file support
- [playground](playground) test library and replay issues
- [scripts](scripts) test scripts
Expand Down
4 changes: 2 additions & 2 deletions generator/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package generator // import "github.com/dyweb/gommon/generator"
import (
dlog "github.com/dyweb/gommon/log"
"github.com/dyweb/gommon/noodle"
"github.com/dyweb/gommon/util/logutil"
)

const (
Expand All @@ -15,7 +14,8 @@ const (
DefaultGeneratedFile = "gommon_generated.go"
)

var log, logReg = logutil.NewPackageLoggerAndRegistry()
var logReg = dlog.NewRegistry()
var log = logReg.Logger()

type ConfigFile struct {
// Loggers is helper methods on struct for gommon/log to build a tree for logger, this is subject to change
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module github.com/dyweb/gommon

require (
github.com/davecgh/go-spew v1.1.1
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.2 // indirect
github.com/stretchr/testify v1.2.2
gopkg.in/yaml.v2 v2.2.1
github.com/stretchr/testify v1.3.0
gopkg.in/yaml.v2 v2.2.2
)
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -10,9 +9,9 @@ github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
File renamed without changes.
2 changes: 1 addition & 1 deletion build/go-dev/Dockerfile → hack/go-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ARG BUILD_GO_VERSION=1.11.2

# glide no longer have release, just hard code it to latest version
ENV GO_VERSION=$BUILD_GO_VERSION \
GLIDE_VERSION=v0.13.1
GLIDE_VERSION=v0.13.2

# TODO: might put glide under GOPATH/bin
RUN \
Expand Down
2 changes: 1 addition & 1 deletion build/go-dev/Makefile → hack/go-dev/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DOCKER_REPO = dyweb/go-dev
GO_VERSIONS = 1.10.7 1.11.4
GO_VERSIONS = 1.11.9 1.12.4
BUILDS = $(addprefix build-, $(GO_VERSIONS))
PUSHS = $(addprefix push-, $(GO_VERSIONS))

Expand Down
File renamed without changes.
65 changes: 0 additions & 65 deletions legacy/config/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions legacy/config/gommon.yml

This file was deleted.

19 changes: 0 additions & 19 deletions legacy/config/gommon_generated.go

This file was deleted.

27 changes: 0 additions & 27 deletions legacy/config/pkg.go

This file was deleted.

31 changes: 0 additions & 31 deletions legacy/config/testdata/multi_doc_multi_vars.yml

This file was deleted.

14 changes: 0 additions & 14 deletions legacy/config/testdata/multi_doc_single_vars.yml

This file was deleted.

2 changes: 0 additions & 2 deletions legacy/config/testdata/single_doc_no_vars.yml

This file was deleted.

3 changes: 0 additions & 3 deletions legacy/config/testdata/single_doc_vars.yml

This file was deleted.

8 changes: 0 additions & 8 deletions legacy/config/testdata/structured.yml

This file was deleted.

Loading

0 comments on commit 3c94dcd

Please sign in to comment.