1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-26 23:10:42 +02:00

сделал constants_starter

This commit is contained in:
Nikitin Aleksandr
2025-08-12 13:02:09 +03:00
parent 1ce50021d5
commit f7dafde4f0
14 changed files with 32 additions and 43 deletions

View File

@@ -2,7 +2,6 @@ package calendar
import (
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/dromara/carbon/v2"
"time"
)
@@ -85,7 +84,7 @@ func (d *HoursMinutesSeconds) UnmarshalString(str string) error {
}
// parse string
t, err := time.Parse(constants.LayoutTime, str)
t, err := time.Parse(constants_starter.LayoutTime, str)
if err != nil {
err = fmt.Errorf("invalid time string: %s, error: %w", str, err)
return err

View File

@@ -1,23 +1,22 @@
package calendar
import (
"github.com/ManyakRus/starter/constants"
"testing"
"time"
)
func TestFindPreviousWorkDay(t *testing.T) {
Date := time.Date(2023, 03, 13, 0, 0, 0, 0, constants.Loc)
Date := time.Date(2023, 03, 13, 0, 0, 0, 0, constants_starter.Loc)
Otvet := FindPreviousWorkDay(Date)
if Otvet != time.Date(2023, 03, 10, 0, 0, 0, 0, constants.Loc) {
if Otvet != time.Date(2023, 03, 10, 0, 0, 0, 0, constants_starter.Loc) {
t.Error("TestFindPreviousWorkDay error")
}
}
func TestIsWorkDay(t *testing.T) {
Date := time.Date(2023, 03, 19, 0, 0, 0, 0, constants.Loc)
Date := time.Date(2023, 03, 19, 0, 0, 0, 0, constants_starter.Loc)
Otvet := IsWorkDay(Date)
if Otvet != false {
t.Error("TestIsWorkDay error")
@@ -35,8 +34,8 @@ func TestHoursMinutesSeconds_UnmarshalByte(t *testing.T) {
func TestDiff_dates(t *testing.T) {
Date1 := time.Date(2023, 03, 19, 0, 0, 0, 0, constants.Loc)
Date2 := time.Date(2023, 03, 20, 0, 0, 0, 0, constants.Loc)
Date1 := time.Date(2023, 03, 19, 0, 0, 0, 0, constants_starter.Loc)
Date2 := time.Date(2023, 03, 20, 0, 0, 0, 0, constants_starter.Loc)
_, _, days, _, _, _ := Diff_dates(Date1, Date2)
if days != 1 {
t.Error("TestDiff_dates error")

View File

@@ -1,5 +1,5 @@
// модуль для хранения постоянных переменных, констант
package constants
package constants_starter
import (
"time"

View File

@@ -8,7 +8,7 @@ import (
"encoding/gob"
"errors"
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/constants_starter"
"github.com/dromara/carbon/v2"
"github.com/google/uuid"
"golang.org/x/exp/constraints"
@@ -36,7 +36,7 @@ import (
func init() {
//время всегда московское (из константы)
carbon.SetLocation(constants.Loc)
carbon.SetLocation(constants_starter.Loc)
}
// IsTestApp - возвращает true если это тестовая среда выполнения приложения
@@ -1682,7 +1682,7 @@ func IsTrueString(s string) bool {
// DateTimeFromString_rus - возвращает дату из строки, из формата "02.01.2006 15:04:05"
func DateTimeFromString_rus(s string) (time.Time, error) {
t, err := time.ParseInLocation(constants.LayoutDateTimeRus, s, constants.Loc)
t, err := time.ParseInLocation(constants_starter.LayoutDateTimeRus, s, constants_starter.Loc)
return t, err
}
@@ -1695,7 +1695,7 @@ func DateFromString_rus(s string) (time.Time, error) {
}
//
t, err := time.ParseInLocation(constants.LayoutDateRus, s, constants.Loc)
t, err := time.ParseInLocation(constants_starter.LayoutDateRus, s, constants_starter.Loc)
return t, err
}

View File

@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/contextmain"
"github.com/google/uuid"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -1503,8 +1502,8 @@ func TestDateFromToToday_rus(t *testing.T) {
}
func TestStringDatePeriod_rus(t *testing.T) {
Date1 := time.Date(2025, 04, 01, 0, 0, 0, 0, constants.Loc)
Date2 := time.Date(2025, 04, 23, 0, 0, 0, 0, constants.Loc)
Date1 := time.Date(2025, 04, 01, 0, 0, 0, 0, constants_starter.Loc)
Date2 := time.Date(2025, 04, 23, 0, 0, 0, 0, constants_starter.Loc)
Otvet := StringDatePeriod_rus(Date1, Date2)
if Otvet == "" {
t.Errorf("error: Expected not empty string, but got %s", Otvet)
@@ -1512,8 +1511,8 @@ func TestStringDatePeriod_rus(t *testing.T) {
}
func TestStringDateSPo_rus(t *testing.T) {
Date1 := time.Date(2025, 04, 01, 0, 0, 0, 0, constants.Loc)
Date2 := time.Date(2025, 04, 23, 0, 0, 0, 0, constants.Loc)
Date1 := time.Date(2025, 04, 01, 0, 0, 0, 0, constants_starter.Loc)
Date2 := time.Date(2025, 04, 23, 0, 0, 0, 0, constants_starter.Loc)
Otvet := StringDateSPo_rus(Date1, Date2)
if Otvet == "" {
t.Errorf("error: Expected not empty string, but got %s", Otvet)

View File

@@ -4,7 +4,6 @@ package microl
import (
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/micro"
"os"
@@ -127,7 +126,7 @@ func Set_FieldFromEnv_Int32(StructReference any, FieldName string, IsRequired bo
func Set_FieldFromEnv_Time(StructReference any, FieldName string, IsRequired bool) {
sValue := Getenv(FieldName, IsRequired)
Value, err := time.Parse(constants.LayoutDateTimeRus, sValue)
Value, err := time.Parse(constants_starter.LayoutDateTimeRus, sValue)
if err != nil {
err = fmt.Errorf("time.Parse() FieldName: %s error: %w", FieldName, err)
log.Error(err)
@@ -151,7 +150,7 @@ func Set_FieldFromEnv_Time(StructReference any, FieldName string, IsRequired boo
func Set_FieldFromEnv_Date(StructReference any, FieldName string, IsRequired bool) {
sValue := Getenv(FieldName, IsRequired)
Value, err := time.Parse(constants.LayoutDateRus, sValue)
Value, err := time.Parse(constants_starter.LayoutDateRus, sValue)
if err != nil {
err = fmt.Errorf("time.Parse() FieldName: %s error: %w", FieldName, err)
log.Error(err)

View File

@@ -1,7 +1,6 @@
package microl
import (
"github.com/ManyakRus/starter/constants"
"os"
"testing"
"time"
@@ -80,7 +79,7 @@ func TestSet_FieldFromEnv_Time(t *testing.T) {
}
sTime := "02.01.2000 00:00:00"
Time1, err := time.Parse(constants.LayoutDateTimeRus, sTime)
Time1, err := time.Parse(constants_starter.LayoutDateTimeRus, sTime)
if err != nil {
t.Error("TestSet_FieldFromEnv_Time() error")
}
@@ -103,7 +102,7 @@ func TestSet_FieldFromEnv_Date(t *testing.T) {
}
sTime := "02.01.2000"
Time1, err := time.Parse(constants.LayoutDateRus, sTime)
Time1, err := time.Parse(constants_starter.LayoutDateRus, sTime)
if err != nil {
t.Error("TestSet_FieldFromEnv_Date() error")
}

View File

@@ -3,7 +3,6 @@ package nats_connect
import (
"context"
"github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/contextmain"
"github.com/ManyakRus/starter/micro"
"testing"
@@ -16,7 +15,7 @@ import (
func TestConnect_err(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
config_main.LoadEnv()
err := Connect_err(constants.SERVICE_NAME + "_test")
err := Connect_err(constants_starter.SERVICE_NAME + "_test")
if err != nil {
t.Error("nats_connect.TestConnect_err() error: ", err)
}
@@ -26,14 +25,14 @@ func TestConnect_err(t *testing.T) {
func TestCloseConnection(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
config_main.LoadEnv()
Connect(constants.SERVICE_NAME + "_test")
Connect(constants_starter.SERVICE_NAME + "_test")
CloseConnection()
}
func TestStartNats(t *testing.T) {
//ProgramDir := micro.ProgramDir_Common()
config_main.LoadEnv()
StartNats(constants.SERVICE_NAME + "_test")
StartNats(constants_starter.SERVICE_NAME + "_test")
micro.Pause(20)
_ = contextmain.GetContext()
@@ -59,14 +58,14 @@ func TestWaitStop(t *testing.T) {
func TestConnect(t *testing.T) {
config_main.LoadEnv()
Connect(constants.SERVICE_NAME + "_test")
Connect(constants_starter.SERVICE_NAME + "_test")
defer CloseConnection()
}
func TestSendMessageCtx(t *testing.T) {
config_main.LoadEnv()
Connect(constants.SERVICE_NAME + "_test")
Connect(constants_starter.SERVICE_NAME + "_test")
defer CloseConnection()
ctxMain := contextmain.GetContext()

View File

@@ -2,7 +2,6 @@ package nats_liveness
import (
"github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/micro"
"testing"
)
@@ -12,7 +11,7 @@ var SERVICE_NAME_TEST = "starter_test"
func TestConnect(t *testing.T) {
config_main.LoadEnv()
FillSettings(SERVICE_NAME_TEST)
Connect(constants.SERVICE_NAME + "_test")
Connect(constants_starter.SERVICE_NAME + "_test")
CloseConnection()
}
@@ -20,7 +19,7 @@ func TestConnect(t *testing.T) {
func TestSendMessage(t *testing.T) {
config_main.LoadEnv()
FillSettings(SERVICE_NAME_TEST)
Connect(constants.SERVICE_NAME + "_test")
Connect(constants_starter.SERVICE_NAME + "_test")
SendMessage()
}

View File

@@ -6,7 +6,7 @@ import (
"context"
"errors"
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/constants_starter"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/port_checker"
"strings"
@@ -409,7 +409,7 @@ func GetDSN(ApplicationName string) string {
dsn += "password=" + Settings.DB_PASSWORD + " "
dsn += "dbname=" + Settings.DB_NAME + " "
dsn += "port=" + Settings.DB_PORT + " "
dsn += "sslmode=disable TimeZone=" + constants.TIME_ZONE + " "
dsn += "sslmode=disable TimeZone=" + constants_starter.TIME_ZONE + " "
dsn += "application_name=" + ApplicationName
return dsn

View File

@@ -8,7 +8,6 @@ import (
"context"
"errors"
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/port_checker"
"strings"
@@ -408,7 +407,7 @@ func GetDSN(ApplicationName string) string {
dsn += "password=" + Settings.DB_PASSWORD + " "
dsn += "dbname=" + Settings.DB_NAME + " "
dsn += "port=" + Settings.DB_PORT + " "
dsn += "sslmode=disable TimeZone=" + constants.TIME_ZONE + " "
dsn += "sslmode=disable TimeZone=" + constants_starter.TIME_ZONE + " "
dsn += "application_name=" + ApplicationName
return dsn

View File

@@ -6,7 +6,6 @@ import (
"context"
"errors"
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/port_checker"
"github.com/jackc/pgx/v5"
@@ -149,7 +148,7 @@ func GetConnectionString(ApplicationName string) string {
dsn += "user=" + Settings.DB_USER + " "
dsn += "password=" + Settings.DB_PASSWORD + " "
dsn += "dbname=" + Settings.DB_NAME + " "
dsn += "port=" + Settings.DB_PORT + " sslmode=disable TimeZone=" + constants.TIME_ZONE + " "
dsn += "port=" + Settings.DB_PORT + " sslmode=disable TimeZone=" + constants_starter.TIME_ZONE + " "
dsn += "application_name=" + ApplicationName + " "
dsn += "search_path=" + Settings.DB_SCHEMA + " "

View File

@@ -6,7 +6,6 @@ import (
"context"
"errors"
"fmt"
"github.com/ManyakRus/starter/constants"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/port_checker"
"github.com/ManyakRus/starter/postgres_pgtype"
@@ -149,7 +148,7 @@ func GetConnectionString(ApplicationName string) string {
dsn += "user=" + Settings.DB_USER + " "
dsn += "password=" + Settings.DB_PASSWORD + " "
dsn += "dbname=" + Settings.DB_NAME + " "
dsn += "port=" + Settings.DB_PORT + " sslmode=disable TimeZone=" + constants.TIME_ZONE + " "
dsn += "port=" + Settings.DB_PORT + " sslmode=disable TimeZone=" + constants_starter.TIME_ZONE + " "
dsn += "application_name=" + ApplicationName + " "
dsn += "search_path=" + Settings.DB_SCHEMA + " "

View File

@@ -2,7 +2,6 @@ package postgres_stek
import (
"errors"
"github.com/ManyakRus/starter/constants"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/tables/table_connections"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/connections"
"testing"
@@ -18,7 +17,7 @@ import (
)
// CONNECTION - объект Соединение, настроенный
var CONNECTION = connections.Connection{Table_Connection: table_connections.Table_Connection{ID: constants.CONNECTION_ID, BranchID: constants.BRANCH_ID, IsLegal: true, Server: "10.1.9.153", Port: "5432", DbName: "kol_atom_ul_uni", DbScheme: "stack", Login: "", Password: ""}}
var CONNECTION = connections.Connection{Table_Connection: table_connections.Table_Connection{ID: constants_starter.CONNECTION_ID, BranchID: constants_starter.BRANCH_ID, IsLegal: true, Server: "10.1.9.153", Port: "5432", DbName: "kol_atom_ul_uni", DbScheme: "stack", Login: "", Password: ""}}
func TestConnect_err(t *testing.T) {
//Connect_Panic()