fix bug of server deploy

This commit is contained in:
douxu 2025-12-11 16:42:25 +08:00
parent 2a3852a246
commit befb4e8971
6 changed files with 36 additions and 30 deletions

View File

@ -16,6 +16,7 @@ type BaseConfig struct {
// ServiceConfig define config struct of service config
type ServiceConfig struct {
ServiceAddr string `mapstructure:"service_addr"`
ServiceName string `mapstructure:"service_name"`
SecretKey string `mapstructure:"secret_key"`
}

View File

@ -4,6 +4,8 @@ package constants
const (
// DevelopmentLogMode define development operator environment for modelRT project
DevelopmentLogMode = "development"
// DebugLogMode define debug operator environment for modelRT project
DebugLogMode = "debug"
// ProductionLogMode define production operator environment for modelRT project
ProductionLogMode = "production"
)

View File

@ -88,6 +88,12 @@ docker logs redis
##### 2.4.1 Postgres数据注入
```SQL
insert into public.grid(id,tagname,name,description,op,ts) VALUES (1, 'grid1', '网格1', '测试网格1', -1,CURRENT_TIMESTAMP);
insert into public.zone(id,grid_id,tagname,name,description,op,ts) VALUES (1, 1,'zone1', '区域1_1', '测试区域1_1', -1,CURRENT_TIMESTAMP);
insert into public.station(id,zone_id,tagname,name,description,is_local,op,ts) VALUES (1, 1,'station1', '站1_1_1', '测试站1_1_1', true, -1,CURRENT_TIMESTAMP);
INSERT INTO public.topologic(flag, uuid_from, uuid_to, context, description, op, ts)
VALUES
(1, '00000000-0000-0000-0000-000000000000', '70c190f2-8a60-42a9-b143-ec5f87e0aa6b', '{}', '', 1, CURRENT_TIMESTAMP),
@ -98,7 +104,6 @@ VALUES
(1, 'e32bc0be-67f4-4d79-a5da-eaa40a5bd77d', '968dd6e6-faec-4f78-b58a-d6e68426b09e', '{}', '', 1, CURRENT_TIMESTAMP),
(1, 'e32bc0be-67f4-4d79-a5da-eaa40a5bd77d', '968dd6e6-faec-4f78-b58a-d6e68426b08e', '{}', '', 1, CURRENT_TIMESTAMP);
INSERT INTO public.bay (bay_uuid, name, tag, type, unom, fla, capacity, description, in_service, state, grid, zone, station, business, context, from_uuids, to_uuids, dev_protect, dev_fault_record, dev_status, dev_dyn_sense, dev_instruct, dev_etc, components, op, ts)
VALUES (
'18e71a24-694a-43fa-93a7-c4d02a27d1bc',
@ -128,7 +133,7 @@ VALUES
(
'968dd6e6-faec-4f78-b58a-d6e68426b09e',
'ns1', 'tag1', 'component1', '', '',
'grid1', 'zone1', 'station1',
'grid1', 'zone1_1', 'station1_1',
-1,
false,
-1, -1,
@ -141,7 +146,7 @@ VALUES
(
'968dd6e6-faec-4f78-b58a-d6e68426b08e',
'ns1', 'tag2', 'component2', '', '',
'grid1', 'zone1', 'station1',
'grid1', 'zone1_1', 'station1_1',
-1,
false,
-1, -1,
@ -152,19 +157,11 @@ VALUES
CURRENT_TIMESTAMP
);
INSERT INTO public.measurement (tag, name, type, size, data_source, event_plan, bay_uuid, component_uuid, op, ts)
VALUES (
'I11_C_rms',
'45母甲侧互连电流C相1',
-1,
200,
'{"type": 1, "io_address": {"device": "ssu001", "channel": "Telemetry1", "station": "001"}}',
'{"cause": {"up": 55.0, "down": 45.0}, "action": {"command": "warning", "parameters": ["I段母线甲侧互连电流C相1"]}, "enable": true}',
'18e71a24-694a-43fa-93a7-c4d02a27d1bc',
'968dd6e6-faec-4f78-b58a-d6e68426b09e',
-1,
CURRENT_TIMESTAMP
);
INSERT INTO public.measurement (id, tag, name, type, size, data_source, event_plan, bay_uuid, component_uuid, op, ts)
VALUES
(3, 'I11_C_rms', '45母甲侧互连电流C相1', -1, 200, '{"type": 1, "io_address": {"device": "ssu001", "channel": "TM1", "station": "001"}}', '{"cause": {"up": 55.0, "down": 45.0}, "action": {"command": "warning", "parameters": ["I段母线甲侧互连电流C相1"]}, "enable": true}', '18e71a24-694a-43fa-93a7-c4d02a27d1bc', '968dd6e6-faec-4f78-b58a-d6e68426b09e', -1, CURRENT_TIMESTAMP),
(4, 'I11_B_rms', '45母甲侧互连电流B相1', -1, 300, '{"type": 1, "io_address": {"device": "ssu001", "channel": "TM2", "station": "001"}}', '{"cause": {"upup": 65, "downdown": 35}, "action": {"command": "warning", "parameters": ["I段母线甲侧互连电流B相1"]}, "enable": true}', '18e71a24-694a-43fa-93a7-c4d02a27d1bc', '968dd6e6-faec-4f78-b58a-d6e68426b09e', -1, CURRENT_TIMESTAMP),
(5, 'I11_A_rms', '45母甲侧互连电流A相1', -1, 300, '{"type": 1, "io_address": {"device": "ssu001", "channel": "TM3", "station": "001"}}', '{"cause": {"up": 55, "down": 45, "upup": 65, "downdown": 35}, "action": {"command": "warning", "parameters": ["I段母线甲侧互连电流A相1"]}, "enable": true}', '18e71a24-694a-43fa-93a7-c4d02a27d1bc', '968dd6e6-faec-4f78-b58a-d6e68426b09e', -1, CURRENT_TIMESTAMP);
```
##### 2.4.2 Redis数据注入

2
go.mod
View File

@ -1,6 +1,6 @@
module modelRT
go 1.24.1
go 1.24
require (
github.com/DATA-DOG/go-sqlmock v1.5.2

View File

@ -2,8 +2,10 @@
package logger
import (
"fmt"
"os"
"sync"
"time"
"modelRT/config"
"modelRT/constants"
@ -32,8 +34,10 @@ func getEncoder() zapcore.Encoder {
// getLogWriter responsible for setting the location of log storage
func getLogWriter(mode, filename string, maxsize, maxBackup, maxAge int, compress bool) zapcore.WriteSyncer {
dateStr := time.Now().Format("2006-01-02 15:04:05")
finalFilename := fmt.Sprintf(filename, dateStr)
lumberJackLogger := &lumberjack.Logger{
Filename: filename, // log file position
Filename: finalFilename, // log file position
MaxSize: maxsize, // log file maxsize
MaxAge: maxAge, // maximum number of day files retained
MaxBackups: maxBackup, // maximum number of old files retained

18
main.go
View File

@ -3,7 +3,9 @@ package main
import (
"context"
"errors"
"flag"
"fmt"
"net/http"
"os"
"os/signal"
@ -72,9 +74,6 @@ func main() {
flag.Parse()
ctx := context.TODO()
// init logger
logger.InitLoggerInstance(modelRTConfig.LoggerConfig)
configPath := filepath.Join(*modelRTConfigDir, *modelRTConfigName+"."+*modelRTConfigType)
if _, err := os.Stat(configPath); os.IsNotExist(err) {
logger.Info(ctx, "configuration file not found,checking for example file")
@ -82,17 +81,20 @@ func main() {
exampleConfigPath := filepath.Join(*modelRTConfigDir, *modelRTConfigName+".example."+*modelRTConfigType)
if _, err := os.Stat(exampleConfigPath); err == nil {
if err := util.CopyFile(exampleConfigPath, configPath); err != nil {
logger.Error(ctx, "failed to copy example config file", "error", err)
panic(err)
panicErr := fmt.Errorf("failed to copy example config file:%w", err)
panic(panicErr)
}
logger.Info(ctx, "successfully copied example config to actual config file")
} else {
logger.Error(ctx, "No config file and no config example file found.")
panicErr := errors.New("no config file and no config example file found")
panic(panicErr)
}
}
modelRTConfig = config.ReadAndInitConfig(*modelRTConfigDir, *modelRTConfigName, *modelRTConfigType)
// init logger
logger.InitLoggerInstance(modelRTConfig.LoggerConfig)
hostName, err := os.Hostname()
if err != nil {
logger.Error(ctx, "get host name failed", "error", err)
@ -210,7 +212,7 @@ func main() {
// }
server := http.Server{
Addr: ":8080",
Addr: modelRTConfig.ServiceConfig.ServiceAddr,
Handler: engine,
}