From b80e8054d51013963c54dc16fb9d1563e4ab705a Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 5 Oct 2022 17:59:08 +0700 Subject: [PATCH] fix code --- cache/db.go | 37 ++++++++++++------ go.mod | 36 ++++++++--------- go.sum | 44 +++++++++++++++++++++ model/permission_request.go | 32 +++++++++++---- model/role_request.go | 8 +++- model/user_request.go | 78 ++++++++++++++++++++++++++++++------- permission/db.go | 55 ++++++++++++++++++-------- role/db.go | 48 ++++++++++++++++------- user/handle.go | 21 ++++++---- 9 files changed, 266 insertions(+), 93 deletions(-) diff --git a/cache/db.go b/cache/db.go index 6d062cb..99feaf3 100644 --- a/cache/db.go +++ b/cache/db.go @@ -18,18 +18,25 @@ func roleFindByCondition(ctx context.Context, cond interface{}, opts ...*options cursor, err := col.Find(ctx, cond, opts...) if err != nil { logger.Error("usermngmt - Role - Find", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.roleFindByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) + return } defer cursor.Close(ctx) if err = cursor.All(ctx, &docs); err != nil { logger.Error("usermngmt - Role - Decode", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.roleFindByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) return } @@ -45,18 +52,24 @@ func permissionFindByCondition(ctx context.Context, cond interface{}, opts ...*o cursor, err := col.Find(ctx, cond, opts...) if err != nil { logger.Error("usermngmt - Permission - Find", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.permissionFindByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) return } defer cursor.Close(ctx) if err = cursor.All(ctx, &docs); err != nil { logger.Error("usermngmt - Permission - Decode", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.permissionFindByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) return } diff --git a/go.mod b/go.mod index 8303802..6845a4e 100644 --- a/go.mod +++ b/go.mod @@ -3,46 +3,46 @@ module github.com/Selly-Modules/usermngmt go 1.17 require ( - github.com/Selly-Modules/logger v0.0.0-20210809034923-140a51f39ec9 + github.com/Selly-Modules/logger v0.0.2 github.com/Selly-Modules/mongodb v1.0.1 github.com/go-redis/redis/v8 v8.11.4 github.com/logrusorgru/aurora v2.0.3+incompatible github.com/thoas/go-funk v0.9.1 go.mongodb.org/mongo-driver v1.7.4 - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 ) require ( github.com/armon/go-radix v1.0.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/elastic/go-licenser v0.3.1 // indirect - github.com/elastic/go-sysinfo v1.1.1 // indirect - github.com/elastic/go-windows v1.0.0 // indirect + github.com/elastic/go-licenser v0.4.1 // indirect + github.com/elastic/go-sysinfo v1.8.1 // indirect + github.com/elastic/go-windows v1.0.1 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/golang/snappy v0.0.1 // indirect - github.com/jcchavezs/porto v0.1.0 // indirect + github.com/jcchavezs/porto v0.4.0 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect github.com/klauspost/compress v1.13.6 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 // indirect + github.com/prometheus/procfs v0.8.0 // indirect github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.0.2 // indirect github.com/xdg-go/stringprep v1.0.2 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect - go.elastic.co/apm v1.13.1 // indirect - go.elastic.co/apm/module/apmzap v1.13.1 // indirect + go.elastic.co/apm v1.15.0 // indirect + go.elastic.co/apm/module/apmzap v1.15.0 // indirect go.elastic.co/fastjson v1.1.0 // indirect - go.uber.org/atomic v1.7.0 // indirect - go.uber.org/multierr v1.6.0 // indirect - go.uber.org/zap v1.18.1 // indirect - golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect - golang.org/x/mod v0.3.0 // indirect - golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect - golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.8.0 // indirect + go.uber.org/zap v1.23.0 // indirect + golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect + golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect + golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect golang.org/x/text v0.3.7 // indirect - golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e // indirect + golang.org/x/tools v0.1.12 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect - howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect + howett.net/plist v1.0.0 // indirect ) diff --git a/go.sum b/go.sum index 1a0ad24..6bb44b7 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Selly-Modules/logger v0.0.0-20210809034923-140a51f39ec9 h1:AuJ/IIZ7yppyP19ILEYkwz26CwGXR4xUyXANKSG0+1U= github.com/Selly-Modules/logger v0.0.0-20210809034923-140a51f39ec9/go.mod h1:RWhSQ3F01an8KD00VjzRBZOMcE5eV2Cy0/l4ZkeieyU= +github.com/Selly-Modules/logger v0.0.2 h1:ZchJbOBN26K11qmfgCtkF2eO2h7ldIKGG5SbQzmgBEE= +github.com/Selly-Modules/logger v0.0.2/go.mod h1:kvXfyQNzXgdHfbocMCtUssRXicVKdwJahAKLKMJD1uU= github.com/Selly-Modules/mongodb v1.0.1 h1:TeBIs2VG4EbE0uAN71bD11zv5X0M7AvJfEcID3TzwIw= github.com/Selly-Modules/mongodb v1.0.1/go.mod h1:OhqdqYqh8WqEEruz6U27Wu1kKoBLwIUQsc+56xl0Wcs= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= @@ -16,10 +18,16 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/elastic/go-licenser v0.3.1 h1:RmRukU/JUmts+rpexAw0Fvt2ly7VVu6mw8z4HrEzObU= github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ= +github.com/elastic/go-licenser v0.4.1 h1:1xDURsc8pL5zYT9R29425J3vkHdt4RT5TNEMeRN48x4= +github.com/elastic/go-licenser v0.4.1/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU= github.com/elastic/go-sysinfo v1.1.1 h1:ZVlaLDyhVkDfjwPGU55CQRCRolNpc7P0BbyhhQZQmMI= github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0= +github.com/elastic/go-sysinfo v1.8.1 h1:4Yhj+HdV6WjbCRgGdZpPJ8lZQlXZLKDAeIkmQ/VRvi4= +github.com/elastic/go-sysinfo v1.8.1/go.mod h1:JfllUnzoQV/JRYymbH3dO1yggI3mV2oTKSXsDHM+uIM= github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY= github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= +github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0= +github.com/elastic/go-windows v1.0.1/go.mod h1:FoVvqWSun28vaDQPbj2Elfc0JahhPB7WQEGa3c814Ss= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -74,6 +82,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jcchavezs/porto v0.1.0 h1:Xmxxn25zQMmgE7/yHYmh19KcItG81hIwfbEEFnd6w/Q= github.com/jcchavezs/porto v0.1.0/go.mod h1:fESH0gzDHiutHRdX2hv27ojnOVFco37hg1W6E9EZF4A= +github.com/jcchavezs/porto v0.4.0 h1:Zj7RligrxmDdKGo6fBO2xYAHxEgrVBfs1YAja20WbV4= +github.com/jcchavezs/porto v0.4.0/go.mod h1:fESH0gzDHiutHRdX2hv27ojnOVFco37hg1W6E9EZF4A= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= @@ -113,6 +123,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 h1:c8R11WC8m7KNMkTv/0+Be8vvwo4I3/Ut9AC2FW8fX3U= github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= +github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -146,10 +158,15 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.elastic.co/apm v1.13.1 h1:ICIcUcQOImg/bve9mQVyLCvm1cSUZ1afdwK6ACnxczU= go.elastic.co/apm v1.13.1/go.mod h1:dylGv2HKR0tiCV+wliJz1KHtDyuD8SPe69oV7VyK6WY= +go.elastic.co/apm v1.15.0 h1:uPk2g/whK7c7XiZyz/YCUnAUBNPiyNeE3ARX3G6Gx7Q= +go.elastic.co/apm v1.15.0/go.mod h1:dylGv2HKR0tiCV+wliJz1KHtDyuD8SPe69oV7VyK6WY= go.elastic.co/apm/module/apmzap v1.13.1 h1:Soa4vNYYabPvOW1vm1A00C0UcEmfEzcx3YBjAgf5ue4= go.elastic.co/apm/module/apmzap v1.13.1/go.mod h1:Tu8/TwffpBoNGmI05VcL1Ye2AC8oXrlMKNaKD1TIQy0= +go.elastic.co/apm/module/apmzap v1.15.0 h1:SjXslnImV3jaK2BtNqRl994H9mpG8+6qqPAahbzwIys= +go.elastic.co/apm/module/apmzap v1.15.0/go.mod h1:eowOIqa+vS+BZ9YOCztd8poYGxSxXh8YfVuOHTMhKQs= go.elastic.co/fastjson v1.1.0 h1:3MrGBWWVIxe/xvsbpghtkFoPciPhOCmjsR/HfwEeQR4= go.elastic.co/fastjson v1.1.0/go.mod h1:boNGISWMjQsUPy/t6yqt2/1Wx4YNPSe+mZjlyw9vKKI= go.mongodb.org/mongo-driver v1.7.1/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8NzkI+yfU8= @@ -158,14 +175,20 @@ go.mongodb.org/mongo-driver v1.7.4/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R7 go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= +go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.18.1 h1:CSUJ2mjFszzEWt4CdKISEuChVIXGBn3lAPwkRGyVrc4= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY= +go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= @@ -173,13 +196,20 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -189,6 +219,7 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -197,6 +228,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -205,6 +238,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -216,6 +250,10 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -235,6 +273,9 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e h1:4nW4NLDYnU28ojHaHO8OVxFHk/aQ33U01a9cjED+pzE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -254,6 +295,7 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -266,3 +308,5 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M= howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= +howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM= +howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= diff --git a/model/permission_request.go b/model/permission_request.go index ec3ed73..0cafe4e 100644 --- a/model/permission_request.go +++ b/model/permission_request.go @@ -36,7 +36,9 @@ func (co PermissionCreateOptions) Validate() error { // Name if co.Name == "" { logger.Error("usermngmt - Permission - Create: no name data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Create: no name data", + Data: co, }) return errors.New("no name data") } @@ -44,7 +46,9 @@ func (co PermissionCreateOptions) Validate() error { // Code if co.Code == "" { logger.Error("usermngmt - Permission - Create: no code data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Create: no code data", + Data: co, }) return errors.New("no code data") } @@ -52,7 +56,9 @@ func (co PermissionCreateOptions) Validate() error { // RoleID if co.RoleID == "" { logger.Error("usermngmt - Permission - Create: no roleID data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Create: no roleID data", + Data: co, }) return errors.New("no role id data") } @@ -63,7 +69,9 @@ func (co PermissionCreateOptions) Validate() error { // Desc if co.Desc == "" { logger.Error("usermngmt - Permission - Create: no desc data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Create: no desc data", + Data: co, }) return errors.New("no desc data") } @@ -75,7 +83,9 @@ func (co PermissionUpdateOptions) Validate() error { // Name if co.Name == "" { logger.Error("usermngmt - Permission - Update: no name data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Update: no name data", + Data: co, }) return errors.New("no name data") } @@ -83,7 +93,9 @@ func (co PermissionUpdateOptions) Validate() error { // Code if co.Code == "" { logger.Error("usermngmt - Permission - Update: no code data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Update: no code data", + Data: co, }) return errors.New("no code data") } @@ -91,7 +103,9 @@ func (co PermissionUpdateOptions) Validate() error { // RoleID if co.RoleID == "" { logger.Error("usermngmt - Permission - Update: no roleID data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Update: no roleID data", + Data: co, }) return errors.New("no role id data") } @@ -102,7 +116,9 @@ func (co PermissionUpdateOptions) Validate() error { // Desc if co.Desc == "" { logger.Error("usermngmt - Permission - Update: no desc data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Permission - Update: no desc data", + Data: co, }) return errors.New("no desc data") } diff --git a/model/role_request.go b/model/role_request.go index 29d4ef2..8f001f4 100644 --- a/model/role_request.go +++ b/model/role_request.go @@ -33,7 +33,9 @@ func (co RoleCreateOptions) Validate() error { // Name if co.Name == "" { logger.Error("usermngmt - Role - Create: no name data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Role - Create: no name data", + Data: co, }) return errors.New(internal.ErrorInvalidName) } @@ -46,7 +48,9 @@ func (co RoleUpdateOptions) Validate() error { // Name if co.Name == "" { logger.Error("usermngmt - Role - Update: no name data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - Role - Update: no name data", + Data: co, }) return errors.New(internal.ErrorInvalidName) } diff --git a/model/user_request.go b/model/user_request.go index bd7c645..4552bd0 100644 --- a/model/user_request.go +++ b/model/user_request.go @@ -71,7 +71,11 @@ func (co UserCreateOptions) Validate() error { // Name if co.Name == "" { logger.Error("usermngmt - User - Create: no name data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Create: no name data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidName) } @@ -79,7 +83,11 @@ func (co UserCreateOptions) Validate() error { // Phone if co.Phone == "" { logger.Error("usermngmt - User - Create: no phone data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Create: no phone data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidPhoneNumber) } @@ -87,7 +95,11 @@ func (co UserCreateOptions) Validate() error { // Email if co.Email == "" { logger.Error("usermngmt - User - Create: no email data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Create: no email data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidEmail) } @@ -95,7 +107,11 @@ func (co UserCreateOptions) Validate() error { // Password if co.Password == "" { logger.Error("usermngmt - User - Create: no password data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Create: no password data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidPassword) } @@ -103,7 +119,11 @@ func (co UserCreateOptions) Validate() error { // Status if co.Status == "" { logger.Error("usermngmt - User - Create: no status data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Create: no status data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidStatus) } @@ -111,7 +131,11 @@ func (co UserCreateOptions) Validate() error { // RoleID if co.RoleID == "" { logger.Error("usermngmt - User - Create: no roleID data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Create: no roleID data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidRole) } @@ -124,7 +148,11 @@ func (uo UserUpdateOptions) Validate() error { // Name if uo.Name == "" { logger.Error("usermngmt - User - Update: no name data", logger.LogData{ - "payload": uo, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Update: no name data", + Data: map[string]interface{}{ + "payload": uo, + }, }) return errors.New(internal.ErrorInvalidName) } @@ -132,7 +160,11 @@ func (uo UserUpdateOptions) Validate() error { // Phone if uo.Phone == "" { logger.Error("usermngmt - User - Update: no phone data", logger.LogData{ - "payload": uo, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Update: no phone data", + Data: map[string]interface{}{ + "payload": uo, + }, }) return errors.New(internal.ErrorInvalidPhoneNumber) } @@ -140,7 +172,11 @@ func (uo UserUpdateOptions) Validate() error { // Email if uo.Email == "" { logger.Error("usermngmt - User - Update: no email data", logger.LogData{ - "payload": uo, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Update: no email data", + Data: map[string]interface{}{ + "payload": uo, + }, }) return errors.New(internal.ErrorInvalidEmail) } @@ -148,7 +184,11 @@ func (uo UserUpdateOptions) Validate() error { // RoleID if uo.RoleID == "" { logger.Error("usermngmt - User - Update: no roleID data", logger.LogData{ - "payload": uo, + Source: "usermngmt.Validate", + Message: "usermngmt - User - Update: no roleID data", + Data: map[string]interface{}{ + "payload": uo, + }, }) return errors.New(internal.ErrorInvalidRole) } @@ -161,14 +201,22 @@ func (co ChangePasswordOptions) Validate() error { // OldPassword, NewPassword if co.OldPassword == "" { logger.Error("usermngmt - User - ChangePassword: no old password data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - ChangePassword: no old password data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidOldPassword) } if co.NewPassword == "" { logger.Error("usermngmt - User - ChangePassword: no new password data", logger.LogData{ - "payload": co, + Source: "usermngmt.Validate", + Message: "usermngmt - User - ChangePassword: no new password data", + Data: map[string]interface{}{ + "payload": co, + }, }) return errors.New(internal.ErrorInvalidNewPassword) } @@ -181,7 +229,11 @@ func (q UserByPermissionQuery) Validate() error { // OldPassword, NewPassword if q.Permission == "" { logger.Error("usermngmt - User - GetUsersByPermission : invalid permission", logger.LogData{ - "payload": q, + Source: "usermngmt.Validate", + Message: "usermngmt - User - GetUsersByPermission : invalid permission", + Data: map[string]interface{}{ + "payload": q, + }, }) return errors.New(internal.ErrorInvalidPermission) } diff --git a/permission/db.go b/permission/db.go index 792a2e6..6bec5d3 100644 --- a/permission/db.go +++ b/permission/db.go @@ -28,8 +28,11 @@ func create(ctx context.Context, doc model.DBPermission) error { _, err := col.InsertOne(ctx, doc) if err != nil { logger.Error("usermngmt - Permission - InsertOne", logger.LogData{ - "doc": doc, - "err": err.Error(), + Source: "usermngmt.create", + Message: err.Error(), + Data: map[string]interface{}{ + "doc": doc, + }, }) return fmt.Errorf("error when create permission: %s", err.Error()) } @@ -44,9 +47,12 @@ func updateOneByCondition(ctx context.Context, cond interface{}, payload interfa _, err := col.UpdateOne(ctx, cond, payload) if err != nil { logger.Error("usermngmt - Permission - UpdateOne", logger.LogData{ - "cond": cond, - "payload": payload, - "err": err.Error(), + Source: "usermngmt.updateOneByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "payload": payload, + }, }) return fmt.Errorf("error when update permission: %s", err.Error()) } @@ -61,8 +67,11 @@ func deleteOneByCondition(ctx context.Context, cond interface{}) error { _, err := col.DeleteOne(ctx, cond) if err != nil { logger.Error("usermngmt - Permission - DeleteOne", logger.LogData{ - "cond": cond, - "err": err.Error(), + Source: "usermngmt.deleteOneByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + }, }) return fmt.Errorf("error when delete permission: %s", err.Error()) } @@ -79,18 +88,24 @@ func findByCondition(ctx context.Context, cond interface{}, opts ...*options.Fin cursor, err := col.Find(ctx, cond, opts...) if err != nil { logger.Error("usermngmt - Permission - Find", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.findByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) return } defer cursor.Close(ctx) if err = cursor.All(ctx, &docs); err != nil { logger.Error("usermngmt - Permission - Decode", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.findByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) return } @@ -105,8 +120,11 @@ func countByCondition(ctx context.Context, cond interface{}) int64 { total, err := col.CountDocuments(ctx, cond) if err != nil { logger.Error("usermngmt - Permission - CountDocuments", logger.LogData{ - "err": err.Error(), - "cond": cond, + Source: "usermngmt.countByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + }, }) } return total @@ -123,8 +141,11 @@ func isPermissionIDExisted(ctx context.Context, permissionID primitive.ObjectID) total, err := col.CountDocuments(ctx, cond) if err != nil { logger.Error("usermngmt - Permission - CountDocuments", logger.LogData{ - "condition": cond, - "err": err.Error(), + Source: "usermngmt.isPermissionIDExisted", + Message: err.Error(), + Data: map[string]interface{}{ + "condition": cond, + }, }) return false } diff --git a/role/db.go b/role/db.go index 020eac5..39c84e8 100644 --- a/role/db.go +++ b/role/db.go @@ -19,8 +19,11 @@ func create(ctx context.Context, doc model.DBRole) error { _, err := col.InsertOne(ctx, doc) if err != nil { logger.Error("usermngmt - Role - InsertOne", logger.LogData{ - "doc": doc, - "err": err.Error(), + Source: "usermngmt.create", + Message: err.Error(), + Data: map[string]interface{}{ + "doc": doc, + }, }) return fmt.Errorf("error when create role: %s", err.Error()) } @@ -35,9 +38,12 @@ func updateOneByCondition(ctx context.Context, cond interface{}, payload interfa _, err := col.UpdateOne(ctx, cond, payload) if err != nil { logger.Error("usermngmt - Role - UpdateOne", logger.LogData{ - "cond": cond, - "payload": payload, - "err": err.Error(), + Source: "usermngmt.updateOneByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "payload": payload, + }, }) return fmt.Errorf("error when update role: %s", err.Error()) } @@ -54,18 +60,24 @@ func findByCondition(ctx context.Context, cond interface{}, opts ...*options.Fin cursor, err := col.Find(ctx, cond, opts...) if err != nil { logger.Error("usermngmt - Role - Find", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.findByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) return } defer cursor.Close(ctx) if err = cursor.All(ctx, &docs); err != nil { logger.Error("usermngmt - Role - Decode", logger.LogData{ - "cond": cond, - "opts": opts, - "err": err.Error(), + Source: "usermngmt.findByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + "opts": opts, + }, }) return } @@ -80,8 +92,11 @@ func countByCondition(ctx context.Context, cond interface{}) int64 { total, err := col.CountDocuments(ctx, cond) if err != nil { logger.Error("usermngmt - Role - CountDocuments", logger.LogData{ - "err": err.Error(), - "cond": cond, + Source: "usermngmt.countByCondition", + Message: err.Error(), + Data: map[string]interface{}{ + "cond": cond, + }, }) } return total @@ -98,8 +113,11 @@ func isRoleIDExisted(ctx context.Context, roleID primitive.ObjectID) bool { total, err := col.CountDocuments(ctx, cond) if err != nil { logger.Error("usermngmt - Role - CountDocuments", logger.LogData{ - "condition": cond, - "err": err.Error(), + Source: "usermngmt.isRoleIDExisted", + Message: err.Error(), + Data: map[string]interface{}{ + "condition": cond, + }, }) return false } diff --git a/user/handle.go b/user/handle.go index f538855..1ecc631 100644 --- a/user/handle.go +++ b/user/handle.go @@ -3,6 +3,7 @@ package user import ( "context" "errors" + "fmt" "sync" "github.com/Selly-Modules/logger" @@ -409,8 +410,9 @@ func ChangeUserPassword(userID string, opt model.ChangePasswordOptions) error { // Validate userID if _, isValid := mongodb.NewIDFromString(userID); !isValid { logger.Error("usermngmt - ChangePassword: invalid userID data", logger.LogData{ - "payload": opt, - "userID": userID, + Source: "usermngmt.user.ChangeUserPassword", + Message: "usermngmt - ChangePassword: invalid userID data", + Data: fmt.Sprintf("userId: %s - opt: %s", userID, opt), }) return errors.New(internal.ErrorInvalidUser) } @@ -624,16 +626,18 @@ func HasPermission(userID, permission string) (result bool) { // Validate userID, permission if userID == "" || permission == "" { logger.Error("usermngmt - HasPermission: email or password cannot be empty", logger.LogData{ - "userID": userID, - "permission": permission, + Source: "usermngmt.user.HasPermission", + Message: "usermngmt - HasPermission: email or password cannot be empty", + Data: fmt.Sprintf("userId: %s - permission: %s", userID, permission), }) return } id, isValid := mongodb.NewIDFromString(userID) if !isValid { logger.Error("usermngmt - HasPermission: invalid user id", logger.LogData{ - "userID": userID, - "permission": permission, + Source: "usermngmt.user.HasPermission", + Message: "usermngmt - HasPermission: invalid user id", + Data: fmt.Sprintf("userId: %s - permission: %s", userID, permission), }) return } @@ -642,8 +646,9 @@ func HasPermission(userID, permission string) (result bool) { user, _ := findByID(ctx, id) if user.ID.IsZero() { logger.Error("usermngmt - HasPermission: user not found", logger.LogData{ - "userID": userID, - "permission": permission, + Source: "usermngmt.user.HasPermission", + Message: "usermngmt - HasPermission: user not found", + Data: fmt.Sprintf("userId: %s - permission: %s", userID, permission), }) return } -- 2.34.1