Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keyed interface #19

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM adrienaury/go-devcontainer:v0.5
FROM adrienaury/go-devcontainer:v2.0

USER root

Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM adrienaury/go-devcontainer-ci:v0.5
FROM adrienaury/go-devcontainer-ci:v2.0

USER root

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ init:
@chmod 0600 ~/.dockerhub.yml
@touch ~/.github.yml
@chmod 0600 ~/.github.yml
@git config --global --add safe.directory /workspace
@git config --local core.hooksPath githooks

.PHONY: warning
Expand Down
7 changes: 4 additions & 3 deletions cmd/jl/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// You should have received a copy of the GNU General Public License
// along with JL. If not, see <http://www.gnu.org/licenses/>.

//nolint:ireturn,varnamelen
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -60,7 +60,7 @@ func ReadRowDefinition(filename string) (*RowDefinition, error) {
}

if _, err := os.Stat(filename); err == nil {
dat, err := ioutil.ReadFile(filename)
dat, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("%w", err)
}
Expand Down Expand Up @@ -112,7 +112,8 @@ func parseDescriptor(def string) (jsonline.Format, jsonline.RawType) {
}

func parse(ti jsonline.Template, to jsonline.Template,
columns []ColumnDefinition) (jsonline.Template, jsonline.Template, error) {
columns []ColumnDefinition,
) (jsonline.Template, jsonline.Template, error) {
for _, column := range columns {
iformat, irawtype := parseDescriptor(column.Input)
oformat, orawtype := parseDescriptor(column.Output)
Expand Down
3 changes: 2 additions & 1 deletion cmd/jl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

// Provisioned by ldflags
//
//nolint:gochecknoglobals
var (
name string
Expand All @@ -35,7 +36,7 @@ var (
)

func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) //nolint:exhaustivestruct
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) //nolint:exhaustruct,exhaustivestruct

cmd, err := NewRootCommand()
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/jl/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with JL. If not, see <http://www.gnu.org/licenses/>.

//nolint:varnamelen,ireturn
package main

import (
Expand Down Expand Up @@ -52,7 +53,7 @@ type RootCommand struct {
}

func NewRootCommand() (*RootCommand, error) {
rootCmd := cobra.Command{ //nolint:exhaustivestruct
rootCmd := cobra.Command{ //nolint:exhaustruct,exhaustivestruct
Use: fmt.Sprintf("%v", name),
Short: "JSONLine templating",
Long: `Order keys and enforce format of JSON lines.`,
Expand Down Expand Up @@ -139,7 +140,7 @@ func initConfig() {
if jsonlog {
log.Logger = zerolog.New(os.Stderr)
} else {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, NoColor: !color}) //nolint:exhaustivestruct
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, NoColor: !color}) //nolint:exhaustruct,exhaustivestruct
}

debug := viper.GetBool("debug")
Expand Down Expand Up @@ -193,7 +194,7 @@ func initViper() {
viper.AddConfigPath("$HOME/.jl")

if err := viper.ReadInConfig(); err != nil {
// nolint: errorlint
//nolint:errorlint
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not found; ignore
} else {
Expand Down
22 changes: 21 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cgi-fr/jsonline

go 1.16
go 1.20

require (
github.com/Trendyol/overlog v0.1.0
Expand All @@ -11,3 +11,23 @@ require (
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
2 changes: 1 addition & 1 deletion pkg/cast/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop,funlen
//nolint:cyclop,funlen,varnamelen
package cast

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cast/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop,funlen
//nolint:cyclop,funlen,varnamelen
package cast

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/cast/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with the jsonline library. If not, see <http://www.gnu.org/licenses/>.

//nolint:varnamelen
package cast_test

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cast/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop,funlen,gomnd
//nolint:cyclop,funlen,nilnil,varnamelen
package cast

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cast/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop,gocyclo,gocognit,funlen,gomnd
//nolint:cyclop,gocyclo,gocognit,funlen,nilnil,varnamelen
package cast

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cast/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop,gomnd
//nolint:cyclop,varnamelen
package cast

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cast/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop,gomnd
//nolint:cyclop,varnamelen
package cast

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cast/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop
//nolint:cyclop,varnamelen
package cast

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cast/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:cyclop,gocyclo,gocognit,funlen,gomnd
//nolint:cyclop,gocyclo,gocognit,funlen,varnamelen,nilnil
package cast

import (
Expand Down
19 changes: 10 additions & 9 deletions pkg/jsonline/conversions_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.

//nolint:forcetypeassert
package jsonline

import (
Expand All @@ -44,7 +45,7 @@ import (
func exportToString(val interface{}) (interface{}, error) {
str, err := cast.ToString(val)
if err != nil {
return nil, fmt.Errorf("%w %T to String format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to String format: %w", ErrUnsupportedExportType, val, err)
}

return str, nil
Expand All @@ -53,7 +54,7 @@ func exportToString(val interface{}) (interface{}, error) {
func exportToNumber(val interface{}) (interface{}, error) {
nb, err := cast.ToNumber(val)
if err != nil {
return nil, fmt.Errorf("%w %T to Number format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to Number format: %w", ErrUnsupportedExportType, val, err)
}

return nb, nil
Expand All @@ -62,7 +63,7 @@ func exportToNumber(val interface{}) (interface{}, error) {
func exportToBool(val interface{}) (interface{}, error) {
b, err := cast.ToBool(val)
if err != nil {
return nil, fmt.Errorf("%w %T to Boolean format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to Boolean format: %w", ErrUnsupportedExportType, val, err)
}

return b, nil
Expand All @@ -71,7 +72,7 @@ func exportToBool(val interface{}) (interface{}, error) {
func exportToBinary(val interface{}) (interface{}, error) {
b, err := cast.ToBinary(val)
if err != nil {
return nil, fmt.Errorf("%w %T to Binary format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to Binary format: %w", ErrUnsupportedExportType, val, err)
}

return base64.StdEncoding.EncodeToString(b.([]byte)), nil
Expand All @@ -80,12 +81,12 @@ func exportToBinary(val interface{}) (interface{}, error) {
func exportToDate(val interface{}) (interface{}, error) {
t, err := cast.ToDate(val)
if err != nil {
return nil, fmt.Errorf("%w %T to Date format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to Date format: %w", ErrUnsupportedExportType, val, err)
}

str, err := cast.ToString(t)
if err != nil {
return nil, fmt.Errorf("%w %T to Date format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to Date format: %w", ErrUnsupportedExportType, val, err)
}

return str, nil
Expand All @@ -94,12 +95,12 @@ func exportToDate(val interface{}) (interface{}, error) {
func exportToDateTime(val interface{}) (interface{}, error) {
t, err := cast.ToTime(val)
if err != nil {
return nil, fmt.Errorf("%w %T to DateTime format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to DateTime format: %w", ErrUnsupportedExportType, val, err)
}

str, err := cast.ToString(t)
if err != nil {
return nil, fmt.Errorf("%w %T to DateTime format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to DateTime format: %w", ErrUnsupportedExportType, val, err)
}

return str, nil
Expand All @@ -108,7 +109,7 @@ func exportToDateTime(val interface{}) (interface{}, error) {
func exportToTimestamp(val interface{}) (interface{}, error) {
i64, err := cast.ToTimestamp(val)
if err != nil {
return nil, fmt.Errorf("%w %T to Timestamp format: %v", ErrUnsupportedExportType, val, err)
return nil, fmt.Errorf("%w %T to Timestamp format: %w", ErrUnsupportedExportType, val, err)
}

return i64, nil
Expand Down
Loading