1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-11-21 05:05:52 +02:00

сделал make mod

This commit is contained in:
Nikitin Aleksandr 2023-12-27 14:28:11 +03:00
parent 48bf9dc634
commit 3c64c2a56b
73 changed files with 489 additions and 1555 deletions

View File

@ -1,7 +1,7 @@
package main
import (
configmain "github.com/ManyakRus/starter/config"
configmain "github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/stopapp"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"github.com/ManyakRus/starter/postgres_gorm"

View File

@ -2,7 +2,7 @@ package server_grpc
import (
"context"
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
@ -14,7 +14,7 @@ import (
const LawsuitStatusType_ID_Test = 1
func Test_server_LawsuitStatusType_Read(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -33,7 +33,7 @@ func Test_server_LawsuitStatusType_Read(t *testing.T) {
}
func Test_server_LawsuitStatusType_Delete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -53,7 +53,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
}
func Test_server_LawsuitStatusType_Create(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
var ModelString string
@ -81,7 +81,7 @@ func Test_server_LawsuitStatusType_Create(t *testing.T) {
}
func Test_server_LawsuitStatusType_Update(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -117,7 +117,7 @@ func Test_server_LawsuitStatusType_Update(t *testing.T) {
}
func Test_server_LawsuitStatusType_Save(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -151,7 +151,7 @@ func Test_server_LawsuitStatusType_Save(t *testing.T) {
}
func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()

View File

@ -1,7 +1,7 @@
package server_nrpc
import (
config_main "github.com/ManyakRus/starter/config"
config_main "github.com/ManyakRus/starter/config_main"
"testing"
)

View File

@ -1,7 +1,7 @@
package crud_lawsuit_status_types
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/postgres_gorm"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -10,7 +10,7 @@ import (
const Postgres_ID_Test = 1
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -31,7 +31,7 @@ func TestRead(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -57,7 +57,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -97,7 +97,7 @@ func TestDelete(t *testing.T) {
func TestFind_ByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()

View File

@ -1,7 +1,7 @@
package grpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"math"
@ -21,7 +21,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -40,7 +40,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -60,7 +60,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -80,7 +80,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -105,7 +105,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -120,7 +120,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()

View File

@ -1,7 +1,7 @@
package nrpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -21,7 +21,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -40,7 +40,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -60,7 +60,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -80,7 +80,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -105,7 +105,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -119,7 +119,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()

View File

@ -1,12 +1,12 @@
package nrpc_client
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"testing"
)
func TestConnect(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
FillSettings()
Connect()
CloseConnection()

View File

@ -1,7 +1,7 @@
package main
import (
configmain "github.com/ManyakRus/starter/config"
configmain "github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/stopapp"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"github.com/ManyakRus/starter/postgres_gorm"

View File

@ -2,7 +2,7 @@ package server_grpc
import (
"context"
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
@ -13,7 +13,7 @@ import (
const LawsuitStatusType_ID_Test = 1
func Test_server_LawsuitStatusType_Read(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -32,7 +32,7 @@ func Test_server_LawsuitStatusType_Read(t *testing.T) {
}
func Test_server_LawsuitStatusType_Delete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -52,7 +52,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
}
func Test_server_LawsuitStatusType_Create(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
var ModelString string
@ -80,7 +80,7 @@ func Test_server_LawsuitStatusType_Create(t *testing.T) {
}
func Test_server_LawsuitStatusType_Update(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -116,7 +116,7 @@ func Test_server_LawsuitStatusType_Update(t *testing.T) {
}
func Test_server_LawsuitStatusType_Save(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -150,7 +150,7 @@ func Test_server_LawsuitStatusType_Save(t *testing.T) {
}
func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()

View File

@ -1,7 +1,7 @@
package server_nrpc
import (
config_main "github.com/ManyakRus/starter/config"
config_main "github.com/ManyakRus/starter/config_main"
"testing"
)

View File

@ -1,7 +1,7 @@
package crud_lawsuit_status_types
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/postgres_gorm"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -10,7 +10,7 @@ import (
const Postgres_ID_Test = 1
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -31,7 +31,7 @@ func TestRead(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -57,7 +57,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -97,7 +97,7 @@ func TestDelete(t *testing.T) {
func TestFind_ByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()

View File

@ -1,7 +1,7 @@
package grpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -20,7 +20,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -39,7 +39,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -59,7 +59,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -79,7 +79,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -104,7 +104,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -152,7 +152,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()

View File

@ -1,7 +1,7 @@
package nrpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -20,7 +20,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -39,7 +39,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -59,7 +59,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -79,7 +79,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -104,7 +104,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -152,7 +152,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()

View File

@ -1,12 +1,12 @@
package nrpc_client
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"testing"
)
func TestConnect(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
FillSettings()
Connect()
CloseConnection()

View File

@ -1,7 +1,7 @@
package main
import (
configmain "github.com/ManyakRus/starter/config"
configmain "github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/stopapp"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"github.com/ManyakRus/starter/postgres_gorm"

View File

@ -2,7 +2,7 @@ package server_grpc
import (
"context"
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
@ -14,7 +14,7 @@ import (
const LawsuitStatusType_ID_Test = 1
func Test_server_LawsuitStatusType_Read(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -33,7 +33,7 @@ func Test_server_LawsuitStatusType_Read(t *testing.T) {
}
func Test_server_LawsuitStatusType_Delete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -53,7 +53,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
}
func Test_server_LawsuitStatusType_Create(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
var ModelString string
@ -81,7 +81,7 @@ func Test_server_LawsuitStatusType_Create(t *testing.T) {
}
func Test_server_LawsuitStatusType_Update(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -117,7 +117,7 @@ func Test_server_LawsuitStatusType_Update(t *testing.T) {
}
func Test_server_LawsuitStatusType_Save(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -151,7 +151,7 @@ func Test_server_LawsuitStatusType_Save(t *testing.T) {
}
func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()

View File

@ -1,7 +1,7 @@
package server_nrpc
import (
config_main "github.com/ManyakRus/starter/config"
config_main "github.com/ManyakRus/starter/config_main"
"testing"
)

View File

@ -1,7 +1,7 @@
package crud_lawsuit_status_types
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/postgres_gorm"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -10,7 +10,7 @@ import (
const Postgres_ID_Test = 1
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -31,7 +31,7 @@ func TestRead(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -57,7 +57,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -97,7 +97,7 @@ func TestDelete(t *testing.T) {
func TestFind_ByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()

View File

@ -1,7 +1,7 @@
package grpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"math"
@ -21,7 +21,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -40,7 +40,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -60,7 +60,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -80,7 +80,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -105,7 +105,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -120,7 +120,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()

View File

@ -1,7 +1,7 @@
package nrpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -21,7 +21,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -40,7 +40,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -60,7 +60,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -80,7 +80,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -105,7 +105,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -119,7 +119,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()

View File

@ -1,12 +1,12 @@
package nrpc_client
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"testing"
)
func TestConnect(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
FillSettings()
Connect()
CloseConnection()

View File

@ -1,7 +1,7 @@
package main
import (
configmain "github.com/ManyakRus/starter/config"
configmain "github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/stopapp"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"github.com/ManyakRus/starter/postgres_gorm"

View File

@ -2,7 +2,7 @@ package server_grpc
import (
"context"
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
@ -13,7 +13,7 @@ import (
const LawsuitStatusType_ID_Test = 1
func Test_server_LawsuitStatusType_Read(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -32,7 +32,7 @@ func Test_server_LawsuitStatusType_Read(t *testing.T) {
}
func Test_server_LawsuitStatusType_Delete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -52,7 +52,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
}
func Test_server_LawsuitStatusType_Create(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
var ModelString string
@ -80,7 +80,7 @@ func Test_server_LawsuitStatusType_Create(t *testing.T) {
}
func Test_server_LawsuitStatusType_Update(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -116,7 +116,7 @@ func Test_server_LawsuitStatusType_Update(t *testing.T) {
}
func Test_server_LawsuitStatusType_Save(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()
@ -150,7 +150,7 @@ func Test_server_LawsuitStatusType_Save(t *testing.T) {
}
func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
crud_starter.InitCrudTransport_DB()
ctx := context.Background()

View File

@ -1,7 +1,7 @@
package server_nrpc
import (
config_main "github.com/ManyakRus/starter/config"
config_main "github.com/ManyakRus/starter/config_main"
"testing"
)

View File

@ -1,7 +1,7 @@
package crud_lawsuit_status_types
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/postgres_gorm"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -10,7 +10,7 @@ import (
const Postgres_ID_Test = 1
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -31,7 +31,7 @@ func TestRead(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -57,7 +57,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()
@ -97,7 +97,7 @@ func TestDelete(t *testing.T) {
func TestFind_ByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
postgres_gorm.Connect()
defer postgres_gorm.CloseConnection()

View File

@ -1,7 +1,7 @@
package grpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -20,7 +20,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -39,7 +39,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -59,7 +59,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -79,7 +79,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -104,7 +104,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
@ -152,7 +152,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()

View File

@ -1,7 +1,7 @@
package nrpc_lawsuit_status_types
import (
config "github.com/ManyakRus/starter/config"
config "github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
@ -20,7 +20,7 @@ func TestGetVersionModel(t *testing.T) {
}
func TestRead(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -39,7 +39,7 @@ func TestRead(t *testing.T) {
}
func TestCreate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -59,7 +59,7 @@ func TestCreate(t *testing.T) {
}
func TestUpdate(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -79,7 +79,7 @@ func TestUpdate(t *testing.T) {
}
func TestSave(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -104,7 +104,7 @@ func TestSave(t *testing.T) {
}
func TestDelete(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()
@ -152,7 +152,7 @@ func TestDelete(t *testing.T) {
}
func TestFindByExtID(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
nrpc_client.Connect()
defer nrpc_client.CloseConnection()

View File

@ -1,12 +1,12 @@
package nrpc_client
import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"testing"
)
func TestConnect(t *testing.T) {
config.LoadEnv()
config_main.LoadEnv()
FillSettings()
Connect()
CloseConnection()

10
go.mod
View File

@ -3,7 +3,7 @@ module github.com/ManyakRus/crud_generator
go 1.20
require (
github.com/ManyakRus/starter v0.0.0-20231128073137-db11116c6e48
github.com/ManyakRus/starter v0.0.0-20231227074038-f1cc2e5171fa
github.com/bxcodec/faker/v3 v3.8.1
github.com/davecgh/go-spew v1.1.1
github.com/iancoleman/strcase v0.3.0
@ -13,19 +13,19 @@ require (
github.com/ompluscator/dynamic-struct v1.4.0
github.com/otiai10/copy v1.14.0
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e
golang.org/x/tools v0.16.0
golang.org/x/tools v0.16.1
gorm.io/gorm v1.25.5
)
require (
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgx/v5 v5.5.1 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/joho/godotenv v1.5.1 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect

24
go.sum
View File

@ -3,8 +3,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJc
github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8=
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792 h1:bxwxD0H3kSUAH3uNk/b74gkImcUiP7dyibmMoVwk338=
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792/go.mod h1:OUyxCVbPW/2lC1e6cM7Am941SJiC88BhNnb24x2R3a8=
github.com/ManyakRus/starter v0.0.0-20231128073137-db11116c6e48 h1:HMa9cFNrgsF5O7bf+bfvYRl2/BICh+xVM0xfsSvbCh8=
github.com/ManyakRus/starter v0.0.0-20231128073137-db11116c6e48/go.mod h1:a+wYuguDadLR6xaj9fN8m6acWhUjzPuxaPtZfJhMNW4=
github.com/ManyakRus/starter v0.0.0-20231227074038-f1cc2e5171fa h1:v+rN/vdH1ODCja4iTka/3QToxu4ey76u76pkFHcSfOI=
github.com/ManyakRus/starter v0.0.0-20231227074038-f1cc2e5171fa/go.mod h1:1fRj4AUMGeQTtnwBa52pvMd9zwqPDms+uaxozhHkM1Q=
github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/SqcM=
github.com/bxcodec/faker/v3 v3.8.1/go.mod h1:DdSDccxF5msjFo5aO4vrobRQ8nIApg8kq3QWPEQD6+o=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
@ -60,10 +60,10 @@ github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw=
github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.5.1 h1:5I9etrGkLrN+2XPCsi6XLlV5DITbSL/xBZdmAxFcXPI=
github.com/jackc/pgx/v5 v5.5.1/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jimsmart/schema v0.2.1 h1:MsSsqq0i86bUskhJJZ6RnrgscbDeBMalLZym6Hx9l3U=
@ -79,7 +79,7 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI=
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
@ -135,8 +135,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
@ -221,8 +221,8 @@ golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
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=
@ -238,7 +238,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=

View File

@ -2,7 +2,7 @@ package config
import (
"github.com/ManyakRus/crud_generator/internal/constants"
ConfigMain "github.com/ManyakRus/starter/config"
ConfigMain "github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/micro"
"log"
"os"

View File

@ -19,7 +19,7 @@ func TestFormatName(t *testing.T) {
func TestDeleteLineWithComment(t *testing.T) {
s := `import (
"github.com/ManyakRus/starter/config"
"github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/postgres_gorm"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"

View File

@ -2,7 +2,7 @@ package folders
import (
"github.com/ManyakRus/crud_generator/internal/config"
ConfigMain "github.com/ManyakRus/starter/config"
ConfigMain "github.com/ManyakRus/starter/config_main"
"testing"
)

View File

@ -2,7 +2,7 @@ package logic
import (
"github.com/ManyakRus/crud_generator/internal/config"
ConfigMain "github.com/ManyakRus/starter/config"
ConfigMain "github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/micro"
"testing"
)

View File

@ -1,7 +1,7 @@
package postgres
import (
ConfigMain "github.com/ManyakRus/starter/config"
ConfigMain "github.com/ManyakRus/starter/config_main"
"github.com/ManyakRus/starter/postgres_gorm"
"testing"
)

View File

@ -1,6 +1,6 @@
// модуль для загрузки переменных окружения в структуру
package config
package config_main
import (
"github.com/ManyakRus/starter/logger"

View File

@ -792,3 +792,13 @@ func DeleteEndSlash(Text string) string {
return Otvet
}
// Int64FromString - возвращает int64 из строки
func Int64FromString(s string) (int64, error) {
var Otvet int64
var err error
Otvet, err = strconv.ParseInt(s, 10, 64)
return Otvet, err
}

View File

@ -1,42 +0,0 @@
package ping
import (
"github.com/ManyakRus/starter/logger"
"net"
"time"
)
// log - глобальный логгер
var log = logger.GetLog()
func Ping_err(IP, Port string) error {
var err error
var timeout time.Duration
timeout = time.Second * 3
network := IP + ":" + Port
conn, err := net.DialTimeout("tcp", network, timeout)
if err != nil {
//log.Warn("PingPort() error: ", err)
} else {
defer conn.Close()
//log.Debug("ping OK: ", network)
}
return err
}
func Ping(IP, Port string) {
var err error
network := IP + ":" + Port
err = Ping_err(IP, Port)
if err != nil {
log.Panic("Ping() error: ", err)
} else {
log.Debug("Ping() OK: ", network)
}
}

View File

@ -0,0 +1,43 @@
package port_checker
import (
"github.com/ManyakRus/starter/logger"
"net"
"time"
)
// log - глобальный логгер
var log = logger.GetLog()
// CheckPort_err - проверяет доступность порта, возвращает ошибку
func CheckPort_err(IP, Port string) error {
var err error
var timeout time.Duration
timeout = time.Second * 3
network := IP + ":" + Port
conn, err := net.DialTimeout("tcp", network, timeout)
if err != nil {
} else {
defer conn.Close()
}
return err
}
// CheckPort - проверяет доступность порта
// создаёт панику при ошибке
func CheckPort(IP, Port string) {
var err error
network := IP + ":" + Port
err = CheckPort_err(IP, Port)
if err != nil {
log.Panic("CheckPort() error: ", err)
} else {
log.Debug("CheckPort() OK: ", network)
}
}

View File

@ -5,8 +5,9 @@ package postgres_gorm
import (
"context"
"errors"
"fmt"
"github.com/ManyakRus/starter/logger"
"github.com/ManyakRus/starter/ping"
"github.com/ManyakRus/starter/port_checker"
"strings"
"time"
@ -60,7 +61,7 @@ func Connect() {
FillSettings()
}
ping.Ping(Settings.DB_HOST, Settings.DB_PORT)
port_checker.CheckPort(Settings.DB_HOST, Settings.DB_PORT)
err := Connect_err()
if err != nil {
@ -97,8 +98,15 @@ func Connect_WithApplicationName_err(ApplicationName string) error {
//
conf := &gorm.Config{}
conn := postgres.Open(dsn)
Conn, err = gorm.Open(conn, conf)
//conn := postgres.Open(dsn)
dialect := postgres.New(postgres.Config{
DSN: dsn,
PreferSimpleProtocol: true, //для запуска мультизапросов
})
Conn, err = gorm.Open(dialect, conf)
//Conn, err = gorm.Open(conn, conf)
Conn.Config.NamingStrategy = schema.NamingStrategy{TablePrefix: Settings.DB_SCHEMA + "."}
Conn.Config.Logger = gormlogger.Default.LogMode(gormlogger.Warn)
@ -130,7 +138,7 @@ func IsClosed() bool {
err = DB.Ping()
if err != nil {
log.Error("DB.Ping() error: ", err)
log.Error("DB.CheckPort() error: ", err)
return true
}
return otvet
@ -366,13 +374,13 @@ loop:
log.Warn("Context app is canceled. postgres_gorm.ping")
break loop
case <-ticker.C:
err := ping.Ping_err(Settings.DB_HOST, Settings.DB_PORT)
err := port_checker.CheckPort_err(Settings.DB_HOST, Settings.DB_PORT)
//log.Debug("ticker, ping err: ", err) //удалить
if err != nil {
NeedReconnect = true
log.Warn("postgres_gorm Ping(", addr, ") error: ", err)
log.Warn("postgres_gorm CheckPort(", addr, ") error: ", err)
} else if NeedReconnect == true {
log.Warn("postgres_gorm Ping(", addr, ") OK. Start Reconnect()")
log.Warn("postgres_gorm CheckPort(", addr, ") OK. Start Reconnect()")
NeedReconnect = false
Connect()
}
@ -381,3 +389,34 @@ loop:
stopapp.GetWaitGroup_Main().Done()
}
// RawMultipleSQL - выполняет текст запроса, отдельно для каждого запроса
func RawMultipleSQL(db *gorm.DB, TextSQL string) *gorm.DB {
var tx *gorm.DB
var err error
tx = db
// запустим все запросы отдельно
sqlSlice := strings.Split(TextSQL, ";")
len1 := len(sqlSlice)
for i, v := range sqlSlice {
if i == len1-1 {
tx = tx.Raw(v)
err = tx.Error
} else {
tx = tx.Exec(v)
err = tx.Error
}
if err != nil {
TextError := fmt.Sprint("db.Raw() error: ", err, ", TextSQL: \n", v)
err = errors.New(TextError)
break
}
}
if tx == nil {
log.Panic("db.Raw() error: rows =nil")
}
return tx
}

View File

@ -1,9 +0,0 @@
language: go
go:
- 1.x
- tip
matrix:
allow_failures:
- go: tip

View File

@ -1,5 +1,6 @@
[![](https://godoc.org/github.com/jackc/pgservicefile?status.svg)](https://godoc.org/github.com/jackc/pgservicefile)
[![Build Status](https://travis-ci.org/jackc/pgservicefile.svg)](https://travis-ci.org/jackc/pgservicefile)
[![Go Reference](https://pkg.go.dev/badge/github.com/jackc/pgservicefile.svg)](https://pkg.go.dev/github.com/jackc/pgservicefile)
[![Build Status](https://github.com/jackc/pgservicefile/actions/workflows/ci.yml/badge.svg)](https://github.com/jackc/pgservicefile/actions/workflows/ci.yml)
# pgservicefile

View File

@ -1,3 +1,12 @@
# 5.5.1 (December 9, 2023)
* Add CopyFromFunc helper function. (robford)
* Add PgConn.Deallocate method that uses PostgreSQL protocol Close message.
* pgx uses new PgConn.Deallocate method. This allows deallocating statements to work in a failed transaction. This fixes a case where the prepared statement map could become invalid.
* Fix: Prefer driver.Valuer over json.Marshaler for json fields. (Jacopo)
* Fix: simple protocol SQL sanitizer previously panicked if an invalid $0 placeholder was used. This now returns an error instead. (maksymnevajdev)
* Add pgtype.Numeric.ScanScientific (Eshton Robateau)
# 5.5.0 (November 4, 2023)
* Add CollectExactlyOneRow. (Julien GOTTELAND)

View File

@ -92,7 +92,7 @@ See the presentation at Golang Estonia, [PGX Top to Bottom](https://www.youtube.
## Supported Go and PostgreSQL Versions
pgx supports the same versions of Go and PostgreSQL that are supported by their respective teams. For [Go](https://golang.org/doc/devel/release.html#policy) that is the two most recent major releases and for [PostgreSQL](https://www.postgresql.org/support/versioning/) the major releases in the last 5 years. This means pgx supports Go 1.20 and higher and PostgreSQL 11 and higher. pgx also is tested against the latest version of [CockroachDB](https://www.cockroachlabs.com/product/).
pgx supports the same versions of Go and PostgreSQL that are supported by their respective teams. For [Go](https://golang.org/doc/devel/release.html#policy) that is the two most recent major releases and for [PostgreSQL](https://www.postgresql.org/support/versioning/) the major releases in the last 5 years. This means pgx supports Go 1.20 and higher and PostgreSQL 12 and higher. pgx also is tested against the latest version of [CockroachDB](https://www.cockroachlabs.com/product/).
## Version Policy

View File

@ -61,6 +61,8 @@ type Batch struct {
}
// Queue queues a query to batch b. query can be an SQL query or the name of a prepared statement.
// The only pgx option argument that is supported is QueryRewriter. Queries are executed using the
// connection's DefaultQueryExecMode.
func (b *Batch) Queue(query string, arguments ...any) *QueuedQuery {
qq := &QueuedQuery{
query: query,

View File

@ -338,17 +338,26 @@ func (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.Statem
return sd, nil
}
// Deallocate releases a prepared statement.
// Deallocate releases a prepared statement. Calling Deallocate on a non-existent prepared statement will succeed.
func (c *Conn) Deallocate(ctx context.Context, name string) error {
var psName string
if sd, ok := c.preparedStatements[name]; ok {
delete(c.preparedStatements, name)
sd := c.preparedStatements[name]
if sd != nil {
psName = sd.Name
} else {
psName = name
}
_, err := c.pgConn.Exec(ctx, "deallocate "+quoteIdentifier(psName)).ReadAll()
return err
err := c.pgConn.Deallocate(ctx, psName)
if err != nil {
return err
}
if sd != nil {
delete(c.preparedStatements, name)
}
return nil
}
// DeallocateAll releases all previously prepared statements from the server and client, where it also resets the statement and description cache.
@ -466,7 +475,7 @@ optionLoop:
if queryRewriter != nil {
sql, arguments, err = queryRewriter.RewriteQuery(ctx, c, sql, arguments)
if err != nil {
return pgconn.CommandTag{}, fmt.Errorf("rewrite query failed: %v", err)
return pgconn.CommandTag{}, fmt.Errorf("rewrite query failed: %w", err)
}
}
@ -733,7 +742,7 @@ optionLoop:
sql, args, err = queryRewriter.RewriteQuery(ctx, c, sql, args)
if err != nil {
rows := c.getRows(ctx, originalSQL, originalArgs)
err = fmt.Errorf("rewrite query failed: %v", err)
err = fmt.Errorf("rewrite query failed: %w", err)
rows.fatal(err)
return rows, err
}
@ -893,8 +902,6 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
return &batchResults{ctx: ctx, conn: c, err: err}
}
mode := c.config.DefaultQueryExecMode
for _, bi := range b.queuedQueries {
var queryRewriter QueryRewriter
sql := bi.query
@ -902,6 +909,7 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
optionLoop:
for len(arguments) > 0 {
// Update Batch.Queue function comment when additional options are implemented
switch arg := arguments[0].(type) {
case QueryRewriter:
queryRewriter = arg
@ -915,7 +923,7 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
var err error
sql, arguments, err = queryRewriter.RewriteQuery(ctx, c, sql, arguments)
if err != nil {
return &batchResults{ctx: ctx, conn: c, err: fmt.Errorf("rewrite query failed: %v", err)}
return &batchResults{ctx: ctx, conn: c, err: fmt.Errorf("rewrite query failed: %w", err)}
}
}
@ -923,6 +931,8 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
bi.arguments = arguments
}
// TODO: changing mode per batch? Update Batch.Queue function comment when implemented
mode := c.config.DefaultQueryExecMode
if mode == QueryExecModeSimpleProtocol {
return c.sendBatchQueryExecModeSimpleProtocol(ctx, b)
}

View File

@ -64,6 +64,33 @@ func (cts *copyFromSlice) Err() error {
return cts.err
}
// CopyFromFunc returns a CopyFromSource interface that relies on nxtf for values.
// nxtf returns rows until it either signals an 'end of data' by returning row=nil and err=nil,
// or it returns an error. If nxtf returns an error, the copy is aborted.
func CopyFromFunc(nxtf func() (row []any, err error)) CopyFromSource {
return &copyFromFunc{next: nxtf}
}
type copyFromFunc struct {
next func() ([]any, error)
valueRow []any
err error
}
func (g *copyFromFunc) Next() bool {
g.valueRow, g.err = g.next()
// only return true if valueRow exists and no error
return g.valueRow != nil && g.err == nil
}
func (g *copyFromFunc) Values() ([]any, error) {
return g.valueRow, g.err
}
func (g *copyFromFunc) Err() error {
return g.err
}
// CopyFromSource is the interface used by *Conn.CopyFrom as the source for copy data.
type CopyFromSource interface {
// Next returns true if there is another row and makes the next row data

View File

@ -36,7 +36,7 @@ func (eqb *ExtendedQueryBuilder) Build(m *pgtype.Map, sd *pgconn.StatementDescri
for i := range args {
err := eqb.appendParam(m, sd.ParamOIDs[i], -1, args[i])
if err != nil {
err = fmt.Errorf("failed to encode args[%d]: %v", i, err)
err = fmt.Errorf("failed to encode args[%d]: %w", i, err)
return err
}
}

View File

@ -35,6 +35,11 @@ func (q *Query) Sanitize(args ...any) (string, error) {
str = part
case int:
argIdx := part - 1
if argIdx < 0 {
return "", fmt.Errorf("first sql argument must be > 0")
}
if argIdx >= len(args) {
return "", fmt.Errorf("insufficient arguments")
}

View File

@ -813,6 +813,9 @@ type StatementDescription struct {
// Prepare creates a prepared statement. If the name is empty, the anonymous prepared statement will be used. This
// allows Prepare to also to describe statements without creating a server-side prepared statement.
//
// Prepare does not send a PREPARE statement to the server. It uses the PostgreSQL Parse and Describe protocol messages
// directly.
func (pgConn *PgConn) Prepare(ctx context.Context, name, sql string, paramOIDs []uint32) (*StatementDescription, error) {
if err := pgConn.lock(); err != nil {
return nil, err
@ -869,6 +872,52 @@ readloop:
return psd, nil
}
// Deallocate deallocates a prepared statement.
//
// Deallocate does not send a DEALLOCATE statement to the server. It uses the PostgreSQL Close protocol message
// directly. This has slightly different behavior than executing DEALLOCATE statement.
// - Deallocate can succeed in an aborted transaction.
// - Deallocating a non-existent prepared statement is not an error.
func (pgConn *PgConn) Deallocate(ctx context.Context, name string) error {
if err := pgConn.lock(); err != nil {
return err
}
defer pgConn.unlock()
if ctx != context.Background() {
select {
case <-ctx.Done():
return newContextAlreadyDoneError(ctx)
default:
}
pgConn.contextWatcher.Watch(ctx)
defer pgConn.contextWatcher.Unwatch()
}
pgConn.frontend.SendClose(&pgproto3.Close{ObjectType: 'S', Name: name})
pgConn.frontend.SendSync(&pgproto3.Sync{})
err := pgConn.flushWithPotentialWriteReadDeadlock()
if err != nil {
pgConn.asyncClose()
return err
}
for {
msg, err := pgConn.receiveMessage()
if err != nil {
pgConn.asyncClose()
return normalizeTimeoutError(ctx, err)
}
switch msg := msg.(type) {
case *pgproto3.ErrorResponse:
return ErrorResponseToPgError(msg)
case *pgproto3.ReadyForQuery:
return nil
}
}
}
// ErrorResponseToPgError converts a wire protocol error message to a *PgError.
func ErrorResponseToPgError(msg *pgproto3.ErrorResponse) *PgError {
return &PgError{

View File

@ -110,7 +110,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
r, _, err := buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
var explicitDimensions []ArrayDimension
@ -122,7 +122,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
for {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
if r == '=' {
@ -133,12 +133,12 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
lower, err := arrayParseInteger(buf)
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
if r != ':' {
@ -147,12 +147,12 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
upper, err := arrayParseInteger(buf)
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
if r != ']' {
@ -164,12 +164,12 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
}
if r != '{' {
return nil, fmt.Errorf("invalid array, expected '{': %v", err)
return nil, fmt.Errorf("invalid array, expected '{' got %v", r)
}
implicitDimensions := []ArrayDimension{{LowerBound: 1, Length: 0}}
@ -178,7 +178,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
for {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
if r == '{' {
@ -195,7 +195,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
for {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
switch r {
@ -214,7 +214,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
buf.UnreadRune()
value, quoted, err := arrayParseValue(buf)
if err != nil {
return nil, fmt.Errorf("invalid array value: %v", err)
return nil, fmt.Errorf("invalid array value: %w", err)
}
if currentDim == counterDim {
implicitDimensions[currentDim].Length++

View File

@ -231,7 +231,7 @@ func (w *uint64Wrapper) ScanNumeric(v Numeric) error {
bi, err := v.toBigInt()
if err != nil {
return fmt.Errorf("cannot scan into *uint64: %v", err)
return fmt.Errorf("cannot scan into *uint64: %w", err)
}
if !bi.IsUint64() {
@ -284,7 +284,7 @@ func (w *uintWrapper) ScanNumeric(v Numeric) error {
bi, err := v.toBigInt()
if err != nil {
return fmt.Errorf("cannot scan into *uint: %v", err)
return fmt.Errorf("cannot scan into *uint: %w", err)
}
if !bi.IsUint64() {

View File

@ -282,17 +282,17 @@ func (scanPlanTextAnyToDateScanner) Scan(src []byte, dst any) error {
if match != nil {
year, err := strconv.ParseInt(match[1], 10, 32)
if err != nil {
return fmt.Errorf("BUG: cannot parse date that regexp matched (year): %v", err)
return fmt.Errorf("BUG: cannot parse date that regexp matched (year): %w", err)
}
month, err := strconv.ParseInt(match[2], 10, 32)
if err != nil {
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %v", err)
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %w", err)
}
day, err := strconv.ParseInt(match[3], 10, 32)
if err != nil {
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %v", err)
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %w", err)
}
// BC matched

View File

@ -25,18 +25,21 @@ func (c JSONCodec) PlanEncode(m *Map, oid uint32, format int16, value any) Encod
case []byte:
return encodePlanJSONCodecEitherFormatByteSlice{}
// Cannot rely on driver.Valuer being handled later because anything can be marshalled.
//
// https://github.com/jackc/pgx/issues/1430
//
// Check for driver.Valuer must come before json.Marshaler so that it is guaranteed to beused
// when both are implemented https://github.com/jackc/pgx/issues/1805
case driver.Valuer:
return &encodePlanDriverValuer{m: m, oid: oid, formatCode: format}
// Must come before trying wrap encode plans because a pointer to a struct may be unwrapped to a struct that can be
// marshalled.
//
// https://github.com/jackc/pgx/issues/1681
case json.Marshaler:
return encodePlanJSONCodecEitherFormatMarshal{}
// Cannot rely on driver.Valuer being handled later because anything can be marshalled.
//
// https://github.com/jackc/pgx/issues/1430
case driver.Valuer:
return &encodePlanDriverValuer{m: m, oid: oid, formatCode: format}
}
// Because anything can be marshalled the normal wrapping in Map.PlanScan doesn't get a chance to run. So try the

View File

@ -339,18 +339,18 @@ func parseUntypedTextMultirange(src []byte) ([]string, error) {
r, _, err := buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %v", err)
return nil, fmt.Errorf("invalid array: %w", err)
}
if r != '{' {
return nil, fmt.Errorf("invalid multirange, expected '{': %v", err)
return nil, fmt.Errorf("invalid multirange, expected '{' got %v", r)
}
parseValueLoop:
for {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid multirange: %v", err)
return nil, fmt.Errorf("invalid multirange: %w", err)
}
switch r {
@ -361,7 +361,7 @@ parseValueLoop:
buf.UnreadRune()
value, err := parseRange(buf)
if err != nil {
return nil, fmt.Errorf("invalid multirange value: %v", err)
return nil, fmt.Errorf("invalid multirange value: %w", err)
}
elements = append(elements, value)
}

View File

@ -119,6 +119,26 @@ func (n Numeric) Int64Value() (Int8, error) {
return Int8{Int64: bi.Int64(), Valid: true}, nil
}
func (n *Numeric) ScanScientific(src string) error {
if !strings.ContainsAny("eE", src) {
return scanPlanTextAnyToNumericScanner{}.Scan([]byte(src), n)
}
if bigF, ok := new(big.Float).SetString(string(src)); ok {
smallF, _ := bigF.Float64()
src = strconv.FormatFloat(smallF, 'f', -1, 64)
}
num, exp, err := parseNumericString(src)
if err != nil {
return err
}
*n = Numeric{Int: num, Exp: exp, Valid: true}
return nil
}
func (n *Numeric) toBigInt() (*big.Int, error) {
if n.Exp == 0 {
return n.Int, nil

View File

@ -40,7 +40,7 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
r, _, err := buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid lower bound: %v", err)
return nil, fmt.Errorf("invalid lower bound: %w", err)
}
switch r {
case '(':
@ -53,7 +53,7 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid lower value: %v", err)
return nil, fmt.Errorf("invalid lower value: %w", err)
}
buf.UnreadRune()
@ -62,13 +62,13 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
} else {
utr.Lower, err = rangeParseValue(buf)
if err != nil {
return nil, fmt.Errorf("invalid lower value: %v", err)
return nil, fmt.Errorf("invalid lower value: %w", err)
}
}
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("missing range separator: %v", err)
return nil, fmt.Errorf("missing range separator: %w", err)
}
if r != ',' {
return nil, fmt.Errorf("missing range separator: %v", r)
@ -76,7 +76,7 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid upper value: %v", err)
return nil, fmt.Errorf("invalid upper value: %w", err)
}
if r == ')' || r == ']' {
@ -85,12 +85,12 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
buf.UnreadRune()
utr.Upper, err = rangeParseValue(buf)
if err != nil {
return nil, fmt.Errorf("invalid upper value: %v", err)
return nil, fmt.Errorf("invalid upper value: %w", err)
}
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("missing upper bound: %v", err)
return nil, fmt.Errorf("missing upper bound: %w", err)
}
switch r {
case ')':

View File

@ -120,7 +120,7 @@ func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value any, buf []byt
buf, err = lowerPlan.Encode(lower, buf)
if err != nil {
return nil, fmt.Errorf("failed to encode %v as element of range: %v", lower, err)
return nil, fmt.Errorf("failed to encode %v as element of range: %w", lower, err)
}
if buf == nil {
return nil, fmt.Errorf("Lower cannot be NULL unless LowerType is Unbounded")
@ -144,7 +144,7 @@ func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value any, buf []byt
buf, err = upperPlan.Encode(upper, buf)
if err != nil {
return nil, fmt.Errorf("failed to encode %v as element of range: %v", upper, err)
return nil, fmt.Errorf("failed to encode %v as element of range: %w", upper, err)
}
if buf == nil {
return nil, fmt.Errorf("Upper cannot be NULL unless UpperType is Unbounded")
@ -194,7 +194,7 @@ func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value any, buf []byte)
buf, err = lowerPlan.Encode(lower, buf)
if err != nil {
return nil, fmt.Errorf("failed to encode %v as element of range: %v", lower, err)
return nil, fmt.Errorf("failed to encode %v as element of range: %w", lower, err)
}
if buf == nil {
return nil, fmt.Errorf("Lower cannot be NULL unless LowerType is Unbounded")
@ -215,7 +215,7 @@ func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value any, buf []byte)
buf, err = upperPlan.Encode(upper, buf)
if err != nil {
return nil, fmt.Errorf("failed to encode %v as element of range: %v", upper, err)
return nil, fmt.Errorf("failed to encode %v as element of range: %w", upper, err)
}
if buf == nil {
return nil, fmt.Errorf("Upper cannot be NULL unless UpperType is Unbounded")
@ -282,7 +282,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target any) erro
err = lowerPlan.Scan(ubr.Lower, lowerTarget)
if err != nil {
return fmt.Errorf("cannot scan into %v from range element: %v", lowerTarget, err)
return fmt.Errorf("cannot scan into %v from range element: %w", lowerTarget, err)
}
}
@ -294,7 +294,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target any) erro
err = upperPlan.Scan(ubr.Upper, upperTarget)
if err != nil {
return fmt.Errorf("cannot scan into %v from range element: %v", upperTarget, err)
return fmt.Errorf("cannot scan into %v from range element: %w", upperTarget, err)
}
}
@ -332,7 +332,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target any) error
err = lowerPlan.Scan([]byte(utr.Lower), lowerTarget)
if err != nil {
return fmt.Errorf("cannot scan into %v from range element: %v", lowerTarget, err)
return fmt.Errorf("cannot scan into %v from range element: %w", lowerTarget, err)
}
}
@ -344,7 +344,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target any) error
err = upperPlan.Scan([]byte(utr.Upper), upperTarget)
if err != nil {
return fmt.Errorf("cannot scan into %v from range element: %v", upperTarget, err)
return fmt.Errorf("cannot scan into %v from range element: %w", upperTarget, err)
}
}

View File

@ -31,7 +31,7 @@
// with sql.Open.
//
// connConfig, _ := pgx.ParseConfig(os.Getenv("DATABASE_URL"))
// connConfig.Logger = myLogger
// connConfig.Tracer = &tracelog.TraceLog{Logger: myLogger, LogLevel: tracelog.LogLevelInfo}
// connStr := stdlib.RegisterConnConfig(connConfig)
// db, _ := sql.Open("pgx", connStr)
//
@ -840,7 +840,7 @@ func (r *Rows) Next(dest []driver.Value) error {
var err error
dest[i], err = r.valueFuncs[i](rv)
if err != nil {
return fmt.Errorf("convert field %d failed: %v", i, err)
return fmt.Errorf("convert field %d failed: %w", i, err)
}
} else {
dest[i] = nil

View File

@ -11,8 +11,6 @@ import (
"go/ast"
"go/token"
"sort"
"golang.org/x/tools/internal/typeparams"
)
// PathEnclosingInterval returns the node that encloses the source
@ -322,7 +320,7 @@ func childrenOf(n ast.Node) []ast.Node {
children = append(children, n.Recv)
}
children = append(children, n.Name)
if tparams := typeparams.ForFuncType(n.Type); tparams != nil {
if tparams := n.Type.TypeParams; tparams != nil {
children = append(children, tparams)
}
if n.Type.Params != nil {
@ -377,7 +375,7 @@ func childrenOf(n ast.Node) []ast.Node {
tok(n.Lbrack, len("[")),
tok(n.Rbrack, len("]")))
case *typeparams.IndexListExpr:
case *ast.IndexListExpr:
children = append(children,
tok(n.Lbrack, len("[")),
tok(n.Rbrack, len("]")))
@ -588,7 +586,7 @@ func NodeDescription(n ast.Node) string {
return "decrement statement"
case *ast.IndexExpr:
return "index expression"
case *typeparams.IndexListExpr:
case *ast.IndexListExpr:
return "index list expression"
case *ast.InterfaceType:
return "interface type"

View File

@ -9,8 +9,6 @@ import (
"go/ast"
"reflect"
"sort"
"golang.org/x/tools/internal/typeparams"
)
// An ApplyFunc is invoked by Apply for each node n, even if n is nil,
@ -252,7 +250,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
a.apply(n, "X", nil, n.X)
a.apply(n, "Index", nil, n.Index)
case *typeparams.IndexListExpr:
case *ast.IndexListExpr:
a.apply(n, "X", nil, n.X)
a.applyList(n, "Indices")
@ -293,7 +291,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
a.apply(n, "Fields", nil, n.Fields)
case *ast.FuncType:
if tparams := typeparams.ForFuncType(n); tparams != nil {
if tparams := n.TypeParams; tparams != nil {
a.apply(n, "TypeParams", nil, tparams)
}
a.apply(n, "Params", nil, n.Params)
@ -408,7 +406,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
case *ast.TypeSpec:
a.apply(n, "Doc", nil, n.Doc)
a.apply(n, "Name", nil, n.Name)
if tparams := typeparams.ForTypeSpec(n); tparams != nil {
if tparams := n.TypeParams; tparams != nil {
a.apply(n, "TypeParams", nil, tparams)
}
a.apply(n, "Type", nil, n.Type)

21
vendor/golang.org/x/tools/internal/event/keys/util.go generated vendored Normal file
View File

@ -0,0 +1,21 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package keys
import (
"sort"
"strings"
)
// Join returns a canonical join of the keys in S:
// a sorted comma-separated string list.
func Join[S ~[]T, T ~string](s S) string {
strs := make([]string, 0, len(s))
for _, v := range s {
strs = append(strs, string(v))
}
sort.Strings(strs)
return strings.Join(strs, ",")
}

View File

@ -254,7 +254,7 @@ type pass struct {
otherFiles []*ast.File // sibling files.
// Intermediate state, generated by load.
existingImports map[string]*ImportInfo
existingImports map[string][]*ImportInfo
allRefs references
missingRefs references
@ -319,7 +319,7 @@ func (p *pass) importIdentifier(imp *ImportInfo) string {
func (p *pass) load() ([]*ImportFix, bool) {
p.knownPackages = map[string]*packageInfo{}
p.missingRefs = references{}
p.existingImports = map[string]*ImportInfo{}
p.existingImports = map[string][]*ImportInfo{}
// Load basic information about the file in question.
p.allRefs = collectReferences(p.f)
@ -350,7 +350,7 @@ func (p *pass) load() ([]*ImportFix, bool) {
}
}
for _, imp := range imports {
p.existingImports[p.importIdentifier(imp)] = imp
p.existingImports[p.importIdentifier(imp)] = append(p.existingImports[p.importIdentifier(imp)], imp)
}
// Find missing references.
@ -389,31 +389,33 @@ func (p *pass) fix() ([]*ImportFix, bool) {
// Found everything, or giving up. Add the new imports and remove any unused.
var fixes []*ImportFix
for _, imp := range p.existingImports {
// We deliberately ignore globals here, because we can't be sure
// they're in the same package. People do things like put multiple
// main packages in the same directory, and we don't want to
// remove imports if they happen to have the same name as a var in
// a different package.
if _, ok := p.allRefs[p.importIdentifier(imp)]; !ok {
fixes = append(fixes, &ImportFix{
StmtInfo: *imp,
IdentName: p.importIdentifier(imp),
FixType: DeleteImport,
})
continue
}
for _, identifierImports := range p.existingImports {
for _, imp := range identifierImports {
// We deliberately ignore globals here, because we can't be sure
// they're in the same package. People do things like put multiple
// main packages in the same directory, and we don't want to
// remove imports if they happen to have the same name as a var in
// a different package.
if _, ok := p.allRefs[p.importIdentifier(imp)]; !ok {
fixes = append(fixes, &ImportFix{
StmtInfo: *imp,
IdentName: p.importIdentifier(imp),
FixType: DeleteImport,
})
continue
}
// An existing import may need to update its import name to be correct.
if name := p.importSpecName(imp); name != imp.Name {
fixes = append(fixes, &ImportFix{
StmtInfo: ImportInfo{
Name: name,
ImportPath: imp.ImportPath,
},
IdentName: p.importIdentifier(imp),
FixType: SetImportName,
})
// An existing import may need to update its import name to be correct.
if name := p.importSpecName(imp); name != imp.Name {
fixes = append(fixes, &ImportFix{
StmtInfo: ImportInfo{
Name: name,
ImportPath: imp.ImportPath,
},
IdentName: p.importIdentifier(imp),
FixType: SetImportName,
})
}
}
}
// Collecting fixes involved map iteration, so sort for stability. See

View File

@ -1,204 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package typeparams contains common utilities for writing tools that interact
// with generic Go code, as introduced with Go 1.18.
//
// Many of the types and functions in this package are proxies for the new APIs
// introduced in the standard library with Go 1.18. For example, the
// typeparams.Union type is an alias for go/types.Union, and the ForTypeSpec
// function returns the value of the go/ast.TypeSpec.TypeParams field. At Go
// versions older than 1.18 these helpers are implemented as stubs, allowing
// users of this package to write code that handles generic constructs inline,
// even if the Go version being used to compile does not support generics.
//
// Additionally, this package contains common utilities for working with the
// new generic constructs, to supplement the standard library APIs. Notably,
// the StructuralTerms API computes a minimal representation of the structural
// restrictions on a type parameter.
//
// An external version of these APIs is available in the
// golang.org/x/exp/typeparams module.
package typeparams
import (
"fmt"
"go/ast"
"go/token"
"go/types"
)
// UnpackIndexExpr extracts data from AST nodes that represent index
// expressions.
//
// For an ast.IndexExpr, the resulting indices slice will contain exactly one
// index expression. For an ast.IndexListExpr (go1.18+), it may have a variable
// number of index expressions.
//
// For nodes that don't represent index expressions, the first return value of
// UnpackIndexExpr will be nil.
func UnpackIndexExpr(n ast.Node) (x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack token.Pos) {
switch e := n.(type) {
case *ast.IndexExpr:
return e.X, e.Lbrack, []ast.Expr{e.Index}, e.Rbrack
case *IndexListExpr:
return e.X, e.Lbrack, e.Indices, e.Rbrack
}
return nil, token.NoPos, nil, token.NoPos
}
// PackIndexExpr returns an *ast.IndexExpr or *ast.IndexListExpr, depending on
// the cardinality of indices. Calling PackIndexExpr with len(indices) == 0
// will panic.
func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack token.Pos) ast.Expr {
switch len(indices) {
case 0:
panic("empty indices")
case 1:
return &ast.IndexExpr{
X: x,
Lbrack: lbrack,
Index: indices[0],
Rbrack: rbrack,
}
default:
return &IndexListExpr{
X: x,
Lbrack: lbrack,
Indices: indices,
Rbrack: rbrack,
}
}
}
// IsTypeParam reports whether t is a type parameter.
func IsTypeParam(t types.Type) bool {
_, ok := t.(*TypeParam)
return ok
}
// OriginMethod returns the origin method associated with the method fn.
// For methods on a non-generic receiver base type, this is just
// fn. However, for methods with a generic receiver, OriginMethod returns the
// corresponding method in the method set of the origin type.
//
// As a special case, if fn is not a method (has no receiver), OriginMethod
// returns fn.
func OriginMethod(fn *types.Func) *types.Func {
recv := fn.Type().(*types.Signature).Recv()
if recv == nil {
return fn
}
base := recv.Type()
p, isPtr := base.(*types.Pointer)
if isPtr {
base = p.Elem()
}
named, isNamed := base.(*types.Named)
if !isNamed {
// Receiver is a *types.Interface.
return fn
}
if ForNamed(named).Len() == 0 {
// Receiver base has no type parameters, so we can avoid the lookup below.
return fn
}
orig := NamedTypeOrigin(named)
gfn, _, _ := types.LookupFieldOrMethod(orig, true, fn.Pkg(), fn.Name())
// This is a fix for a gopls crash (#60628) due to a go/types bug (#60634). In:
// package p
// type T *int
// func (*T) f() {}
// LookupFieldOrMethod(T, true, p, f)=nil, but NewMethodSet(*T)={(*T).f}.
// Here we make them consistent by force.
// (The go/types bug is general, but this workaround is reached only
// for generic T thanks to the early return above.)
if gfn == nil {
mset := types.NewMethodSet(types.NewPointer(orig))
for i := 0; i < mset.Len(); i++ {
m := mset.At(i)
if m.Obj().Id() == fn.Id() {
gfn = m.Obj()
break
}
}
}
// In golang/go#61196, we observe another crash, this time inexplicable.
if gfn == nil {
panic(fmt.Sprintf("missing origin method for %s.%s; named == origin: %t, named.NumMethods(): %d, origin.NumMethods(): %d", named, fn, named == orig, named.NumMethods(), orig.NumMethods()))
}
return gfn.(*types.Func)
}
// GenericAssignableTo is a generalization of types.AssignableTo that
// implements the following rule for uninstantiated generic types:
//
// If V and T are generic named types, then V is considered assignable to T if,
// for every possible instantation of V[A_1, ..., A_N], the instantiation
// T[A_1, ..., A_N] is valid and V[A_1, ..., A_N] implements T[A_1, ..., A_N].
//
// If T has structural constraints, they must be satisfied by V.
//
// For example, consider the following type declarations:
//
// type Interface[T any] interface {
// Accept(T)
// }
//
// type Container[T any] struct {
// Element T
// }
//
// func (c Container[T]) Accept(t T) { c.Element = t }
//
// In this case, GenericAssignableTo reports that instantiations of Container
// are assignable to the corresponding instantiation of Interface.
func GenericAssignableTo(ctxt *Context, V, T types.Type) bool {
// If V and T are not both named, or do not have matching non-empty type
// parameter lists, fall back on types.AssignableTo.
VN, Vnamed := V.(*types.Named)
TN, Tnamed := T.(*types.Named)
if !Vnamed || !Tnamed {
return types.AssignableTo(V, T)
}
vtparams := ForNamed(VN)
ttparams := ForNamed(TN)
if vtparams.Len() == 0 || vtparams.Len() != ttparams.Len() || NamedTypeArgs(VN).Len() != 0 || NamedTypeArgs(TN).Len() != 0 {
return types.AssignableTo(V, T)
}
// V and T have the same (non-zero) number of type params. Instantiate both
// with the type parameters of V. This must always succeed for V, and will
// succeed for T if and only if the type set of each type parameter of V is a
// subset of the type set of the corresponding type parameter of T, meaning
// that every instantiation of V corresponds to a valid instantiation of T.
// Minor optimization: ensure we share a context across the two
// instantiations below.
if ctxt == nil {
ctxt = NewContext()
}
var targs []types.Type
for i := 0; i < vtparams.Len(); i++ {
targs = append(targs, vtparams.At(i))
}
vinst, err := Instantiate(ctxt, V, targs, true)
if err != nil {
panic("type parameters should satisfy their own constraints")
}
tinst, err := Instantiate(ctxt, T, targs, true)
if err != nil {
return false
}
return types.AssignableTo(vinst, tinst)
}

View File

@ -1,122 +0,0 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package typeparams
import (
"go/types"
)
// CoreType returns the core type of T or nil if T does not have a core type.
//
// See https://go.dev/ref/spec#Core_types for the definition of a core type.
func CoreType(T types.Type) types.Type {
U := T.Underlying()
if _, ok := U.(*types.Interface); !ok {
return U // for non-interface types,
}
terms, err := _NormalTerms(U)
if len(terms) == 0 || err != nil {
// len(terms) -> empty type set of interface.
// err != nil => U is invalid, exceeds complexity bounds, or has an empty type set.
return nil // no core type.
}
U = terms[0].Type().Underlying()
var identical int // i in [0,identical) => Identical(U, terms[i].Type().Underlying())
for identical = 1; identical < len(terms); identical++ {
if !types.Identical(U, terms[identical].Type().Underlying()) {
break
}
}
if identical == len(terms) {
// https://go.dev/ref/spec#Core_types
// "There is a single type U which is the underlying type of all types in the type set of T"
return U
}
ch, ok := U.(*types.Chan)
if !ok {
return nil // no core type as identical < len(terms) and U is not a channel.
}
// https://go.dev/ref/spec#Core_types
// "the type chan E if T contains only bidirectional channels, or the type chan<- E or
// <-chan E depending on the direction of the directional channels present."
for chans := identical; chans < len(terms); chans++ {
curr, ok := terms[chans].Type().Underlying().(*types.Chan)
if !ok {
return nil
}
if !types.Identical(ch.Elem(), curr.Elem()) {
return nil // channel elements are not identical.
}
if ch.Dir() == types.SendRecv {
// ch is bidirectional. We can safely always use curr's direction.
ch = curr
} else if curr.Dir() != types.SendRecv && ch.Dir() != curr.Dir() {
// ch and curr are not bidirectional and not the same direction.
return nil
}
}
return ch
}
// _NormalTerms returns a slice of terms representing the normalized structural
// type restrictions of a type, if any.
//
// For all types other than *types.TypeParam, *types.Interface, and
// *types.Union, this is just a single term with Tilde() == false and
// Type() == typ. For *types.TypeParam, *types.Interface, and *types.Union, see
// below.
//
// Structural type restrictions of a type parameter are created via
// non-interface types embedded in its constraint interface (directly, or via a
// chain of interface embeddings). For example, in the declaration type
// T[P interface{~int; m()}] int the structural restriction of the type
// parameter P is ~int.
//
// With interface embedding and unions, the specification of structural type
// restrictions may be arbitrarily complex. For example, consider the
// following:
//
// type A interface{ ~string|~[]byte }
//
// type B interface{ int|string }
//
// type C interface { ~string|~int }
//
// type T[P interface{ A|B; C }] int
//
// In this example, the structural type restriction of P is ~string|int: A|B
// expands to ~string|~[]byte|int|string, which reduces to ~string|~[]byte|int,
// which when intersected with C (~string|~int) yields ~string|int.
//
// _NormalTerms computes these expansions and reductions, producing a
// "normalized" form of the embeddings. A structural restriction is normalized
// if it is a single union containing no interface terms, and is minimal in the
// sense that removing any term changes the set of types satisfying the
// constraint. It is left as a proof for the reader that, modulo sorting, there
// is exactly one such normalized form.
//
// Because the minimal representation always takes this form, _NormalTerms
// returns a slice of tilde terms corresponding to the terms of the union in
// the normalized structural restriction. An error is returned if the type is
// invalid, exceeds complexity bounds, or has an empty type set. In the latter
// case, _NormalTerms returns ErrEmptyTypeSet.
//
// _NormalTerms makes no guarantees about the order of terms, except that it
// is deterministic.
func _NormalTerms(typ types.Type) ([]*Term, error) {
switch typ := typ.(type) {
case *TypeParam:
return StructuralTerms(typ)
case *Union:
return UnionTermSet(typ)
case *types.Interface:
return InterfaceTermSet(typ)
default:
return []*Term{NewTerm(false, typ)}, nil
}
}

View File

@ -1,12 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.18
// +build !go1.18
package typeparams
// Enabled reports whether type parameters are enabled in the current build
// environment.
const Enabled = false

View File

@ -1,15 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package typeparams
// Note: this constant is in a separate file as this is the only acceptable
// diff between the <1.18 API of this package and the 1.18 API.
// Enabled reports whether type parameters are enabled in the current build
// environment.
const Enabled = true

View File

@ -1,218 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package typeparams
import (
"errors"
"fmt"
"go/types"
"os"
"strings"
)
//go:generate go run copytermlist.go
const debug = false
var ErrEmptyTypeSet = errors.New("empty type set")
// StructuralTerms returns a slice of terms representing the normalized
// structural type restrictions of a type parameter, if any.
//
// Structural type restrictions of a type parameter are created via
// non-interface types embedded in its constraint interface (directly, or via a
// chain of interface embeddings). For example, in the declaration
//
// type T[P interface{~int; m()}] int
//
// the structural restriction of the type parameter P is ~int.
//
// With interface embedding and unions, the specification of structural type
// restrictions may be arbitrarily complex. For example, consider the
// following:
//
// type A interface{ ~string|~[]byte }
//
// type B interface{ int|string }
//
// type C interface { ~string|~int }
//
// type T[P interface{ A|B; C }] int
//
// In this example, the structural type restriction of P is ~string|int: A|B
// expands to ~string|~[]byte|int|string, which reduces to ~string|~[]byte|int,
// which when intersected with C (~string|~int) yields ~string|int.
//
// StructuralTerms computes these expansions and reductions, producing a
// "normalized" form of the embeddings. A structural restriction is normalized
// if it is a single union containing no interface terms, and is minimal in the
// sense that removing any term changes the set of types satisfying the
// constraint. It is left as a proof for the reader that, modulo sorting, there
// is exactly one such normalized form.
//
// Because the minimal representation always takes this form, StructuralTerms
// returns a slice of tilde terms corresponding to the terms of the union in
// the normalized structural restriction. An error is returned if the
// constraint interface is invalid, exceeds complexity bounds, or has an empty
// type set. In the latter case, StructuralTerms returns ErrEmptyTypeSet.
//
// StructuralTerms makes no guarantees about the order of terms, except that it
// is deterministic.
func StructuralTerms(tparam *TypeParam) ([]*Term, error) {
constraint := tparam.Constraint()
if constraint == nil {
return nil, fmt.Errorf("%s has nil constraint", tparam)
}
iface, _ := constraint.Underlying().(*types.Interface)
if iface == nil {
return nil, fmt.Errorf("constraint is %T, not *types.Interface", constraint.Underlying())
}
return InterfaceTermSet(iface)
}
// InterfaceTermSet computes the normalized terms for a constraint interface,
// returning an error if the term set cannot be computed or is empty. In the
// latter case, the error will be ErrEmptyTypeSet.
//
// See the documentation of StructuralTerms for more information on
// normalization.
func InterfaceTermSet(iface *types.Interface) ([]*Term, error) {
return computeTermSet(iface)
}
// UnionTermSet computes the normalized terms for a union, returning an error
// if the term set cannot be computed or is empty. In the latter case, the
// error will be ErrEmptyTypeSet.
//
// See the documentation of StructuralTerms for more information on
// normalization.
func UnionTermSet(union *Union) ([]*Term, error) {
return computeTermSet(union)
}
func computeTermSet(typ types.Type) ([]*Term, error) {
tset, err := computeTermSetInternal(typ, make(map[types.Type]*termSet), 0)
if err != nil {
return nil, err
}
if tset.terms.isEmpty() {
return nil, ErrEmptyTypeSet
}
if tset.terms.isAll() {
return nil, nil
}
var terms []*Term
for _, term := range tset.terms {
terms = append(terms, NewTerm(term.tilde, term.typ))
}
return terms, nil
}
// A termSet holds the normalized set of terms for a given type.
//
// The name termSet is intentionally distinct from 'type set': a type set is
// all types that implement a type (and includes method restrictions), whereas
// a term set just represents the structural restrictions on a type.
type termSet struct {
complete bool
terms termlist
}
func indentf(depth int, format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, strings.Repeat(".", depth)+format+"\n", args...)
}
func computeTermSetInternal(t types.Type, seen map[types.Type]*termSet, depth int) (res *termSet, err error) {
if t == nil {
panic("nil type")
}
if debug {
indentf(depth, "%s", t.String())
defer func() {
if err != nil {
indentf(depth, "=> %s", err)
} else {
indentf(depth, "=> %s", res.terms.String())
}
}()
}
const maxTermCount = 100
if tset, ok := seen[t]; ok {
if !tset.complete {
return nil, fmt.Errorf("cycle detected in the declaration of %s", t)
}
return tset, nil
}
// Mark the current type as seen to avoid infinite recursion.
tset := new(termSet)
defer func() {
tset.complete = true
}()
seen[t] = tset
switch u := t.Underlying().(type) {
case *types.Interface:
// The term set of an interface is the intersection of the term sets of its
// embedded types.
tset.terms = allTermlist
for i := 0; i < u.NumEmbeddeds(); i++ {
embedded := u.EmbeddedType(i)
if _, ok := embedded.Underlying().(*TypeParam); ok {
return nil, fmt.Errorf("invalid embedded type %T", embedded)
}
tset2, err := computeTermSetInternal(embedded, seen, depth+1)
if err != nil {
return nil, err
}
tset.terms = tset.terms.intersect(tset2.terms)
}
case *Union:
// The term set of a union is the union of term sets of its terms.
tset.terms = nil
for i := 0; i < u.Len(); i++ {
t := u.Term(i)
var terms termlist
switch t.Type().Underlying().(type) {
case *types.Interface:
tset2, err := computeTermSetInternal(t.Type(), seen, depth+1)
if err != nil {
return nil, err
}
terms = tset2.terms
case *TypeParam, *Union:
// A stand-alone type parameter or union is not permitted as union
// term.
return nil, fmt.Errorf("invalid union term %T", t)
default:
if t.Type() == types.Typ[types.Invalid] {
continue
}
terms = termlist{{t.Tilde(), t.Type()}}
}
tset.terms = tset.terms.union(terms)
if len(tset.terms) > maxTermCount {
return nil, fmt.Errorf("exceeded max term count %d", maxTermCount)
}
}
case *TypeParam:
panic("unreachable")
default:
// For all other types, the term set is just a single non-tilde term
// holding the type itself.
if u != types.Typ[types.Invalid] {
tset.terms = termlist{{false, t}}
}
}
return tset, nil
}
// under is a facade for the go/types internal function of the same name. It is
// used by typeterm.go.
func under(t types.Type) types.Type {
return t.Underlying()
}

View File

@ -1,163 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Code generated by copytermlist.go DO NOT EDIT.
package typeparams
import (
"bytes"
"go/types"
)
// A termlist represents the type set represented by the union
// t1 ∪ y2 ∪ ... tn of the type sets of the terms t1 to tn.
// A termlist is in normal form if all terms are disjoint.
// termlist operations don't require the operands to be in
// normal form.
type termlist []*term
// allTermlist represents the set of all types.
// It is in normal form.
var allTermlist = termlist{new(term)}
// String prints the termlist exactly (without normalization).
func (xl termlist) String() string {
if len(xl) == 0 {
return "∅"
}
var buf bytes.Buffer
for i, x := range xl {
if i > 0 {
buf.WriteString(" | ")
}
buf.WriteString(x.String())
}
return buf.String()
}
// isEmpty reports whether the termlist xl represents the empty set of types.
func (xl termlist) isEmpty() bool {
// If there's a non-nil term, the entire list is not empty.
// If the termlist is in normal form, this requires at most
// one iteration.
for _, x := range xl {
if x != nil {
return false
}
}
return true
}
// isAll reports whether the termlist xl represents the set of all types.
func (xl termlist) isAll() bool {
// If there's a 𝓤 term, the entire list is 𝓤.
// If the termlist is in normal form, this requires at most
// one iteration.
for _, x := range xl {
if x != nil && x.typ == nil {
return true
}
}
return false
}
// norm returns the normal form of xl.
func (xl termlist) norm() termlist {
// Quadratic algorithm, but good enough for now.
// TODO(gri) fix asymptotic performance
used := make([]bool, len(xl))
var rl termlist
for i, xi := range xl {
if xi == nil || used[i] {
continue
}
for j := i + 1; j < len(xl); j++ {
xj := xl[j]
if xj == nil || used[j] {
continue
}
if u1, u2 := xi.union(xj); u2 == nil {
// If we encounter a 𝓤 term, the entire list is 𝓤.
// Exit early.
// (Note that this is not just an optimization;
// if we continue, we may end up with a 𝓤 term
// and other terms and the result would not be
// in normal form.)
if u1.typ == nil {
return allTermlist
}
xi = u1
used[j] = true // xj is now unioned into xi - ignore it in future iterations
}
}
rl = append(rl, xi)
}
return rl
}
// union returns the union xl ∪ yl.
func (xl termlist) union(yl termlist) termlist {
return append(xl, yl...).norm()
}
// intersect returns the intersection xl ∩ yl.
func (xl termlist) intersect(yl termlist) termlist {
if xl.isEmpty() || yl.isEmpty() {
return nil
}
// Quadratic algorithm, but good enough for now.
// TODO(gri) fix asymptotic performance
var rl termlist
for _, x := range xl {
for _, y := range yl {
if r := x.intersect(y); r != nil {
rl = append(rl, r)
}
}
}
return rl.norm()
}
// equal reports whether xl and yl represent the same type set.
func (xl termlist) equal(yl termlist) bool {
// TODO(gri) this should be more efficient
return xl.subsetOf(yl) && yl.subsetOf(xl)
}
// includes reports whether t ∈ xl.
func (xl termlist) includes(t types.Type) bool {
for _, x := range xl {
if x.includes(t) {
return true
}
}
return false
}
// supersetOf reports whether y ⊆ xl.
func (xl termlist) supersetOf(y *term) bool {
for _, x := range xl {
if y.subsetOf(x) {
return true
}
}
return false
}
// subsetOf reports whether xl ⊆ yl.
func (xl termlist) subsetOf(yl termlist) bool {
if yl.isEmpty() {
return xl.isEmpty()
}
// each term x of xl must be a subset of yl
for _, x := range xl {
if !yl.supersetOf(x) {
return false // x is not a subset yl
}
}
return true
}

View File

@ -1,197 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.18
// +build !go1.18
package typeparams
import (
"go/ast"
"go/token"
"go/types"
)
func unsupported() {
panic("type parameters are unsupported at this go version")
}
// IndexListExpr is a placeholder type, as type parameters are not supported at
// this Go version. Its methods panic on use.
type IndexListExpr struct {
ast.Expr
X ast.Expr // expression
Lbrack token.Pos // position of "["
Indices []ast.Expr // index expressions
Rbrack token.Pos // position of "]"
}
// ForTypeSpec returns an empty field list, as type parameters on not supported
// at this Go version.
func ForTypeSpec(*ast.TypeSpec) *ast.FieldList {
return nil
}
// ForFuncType returns an empty field list, as type parameters are not
// supported at this Go version.
func ForFuncType(*ast.FuncType) *ast.FieldList {
return nil
}
// TypeParam is a placeholder type, as type parameters are not supported at
// this Go version. Its methods panic on use.
type TypeParam struct{ types.Type }
func (*TypeParam) Index() int { unsupported(); return 0 }
func (*TypeParam) Constraint() types.Type { unsupported(); return nil }
func (*TypeParam) Obj() *types.TypeName { unsupported(); return nil }
// TypeParamList is a placeholder for an empty type parameter list.
type TypeParamList struct{}
func (*TypeParamList) Len() int { return 0 }
func (*TypeParamList) At(int) *TypeParam { unsupported(); return nil }
// TypeList is a placeholder for an empty type list.
type TypeList struct{}
func (*TypeList) Len() int { return 0 }
func (*TypeList) At(int) types.Type { unsupported(); return nil }
// NewTypeParam is unsupported at this Go version, and panics.
func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam {
unsupported()
return nil
}
// SetTypeParamConstraint is unsupported at this Go version, and panics.
func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type) {
unsupported()
}
// NewSignatureType calls types.NewSignature, panicking if recvTypeParams or
// typeParams is non-empty.
func NewSignatureType(recv *types.Var, recvTypeParams, typeParams []*TypeParam, params, results *types.Tuple, variadic bool) *types.Signature {
if len(recvTypeParams) != 0 || len(typeParams) != 0 {
panic("signatures cannot have type parameters at this Go version")
}
return types.NewSignature(recv, params, results, variadic)
}
// ForSignature returns an empty slice.
func ForSignature(*types.Signature) *TypeParamList {
return nil
}
// RecvTypeParams returns a nil slice.
func RecvTypeParams(sig *types.Signature) *TypeParamList {
return nil
}
// IsComparable returns false, as no interfaces are type-restricted at this Go
// version.
func IsComparable(*types.Interface) bool {
return false
}
// IsMethodSet returns true, as no interfaces are type-restricted at this Go
// version.
func IsMethodSet(*types.Interface) bool {
return true
}
// IsImplicit returns false, as no interfaces are implicit at this Go version.
func IsImplicit(*types.Interface) bool {
return false
}
// MarkImplicit does nothing, because this Go version does not have implicit
// interfaces.
func MarkImplicit(*types.Interface) {}
// ForNamed returns an empty type parameter list, as type parameters are not
// supported at this Go version.
func ForNamed(*types.Named) *TypeParamList {
return nil
}
// SetForNamed panics if tparams is non-empty.
func SetForNamed(_ *types.Named, tparams []*TypeParam) {
if len(tparams) > 0 {
unsupported()
}
}
// NamedTypeArgs returns nil.
func NamedTypeArgs(*types.Named) *TypeList {
return nil
}
// NamedTypeOrigin is the identity method at this Go version.
func NamedTypeOrigin(named *types.Named) *types.Named {
return named
}
// Term holds information about a structural type restriction.
type Term struct {
tilde bool
typ types.Type
}
func (m *Term) Tilde() bool { return m.tilde }
func (m *Term) Type() types.Type { return m.typ }
func (m *Term) String() string {
pre := ""
if m.tilde {
pre = "~"
}
return pre + m.typ.String()
}
// NewTerm is unsupported at this Go version, and panics.
func NewTerm(tilde bool, typ types.Type) *Term {
return &Term{tilde, typ}
}
// Union is a placeholder type, as type parameters are not supported at this Go
// version. Its methods panic on use.
type Union struct{ types.Type }
func (*Union) Len() int { return 0 }
func (*Union) Term(i int) *Term { unsupported(); return nil }
// NewUnion is unsupported at this Go version, and panics.
func NewUnion(terms []*Term) *Union {
unsupported()
return nil
}
// InitInstanceInfo is a noop at this Go version.
func InitInstanceInfo(*types.Info) {}
// Instance is a placeholder type, as type parameters are not supported at this
// Go version.
type Instance struct {
TypeArgs *TypeList
Type types.Type
}
// GetInstances returns a nil map, as type parameters are not supported at this
// Go version.
func GetInstances(info *types.Info) map[*ast.Ident]Instance { return nil }
// Context is a placeholder type, as type parameters are not supported at
// this Go version.
type Context struct{}
// NewContext returns a placeholder Context instance.
func NewContext() *Context {
return &Context{}
}
// Instantiate is unsupported on this Go version, and panics.
func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
unsupported()
return nil, nil
}

View File

@ -1,151 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package typeparams
import (
"go/ast"
"go/types"
)
// IndexListExpr is an alias for ast.IndexListExpr.
type IndexListExpr = ast.IndexListExpr
// ForTypeSpec returns n.TypeParams.
func ForTypeSpec(n *ast.TypeSpec) *ast.FieldList {
if n == nil {
return nil
}
return n.TypeParams
}
// ForFuncType returns n.TypeParams.
func ForFuncType(n *ast.FuncType) *ast.FieldList {
if n == nil {
return nil
}
return n.TypeParams
}
// TypeParam is an alias for types.TypeParam
type TypeParam = types.TypeParam
// TypeParamList is an alias for types.TypeParamList
type TypeParamList = types.TypeParamList
// TypeList is an alias for types.TypeList
type TypeList = types.TypeList
// NewTypeParam calls types.NewTypeParam.
func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam {
return types.NewTypeParam(name, constraint)
}
// SetTypeParamConstraint calls tparam.SetConstraint(constraint).
func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type) {
tparam.SetConstraint(constraint)
}
// NewSignatureType calls types.NewSignatureType.
func NewSignatureType(recv *types.Var, recvTypeParams, typeParams []*TypeParam, params, results *types.Tuple, variadic bool) *types.Signature {
return types.NewSignatureType(recv, recvTypeParams, typeParams, params, results, variadic)
}
// ForSignature returns sig.TypeParams()
func ForSignature(sig *types.Signature) *TypeParamList {
return sig.TypeParams()
}
// RecvTypeParams returns sig.RecvTypeParams().
func RecvTypeParams(sig *types.Signature) *TypeParamList {
return sig.RecvTypeParams()
}
// IsComparable calls iface.IsComparable().
func IsComparable(iface *types.Interface) bool {
return iface.IsComparable()
}
// IsMethodSet calls iface.IsMethodSet().
func IsMethodSet(iface *types.Interface) bool {
return iface.IsMethodSet()
}
// IsImplicit calls iface.IsImplicit().
func IsImplicit(iface *types.Interface) bool {
return iface.IsImplicit()
}
// MarkImplicit calls iface.MarkImplicit().
func MarkImplicit(iface *types.Interface) {
iface.MarkImplicit()
}
// ForNamed extracts the (possibly empty) type parameter object list from
// named.
func ForNamed(named *types.Named) *TypeParamList {
return named.TypeParams()
}
// SetForNamed sets the type params tparams on n. Each tparam must be of
// dynamic type *types.TypeParam.
func SetForNamed(n *types.Named, tparams []*TypeParam) {
n.SetTypeParams(tparams)
}
// NamedTypeArgs returns named.TypeArgs().
func NamedTypeArgs(named *types.Named) *TypeList {
return named.TypeArgs()
}
// NamedTypeOrigin returns named.Orig().
func NamedTypeOrigin(named *types.Named) *types.Named {
return named.Origin()
}
// Term is an alias for types.Term.
type Term = types.Term
// NewTerm calls types.NewTerm.
func NewTerm(tilde bool, typ types.Type) *Term {
return types.NewTerm(tilde, typ)
}
// Union is an alias for types.Union
type Union = types.Union
// NewUnion calls types.NewUnion.
func NewUnion(terms []*Term) *Union {
return types.NewUnion(terms)
}
// InitInstanceInfo initializes info to record information about type and
// function instances.
func InitInstanceInfo(info *types.Info) {
info.Instances = make(map[*ast.Ident]types.Instance)
}
// Instance is an alias for types.Instance.
type Instance = types.Instance
// GetInstances returns info.Instances.
func GetInstances(info *types.Info) map[*ast.Ident]Instance {
return info.Instances
}
// Context is an alias for types.Context.
type Context = types.Context
// NewContext calls types.NewContext.
func NewContext() *Context {
return types.NewContext()
}
// Instantiate calls types.Instantiate.
func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
return types.Instantiate(ctxt, typ, targs, validate)
}

View File

@ -1,169 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Code generated by copytermlist.go DO NOT EDIT.
package typeparams
import "go/types"
// A term describes elementary type sets:
//
// ∅: (*term)(nil) == ∅ // set of no types (empty set)
// 𝓤: &term{} == 𝓤 // set of all types (𝓤niverse)
// T: &term{false, T} == {T} // set of type T
// ~t: &term{true, t} == {t' | under(t') == t} // set of types with underlying type t
type term struct {
tilde bool // valid if typ != nil
typ types.Type
}
func (x *term) String() string {
switch {
case x == nil:
return "∅"
case x.typ == nil:
return "𝓤"
case x.tilde:
return "~" + x.typ.String()
default:
return x.typ.String()
}
}
// equal reports whether x and y represent the same type set.
func (x *term) equal(y *term) bool {
// easy cases
switch {
case x == nil || y == nil:
return x == y
case x.typ == nil || y.typ == nil:
return x.typ == y.typ
}
// ∅ ⊂ x, y ⊂ 𝓤
return x.tilde == y.tilde && types.Identical(x.typ, y.typ)
}
// union returns the union x ∪ y: zero, one, or two non-nil terms.
func (x *term) union(y *term) (_, _ *term) {
// easy cases
switch {
case x == nil && y == nil:
return nil, nil // ∅ ∪ ∅ == ∅
case x == nil:
return y, nil // ∅ ∪ y == y
case y == nil:
return x, nil // x ∪ ∅ == x
case x.typ == nil:
return x, nil // 𝓤 ∪ y == 𝓤
case y.typ == nil:
return y, nil // x ∪ 𝓤 == 𝓤
}
// ∅ ⊂ x, y ⊂ 𝓤
if x.disjoint(y) {
return x, y // x ∪ y == (x, y) if x ∩ y == ∅
}
// x.typ == y.typ
// ~t ∪ ~t == ~t
// ~t ∪ T == ~t
// T ∪ ~t == ~t
// T ∪ T == T
if x.tilde || !y.tilde {
return x, nil
}
return y, nil
}
// intersect returns the intersection x ∩ y.
func (x *term) intersect(y *term) *term {
// easy cases
switch {
case x == nil || y == nil:
return nil // ∅ ∩ y == ∅ and ∩ ∅ == ∅
case x.typ == nil:
return y // 𝓤 ∩ y == y
case y.typ == nil:
return x // x ∩ 𝓤 == x
}
// ∅ ⊂ x, y ⊂ 𝓤
if x.disjoint(y) {
return nil // x ∩ y == ∅ if x ∩ y == ∅
}
// x.typ == y.typ
// ~t ∩ ~t == ~t
// ~t ∩ T == T
// T ∩ ~t == T
// T ∩ T == T
if !x.tilde || y.tilde {
return x
}
return y
}
// includes reports whether t ∈ x.
func (x *term) includes(t types.Type) bool {
// easy cases
switch {
case x == nil:
return false // t ∈ ∅ == false
case x.typ == nil:
return true // t ∈ 𝓤 == true
}
// ∅ ⊂ x ⊂ 𝓤
u := t
if x.tilde {
u = under(u)
}
return types.Identical(x.typ, u)
}
// subsetOf reports whether x ⊆ y.
func (x *term) subsetOf(y *term) bool {
// easy cases
switch {
case x == nil:
return true // ∅ ⊆ y == true
case y == nil:
return false // x ⊆ ∅ == false since x != ∅
case y.typ == nil:
return true // x ⊆ 𝓤 == true
case x.typ == nil:
return false // 𝓤 ⊆ y == false since y != 𝓤
}
// ∅ ⊂ x, y ⊂ 𝓤
if x.disjoint(y) {
return false // x ⊆ y == false if x ∩ y == ∅
}
// x.typ == y.typ
// ~t ⊆ ~t == true
// ~t ⊆ T == false
// T ⊆ ~t == true
// T ⊆ T == true
return !x.tilde || y.tilde
}
// disjoint reports whether x ∩ y == ∅.
// x.typ and y.typ must not be nil.
func (x *term) disjoint(y *term) bool {
if debug && (x.typ == nil || y.typ == nil) {
panic("invalid argument(s)")
}
ux := x.typ
if y.tilde {
ux = under(ux)
}
uy := y.typ
if x.tilde {
uy = under(uy)
}
return !types.Identical(ux, uy)
}

15
vendor/modules.txt vendored
View File

@ -1,14 +1,14 @@
# github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792
## explicit; go 1.13
github.com/ManyakRus/logrus
# github.com/ManyakRus/starter v0.0.0-20231128073137-db11116c6e48
# github.com/ManyakRus/starter v0.0.0-20231227074038-f1cc2e5171fa
## explicit; go 1.20
github.com/ManyakRus/starter/config
github.com/ManyakRus/starter/config_main
github.com/ManyakRus/starter/contextmain
github.com/ManyakRus/starter/log
github.com/ManyakRus/starter/logger
github.com/ManyakRus/starter/micro
github.com/ManyakRus/starter/ping
github.com/ManyakRus/starter/port_checker
github.com/ManyakRus/starter/postgres_gorm
github.com/ManyakRus/starter/stopapp
# github.com/bxcodec/faker/v3 v3.8.1
@ -24,10 +24,10 @@ github.com/iancoleman/strcase
# github.com/jackc/pgpassfile v1.0.0
## explicit; go 1.12
github.com/jackc/pgpassfile
# github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a
# github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9
## explicit; go 1.14
github.com/jackc/pgservicefile
# github.com/jackc/pgx/v5 v5.5.0
# github.com/jackc/pgx/v5 v5.5.1
## explicit; go 1.19
github.com/jackc/pgx/v5
github.com/jackc/pgx/v5/internal/anynil
@ -70,7 +70,7 @@ github.com/otiai10/copy
# github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e
## explicit
github.com/serenize/snaker
# golang.org/x/crypto v0.16.0
# golang.org/x/crypto v0.17.0
## explicit; go 1.18
golang.org/x/crypto/pbkdf2
# golang.org/x/mod v0.14.0
@ -101,7 +101,7 @@ golang.org/x/text/transform
golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm
golang.org/x/text/width
# golang.org/x/tools v0.16.0
# golang.org/x/tools v0.16.1
## explicit; go 1.18
golang.org/x/tools/go/ast/astutil
golang.org/x/tools/imports
@ -113,7 +113,6 @@ golang.org/x/tools/internal/event/tag
golang.org/x/tools/internal/gocommand
golang.org/x/tools/internal/gopathwalk
golang.org/x/tools/internal/imports
golang.org/x/tools/internal/typeparams
# gorm.io/driver/postgres v1.5.4
## explicit; go 1.18
gorm.io/driver/postgres