fix modulePath

This commit is contained in:
Hoang 2021-11-10 17:08:39 +07:00
parent 7bea76065a
commit 09cc989cc8
10 changed files with 21 additions and 15 deletions

View File

@ -47,7 +47,7 @@ func (s Service) Create(payload CreateOptions) error {
// Create device
_, err = col.InsertOne(ctx, deviceData)
if err != nil {
logger.Error("devicemngt - Create ", logger.LogData{
logger.Error("devicemngmt - Create ", logger.LogData{
"doc": deviceData,
"err": err.Error(),
})

View File

@ -20,7 +20,7 @@ func (s Service) DeleteByDeviceID(deviceID string) error {
// Delete
if _, err := col.DeleteOne(ctx, cond); err != nil {
logger.Error("devicemngt - deleteByDeviceID", logger.LogData{
logger.Error("devicemngmt - deleteByDeviceID", logger.LogData{
"deviceId": deviceID,
"err": err.Error(),
})

View File

@ -21,7 +21,7 @@ func (s Service) FindAllDevicesByUserID(userID string) []Device {
// Find
cursor, err := col.Find(ctx, cond)
if err != nil {
logger.Error("devicemngt - findAllDevicesByUserID ", logger.LogData{
logger.Error("devicemngmt - findAllDevicesByUserID ", logger.LogData{
"err": err.Error(),
})
return result

View File

@ -20,7 +20,7 @@ func (s Service) GetUserIDByAuthToken(authToken string) (userID string) {
// Find
if err := col.FindOne(ctx, cond).Decode(&device); err != nil {
logger.Error("devicemngt - getUserIDByAuthToken", logger.LogData{
logger.Error("devicemngmt - getUserIDByAuthToken", logger.LogData{
"authToken": authToken,
"err": err.Error(),
})

View File

@ -59,7 +59,7 @@ func (s Service) UpdateByDeviceID(deviceID string, payload UpdateOptions) error
// Update
_, err = col.UpdateOne(ctx, cond, updateData)
if err != nil {
logger.Error("devicemngt - updateByDeviceID", logger.LogData{
logger.Error("devicemngmt - updateByDeviceID", logger.LogData{
"deviceId": deviceID,
"err": err.Error(),
})

View File

@ -3,6 +3,7 @@ package devicemngmt
// Constant ...
const (
tableDevice = "devices"
tablePrefixDefault = "devicemngmt"
timezoneHCM = "Asia/Ho_Chi_Minh"

2
db.go
View File

@ -24,7 +24,7 @@ func (s Service) isDeviceIDExisted(ctx context.Context, deviceID string) bool {
)
if err := col.FindOne(ctx, bson.M{"deviceId": deviceID}).Decode(&device); err != nil {
logger.Error("devicemngt - findByDeviceID", logger.LogData{
logger.Error("devicemngmt - findByDeviceID", logger.LogData{
"deviceId": deviceID,
"err": err.Error(),
})

View File

@ -35,6 +35,11 @@ func Init(config Config) (*Service, error) {
return nil, errors.New("please provide all necessary information for init device")
}
// If prefixTable is empty then it is devicemngmt
if config.TablePrefix == "" {
config.TablePrefix = tablePrefixDefault
}
// Connect MongoDB
db, err := mongodb.Connect(
config.MongoDB.Host,

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/selly-Modules/devicemngmt
module github.com/Selly-Modules/devicemngmt
go 1.17

View File

@ -9,7 +9,7 @@ import (
func (co CreateOptions) validate() error {
// DeviceID
if co.DeviceID == "" {
logger.Error("devicemngt - Create: no deviceID data", logger.LogData{
logger.Error("devicemngmt - Create: no deviceID data", logger.LogData{
"payload": co,
})
return errors.New("no deviceID data")
@ -17,7 +17,7 @@ func (co CreateOptions) validate() error {
// UserAgent
if co.UserAgent == "" {
logger.Error("devicemngt - Create: no userAgent data", logger.LogData{
logger.Error("devicemngmt - Create: no userAgent data", logger.LogData{
"payload": co,
})
return errors.New("no userAgent data")
@ -25,7 +25,7 @@ func (co CreateOptions) validate() error {
// IP
if co.IP == "" {
logger.Error("devicemngt - Create: no ip data", logger.LogData{
logger.Error("devicemngmt - Create: no ip data", logger.LogData{
"payload": co,
})
return errors.New("no ip data")
@ -33,7 +33,7 @@ func (co CreateOptions) validate() error {
// UserID
if co.UserID == "" {
logger.Error("devicemngt - Create: no userID data", logger.LogData{
logger.Error("devicemngmt - Create: no userID data", logger.LogData{
"payload": co,
})
return errors.New("no userID data")
@ -41,7 +41,7 @@ func (co CreateOptions) validate() error {
// AuthToken
if co.AuthToken == "" {
logger.Error("devicemngt - Create: no authToken data", logger.LogData{
logger.Error("devicemngmt - Create: no authToken data", logger.LogData{
"payload": co,
})
return errors.New("no authToken data")
@ -53,7 +53,7 @@ func (co CreateOptions) validate() error {
func (uo UpdateOptions) validate() error {
// UserAgent
if uo.UserAgent == "" {
logger.Error("devicemngt - Update: no userAgent data", logger.LogData{
logger.Error("devicemngmt - Update: no userAgent data", logger.LogData{
"payload": uo,
})
return errors.New("no userAgent data")
@ -61,7 +61,7 @@ func (uo UpdateOptions) validate() error {
// IP
if uo.IP == "" {
logger.Error("devicemngt - Update: no ip data", logger.LogData{
logger.Error("devicemngmt - Update: no ip data", logger.LogData{
"payload": uo,
})
return errors.New("no ip data")
@ -69,7 +69,7 @@ func (uo UpdateOptions) validate() error {
// AuthToken
if uo.AuthToken == "" {
logger.Error("devicemngt - Update: no authToken data", logger.LogData{
logger.Error("devicemngmt - Update: no authToken data", logger.LogData{
"payload": uo,
})
return errors.New("no authToken data")