add(commands for common configs)
This commit is contained in:
1 parent
19c02ef270
commit
93071eef5b
23 files changed
+920
-158
No files matched your search
+24
-10
@@ -7,21 +7,31 @@ import (
|
||||
)
|
||||
|
||||
type getModuleByUuidAndNameRequest struct {
|
||||
Name string
|
||||
Uuid string
|
||||
ModuleName string
|
||||
Uuid string
|
||||
}
|
||||
|
||||
type getSchemaByModuleIdRequest struct {
|
||||
ModuleId int32
|
||||
ModuleId string
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Id int64
|
||||
Id string
|
||||
Name string
|
||||
CommonConfigs []string
|
||||
Description string
|
||||
ModuleId string
|
||||
Version int32
|
||||
Active bool
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Data map[string]interface{}
|
||||
}
|
||||
|
||||
type CommonConfig struct {
|
||||
Id string
|
||||
Name string
|
||||
Description string
|
||||
ModuleId int32
|
||||
Version int32
|
||||
Active bool
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Data map[string]interface{}
|
||||
@@ -36,7 +46,7 @@ type Connection struct {
|
||||
}
|
||||
|
||||
type ModuleInfo struct {
|
||||
Id int32
|
||||
Id string
|
||||
Name string
|
||||
Active bool
|
||||
CreatedAt time.Time
|
||||
@@ -48,10 +58,14 @@ type ModuleInfo struct {
|
||||
}
|
||||
|
||||
type ConfigSchema struct {
|
||||
Id int32
|
||||
Id string
|
||||
Version string
|
||||
ModuleId int32
|
||||
ModuleId string
|
||||
Schema schema.Schema
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type deleted struct {
|
||||
Deleted int
|
||||
}
|
||||
+7
-4
@@ -1,8 +1,11 @@
|
||||
package cfg
|
||||
|
||||
const (
|
||||
getAvailableConfigs = "config/module/get_modules_info"
|
||||
getConfigByModuleName = "config/config/get_config_by_instance_uuid_and_module_name"
|
||||
createUpdateConfig = "config/config/create_update_config"
|
||||
getSchemaByModuleId = "config/schema/get_by_module_id"
|
||||
getAvailableConfigs = "config/module/get_modules_info"
|
||||
getConfigByModuleName = "config/config/get_active_config_by_module_name"
|
||||
createUpdateConfig = "config/config/create_update_config"
|
||||
getSchemaByModuleId = "config/schema/get_by_module_id"
|
||||
getCommonConfigs = "config/common_config/get_configs"
|
||||
createUpdateCommonConfig = "config/common_config/create_update_config"
|
||||
deleteCommonConfig = "config/common_config/delete_config"
|
||||
)
|
||||
+32
-2
@@ -53,7 +53,7 @@ func (c *configClient) GetAvailableConfigs() ([]ModuleInfo, error) {
|
||||
}
|
||||
|
||||
func (c *configClient) GetConfigByModuleName(name string) (*Config, error) {
|
||||
request := &getModuleByUuidAndNameRequest{Name: name, Uuid: c.instanceUuid}
|
||||
request := &getModuleByUuidAndNameRequest{ModuleName: name, Uuid: c.instanceUuid}
|
||||
response := new(Config)
|
||||
err := c.cli.Invoke(getConfigByModuleName, callerId, request, response, backend.WithMetadata(c.headers))
|
||||
if err != nil {
|
||||
@@ -73,7 +73,7 @@ func (c *configClient) CreateUpdateConfig(request Config) (*Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) GetSchemaByModuleId(moduleId int32) (*ConfigSchema, error) {
|
||||
func (c *configClient) GetSchemaByModuleId(moduleId string) (*ConfigSchema, error) {
|
||||
request := &getSchemaByModuleIdRequest{ModuleId: moduleId}
|
||||
response := new(ConfigSchema)
|
||||
err := c.cli.Invoke(getSchemaByModuleId, callerId, &request, response, backend.WithMetadata(c.headers))
|
||||
@@ -84,6 +84,36 @@ func (c *configClient) GetSchemaByModuleId(moduleId int32) (*ConfigSchema, error
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) GetCommonConfigs(req []string) ([]CommonConfig, error) {
|
||||
response := make([]CommonConfig, 0)
|
||||
err := c.cli.Invoke(getCommonConfigs, callerId, req, &response, backend.WithMetadata(c.headers))
|
||||
if err != nil {
|
||||
return nil, c.errorHandler(err)
|
||||
} else {
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig, error) {
|
||||
response := new(CommonConfig)
|
||||
err := c.cli.Invoke(createUpdateCommonConfig, callerId, req, response, backend.WithMetadata(c.headers))
|
||||
if err != nil {
|
||||
return nil, c.errorHandler(err)
|
||||
} else {
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) DeleteCommonConfig(req []string) (int, error) {
|
||||
response := new(deleted)
|
||||
err := c.cli.Invoke(deleteCommonConfig, callerId, req, response, backend.WithMetadata(c.headers))
|
||||
if err != nil {
|
||||
return 0, c.errorHandler(err)
|
||||
} else {
|
||||
return response.Deleted, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) errorHandler(err error) error {
|
||||
errStatus, ok := status.FromError(err)
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user