Skip to content

Commit f609097

Browse files
authored
feat: Code generator (#38)
1 parent e8d3ebe commit f609097

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3038
-266
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ certs
44
bin
55
easyp
66
coverage.out
7+
easyp.lock

.mockery.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
with-expecter: true
2+
quiet: false
3+
keeptree: false
4+
inpackage: false
5+
disable-version-string: true

Makefile

-34
This file was deleted.

Taskfile.yml

+30-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ vars:
44
LINTER_VERSION: "1.57.2"
55
GOTESTSUM_VERSION: "1.11.0"
66
LOCAL_BIN: "{{.USER_WORKING_DIR}}/bin"
7+
MOCKERY_VERSION: "v2.41.0"
78

89
tasks:
910

@@ -15,10 +16,15 @@ tasks:
1516
cmds:
1617
- "GOBIN={{.LOCAL_BIN}} go install gotest.tools/gotestsum@v{{.GOTESTSUM_VERSION}}"
1718

19+
install_mockery:
20+
cmds:
21+
- "GOBIN={{.LOCAL_BIN}} go install github.com/vektra/mockery/v2@{{.MOCKERY_VERSION}}"
22+
1823
init:
1924
deps:
2025
- install_linters
2126
- install_gotestsum
27+
- install_mockery
2228
cmds:
2329
- "go get -v ./..."
2430

@@ -53,4 +59,27 @@ tasks:
5359
cmds:
5460
- "rm -rf ./bin"
5561
- "rm -rf ./coverage.out"
56-
- "go clean -cache"
62+
- "go clean -cache"
63+
64+
mock:
65+
cmds:
66+
- "{{.LOCAL_BIN}}/mockery --name {{.NAME}} --dir {{.DIR}} --output {{.DIR}}/mocks"
67+
68+
mocks:
69+
cmds:
70+
- task: mock
71+
vars: { NAME: 'LockFile', DIR: './internal/mod/adapters/storage' }
72+
73+
- task: mock
74+
vars: { NAME: 'Storage', DIR: './internal/mod' }
75+
- task: mock
76+
vars: { NAME: 'ModuleConfig', DIR: './internal/mod' }
77+
- task: mock
78+
vars: { NAME: 'LockFile', DIR: './internal/mod' }
79+
80+
- task: mock
81+
vars: {NAME: 'Mod', DIR: './internal/api/shared/module_reflect'}
82+
- task: mock
83+
vars: {NAME: 'Storage', DIR: './internal/api/shared/module_reflect'}
84+
- task: mock
85+
vars: {NAME: 'LockFile', DIR: './internal/api/shared/module_reflect'}

cmd/easyp/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func main() {
3838
api.Mod{},
3939
api.Completion{},
4040
api.Init{},
41+
api.Generate{},
4142
),
4243
Flags: []cli.Flag{
4344
config.FlagDebug,

easyp.yaml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
version: v1alpha
2+
3+
lint:
4+
5+
use:
6+
# Minimal
7+
- DIRECTORY_SAME_PACKAGE
8+
- PACKAGE_DEFINED
9+
- PACKAGE_DIRECTORY_MATCH
10+
- PACKAGE_SAME_DIRECTORY
11+
12+
# Basic
13+
- ENUM_FIRST_VALUE_ZERO
14+
- ENUM_NO_ALLOW_ALIAS
15+
- ENUM_PASCAL_CASE
16+
- ENUM_VALUE_UPPER_SNAKE_CASE
17+
- FIELD_LOWER_SNAKE_CASE
18+
- IMPORT_NO_PUBLIC
19+
- IMPORT_NO_WEAK
20+
- IMPORT_USED
21+
- MESSAGE_PASCAL_CASE
22+
- ONEOF_LOWER_SNAKE_CASE
23+
- PACKAGE_LOWER_SNAKE_CASE
24+
- PACKAGE_SAME_CSHARP_NAMESPACE
25+
- PACKAGE_SAME_GO_PACKAGE
26+
- PACKAGE_SAME_JAVA_MULTIPLE_FILES
27+
- PACKAGE_SAME_JAVA_PACKAGE
28+
- PACKAGE_SAME_PHP_NAMESPACE
29+
- PACKAGE_SAME_RUBY_PACKAGE
30+
- PACKAGE_SAME_SWIFT_PREFIX
31+
- RPC_PASCAL_CASE
32+
- SERVICE_PASCAL_CASE
33+
34+
# Default
35+
- ENUM_VALUE_PREFIX
36+
- ENUM_ZERO_VALUE_SUFFIX
37+
- FILE_LOWER_SNAKE_CASE
38+
- RPC_REQUEST_RESPONSE_UNIQUE
39+
- RPC_REQUEST_STANDARD_NAME
40+
- RPC_RESPONSE_STANDARD_NAME
41+
- PACKAGE_VERSION_SUFFIX
42+
- SERVICE_SUFFIX
43+
44+
# Comments
45+
- COMMENT_ENUM
46+
- COMMENT_ENUM_VALUE
47+
- COMMENT_FIELD
48+
- COMMENT_MESSAGE
49+
- COMMENT_ONEOF
50+
- COMMENT_RPC
51+
- COMMENT_SERVICE
52+
53+
# Unary RPC
54+
- RPC_NO_CLIENT_STREAMING
55+
- RPC_NO_SERVER_STREAMING
56+
57+
enum_zero_value_suffix: _NONE
58+
59+
service_suffix: API
60+
61+
deps:
62+
- github.com/googleapis/googleapis
63+
- github.com/bufbuild/[email protected]
64+
- github.com/grpc-ecosystem/[email protected]
65+
66+
generate:
67+
plugins:
68+
- name: go
69+
out: .
70+
opts:
71+
paths: source_relative
72+
- name: go-grpc
73+
out: .
74+
opts:
75+
paths: source_relative
76+
require_unimplemented_servers: false
77+
- name: grpc-gateway
78+
out: .
79+
opts:
80+
paths: source_relative
81+
- name: openapiv2
82+
out: .
83+
opts:
84+
simple_operation_ids: false
85+
generate_unbound_methods: false
86+
- name: validate-go
87+
out: .
88+
opts:
89+
paths: source_relative

go.mod

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ module github.com/easyp-tech/easyp
33
go 1.22
44

55
require (
6+
github.com/brianvoe/gofakeit/v6 v6.28.0
67
github.com/codeclysm/extract/v3 v3.1.1
78
github.com/goccy/go-yaml v1.11.3
89
github.com/samber/lo v1.39.0
910
github.com/stretchr/testify v1.8.4
10-
github.com/urfave/cli/v2 v2.27.2
11-
github.com/yoheimuta/go-protoparser/v4 v4.10.0
11+
github.com/urfave/cli/v2 v2.27.1
12+
github.com/yoheimuta/go-protoparser/v4 v4.9.0
13+
golang.org/x/mod v0.17.0
1214
gopkg.in/yaml.v3 v3.0.1
1315
)
1416

@@ -23,6 +25,7 @@ require (
2325
github.com/mattn/go-isatty v0.0.20 // indirect
2426
github.com/pmezard/go-difflib v1.0.0 // indirect
2527
github.com/russross/blackfriday/v2 v2.1.0 // indirect
28+
github.com/stretchr/objx v0.5.0 // indirect
2629
github.com/ulikunitz/xz v0.5.12 // indirect
2730
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
2831
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect

go.sum

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
github.com/arduino/go-paths-helper v1.2.0 h1:qDW93PR5IZUN/jzO4rCtexiwF8P4OIcOmcSgAYLZfY4=
22
github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
3+
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
4+
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
35
github.com/codeclysm/extract/v3 v3.1.1 h1:iHZtdEAwSTqPrd+1n4jfhr1qBhUWtHlMTjT90+fJVXg=
46
github.com/codeclysm/extract/v3 v3.1.1/go.mod h1:ZJi80UG2JtfHqJI+lgJSCACttZi++dHxfWuPaMhlOfQ=
5-
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
6-
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
77
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
88
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
9+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
910
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1011
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1112
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
@@ -18,14 +19,12 @@ github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7a
1819
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
1920
github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I=
2021
github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
21-
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
22-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
22+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
23+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
2324
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
2425
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
2526
github.com/juju/errors v1.0.0 h1:yiq7kjCLll1BiaRuNY53MGI0+EQ3rF6GB+wvboZDefM=
2627
github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5Qe8=
27-
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
28-
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
2928
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
3029
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
3130
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@@ -45,42 +44,37 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
4544
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4645
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
4746
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
47+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
48+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
49+
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
50+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
51+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
52+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
4853
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
4954
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
50-
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
51-
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
5255
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
5356
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
5457
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
5558
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
56-
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
57-
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
58-
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI=
59-
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
6059
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
6160
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
6261
github.com/yoheimuta/go-protoparser/v4 v4.9.0 h1:zHRXzRjkOamwMkPu7bpiCtOpxHkM9c8zxQOvW99eWlo=
6362
github.com/yoheimuta/go-protoparser/v4 v4.9.0/go.mod h1:AHNNnSWnb0UoL4QgHPiOAg2BniQceFscPI5X/BZNHl8=
64-
github.com/yoheimuta/go-protoparser/v4 v4.10.0 h1:AcFzoUwzO7NmuluJvVnNjjKjDNVWkq/+3RHU9t0lnKs=
65-
github.com/yoheimuta/go-protoparser/v4 v4.10.0/go.mod h1:AHNNnSWnb0UoL4QgHPiOAg2BniQceFscPI5X/BZNHl8=
6663
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
6764
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
68-
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
69-
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
70-
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
71-
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
7265
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
7366
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
67+
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
68+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
7469
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7570
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
76-
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
77-
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
7871
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
7972
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
8073
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
8174
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
8275
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8376
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
8477
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
78+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8579
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
8680
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/api/config/config.go

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
package config
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"io"
76
"log"
87
"os"
98

10-
"github.com/goccy/go-yaml"
119
"github.com/urfave/cli/v2"
10+
"gopkg.in/yaml.v3"
1211
)
1312

13+
// Plugin is the configuration of the plugin.
14+
type Plugin struct {
15+
Name string `json:"name" yaml:"name"`
16+
Out string `json:"out" yaml:"out"`
17+
Opts map[string]string `json:"opts" yaml:"opts"`
18+
}
19+
20+
// Generate is the configuration of the generate command.
21+
type Generate struct {
22+
Plugins []Plugin `json:"plugins" yaml:"plugins"`
23+
}
24+
1425
// Config is the configuration of easyp.
1526
type Config struct {
1627
// LintConfig is the lint configuration.
17-
Lint LintConfig `json:"lint" yaml:"lint" env:"EASYP_LINT"`
28+
Lint LintConfig `json:"lint" yaml:"lint"`
1829

1930
// Deps is the dependencies repositories
20-
Deps []string `json:"deps" yaml:"deps" env:"EASYP_DEPS"`
31+
Deps []string `json:"deps" yaml:"deps"`
32+
33+
// Generate is the generate configuration.
34+
Generate Generate `json:"generate" yaml:"generate"`
2135
}
2236

37+
// ReadConfig reads the configuration from the file.
2338
func ReadConfig(ctx *cli.Context) (*Config, error) {
2439
cfgFileName := ctx.String(FlagCfg.Name)
2540
cfgFile, err := os.Open(cfgFileName)
@@ -30,19 +45,20 @@ func ReadConfig(ctx *cli.Context) (*Config, error) {
3045

3146
return nil, fmt.Errorf("os.Open: %w", err)
3247
}
48+
defer func() {
49+
err := cfgFile.Close()
50+
if err != nil {
51+
log.Fatalf("Error close config file: %s", cfgFileName)
52+
}
53+
}()
3354

3455
buf, err := io.ReadAll(cfgFile)
3556
if err != nil {
3657
return nil, fmt.Errorf("io.ReadAll: %w", err)
3758
}
3859

39-
jsBuf, err := yaml.YAMLToJSON(buf)
40-
if err != nil {
41-
return nil, fmt.Errorf("yaml.YAMLToJSON: %w", err)
42-
}
43-
4460
cfg := &Config{}
45-
err = json.Unmarshal(jsBuf, &cfg)
61+
err = yaml.Unmarshal(buf, &cfg)
4662
if err != nil {
4763
return nil, fmt.Errorf("json.Unmarshal: %w", err)
4864
}

0 commit comments

Comments
 (0)