Skip to content

Commit e9738b5

Browse files
feat: added mongodb integration for go-grpc-server
1 parent 7dcf646 commit e9738b5

File tree

7 files changed

+309
-138
lines changed

7 files changed

+309
-138
lines changed

core/internal/languages/golang/frameworks/common-files/copier.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type clientData struct {
5757
SourceNodeID string
5858
}
5959

60-
func NewCopier(userName, repositoryName, nodeName, nodeDirectoryName, templatesRootPath string, isRestServer bool, restServerPort string, isGrpcServer bool, grpcServerPort string, isRestSQLDB bool, restSQLDB string, isGrpcSQLDB bool, grpcSQLDB string, restResources []*corenode.Resource, grpcResources []*corenode.Resource, restClients []*corenode.RestClient, grpcClients []*corenode.GrpcClient) *Copier {
60+
func NewCopier(userName, repositoryName, nodeName, nodeDirectoryName, templatesRootPath string, isRestServer bool, restServerPort string, isGrpcServer bool, grpcServerPort string, isRestSQLDB bool, restSQLDB string, isGrpcSQLDB bool, grpcSQLDB string, isRestNoSQLDB bool, restNoSQLDB string, isGrpcNoSQLDB bool, grpcNoSQLDB string, restResources []*corenode.Resource, grpcResources []*corenode.Resource, restClients []*corenode.RestClient, grpcClients []*corenode.GrpcClient) *Copier {
6161

6262
pluralizeClient := pluralize.NewClient()
6363

@@ -121,6 +121,16 @@ func NewCopier(userName, repositoryName, nodeName, nodeDirectoryName, templatesR
121121
data["GrpcSQLDB"] = grpcSQLDB
122122
}
123123

124+
data["IsRestNoSQLDB"] = isRestNoSQLDB
125+
if isRestNoSQLDB {
126+
data["RestNoSQLDB"] = restNoSQLDB
127+
}
128+
129+
data["IsGrpcNoSQLDB"] = isGrpcNoSQLDB
130+
if isGrpcNoSQLDB {
131+
data["GrpcNoSQLDB"] = grpcNoSQLDB
132+
}
133+
124134
return &Copier{
125135
TemplatesRootPath: templatesRootPath,
126136
NodeDirectoryName: nodeDirectoryName,

core/internal/languages/golang/frameworks/go-gin-server/copier.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ package goginserver
22

33
import (
44
"errors"
5+
"text/template"
6+
57
"github.com/gertd/go-pluralize"
68
"github.com/iancoleman/strcase"
79
corenode "github.com/intelops/compage/core/internal/core/node"
810
"github.com/intelops/compage/core/internal/languages/executor"
911
commonUtils "github.com/intelops/compage/core/internal/languages/utils"
1012
log "github.com/sirupsen/logrus"
11-
"text/template"
13+
14+
"strings"
1215

1316
"github.com/intelops/compage/core/internal/utils"
1417
"golang.org/x/text/cases"
1518
"golang.org/x/text/language"
16-
"strings"
1719
)
1820

1921
const RestServerPath = "/pkg/rest/server"
2022
const RestClientPath = "/pkg/rest/client"
2123

2224
const DaosPath = RestServerPath + "/daos"
2325
const SQLDBClientsPath = DaosPath + "/clients/sqls"
24-
const NOSQLDBClientsPath = DaosPath + "/clients/nosqls"
26+
const NoSQLDBClientsPath = DaosPath + "/clients/nosqls"
2527

2628
const ServicesPath = RestServerPath + "/services"
2729
const ControllersPath = RestServerPath + "/controllers"
@@ -161,17 +163,16 @@ func (c *Copier) createRestServerDirectories() error {
161163
log.Debugf("error creating daos directory: %v", err)
162164
return err
163165
}
164-
// create directories for every resource's db client.
165166
if c.IsSQLDB {
167+
// create directories for every resource's db client.
166168
sqlDBClientsDirectory := c.NodeDirectoryName + SQLDBClientsPath
167169
if err := utils.CreateDirectories(sqlDBClientsDirectory); err != nil {
168170
log.Debugf("error creating sql db clients directory: %v", err)
169171
return err
170172
}
171-
}
172-
// create directories for every resource's db client.
173-
if c.IsNoSQLDB {
174-
noSQLDBClientsDirectory := c.NodeDirectoryName + NOSQLDBClientsPath
173+
} else if c.IsNoSQLDB {
174+
// create directories for every resource's db client.
175+
noSQLDBClientsDirectory := c.NodeDirectoryName + NoSQLDBClientsPath
175176
if err := utils.CreateDirectories(noSQLDBClientsDirectory); err != nil {
176177
log.Debugf("error creating nosql db clients directory: %v", err)
177178
return err
@@ -556,44 +557,43 @@ func (c *Copier) CreateRestServer() error {
556557
return err
557558
}
558559
}
559-
// create sql db config file (common to all resources for specific database)
560-
// No vars in config file as of now but in future they may be there.
561560
if c.IsSQLDB {
561+
// create sql db config file (common to all resources for specific database)
562+
// No vars in config file as of now but in future they may be there.
562563
if c.SQLDB == SQLite {
563564
var filePaths []string
564565
// client files
565566
targetSQLiteConfigFileName := c.NodeDirectoryName + SQLDBClientsPath + "/" + SQLiteDBConfigFile
566-
_, err2 := utils.CopyFile(targetSQLiteConfigFileName, c.TemplatesRootPath+SQLDBClientsPath+"/"+SQLiteDBConfigFile)
567-
if err2 != nil {
568-
log.Debugf("error copying sqlite config file: %v", err2)
569-
return err2
567+
_, err := utils.CopyFile(targetSQLiteConfigFileName, c.TemplatesRootPath+SQLDBClientsPath+"/"+SQLiteDBConfigFile)
568+
if err != nil {
569+
log.Debugf("error copying sqlite config file: %v", err)
570+
return err
570571
}
571572
filePaths = append(filePaths, targetSQLiteConfigFileName)
572573
return executor.Execute(filePaths, c.Data)
573574
} else if c.SQLDB == MySQL {
574575
var filePaths []string
575576
// client files
576577
targetMySQLConfigFileName := c.NodeDirectoryName + SQLDBClientsPath + "/" + MySQLDBConfigFile
577-
_, err2 := utils.CopyFile(targetMySQLConfigFileName, c.TemplatesRootPath+SQLDBClientsPath+"/"+MySQLDBConfigFile)
578-
if err2 != nil {
579-
log.Debugf("error copying mysql config file: %v", err2)
580-
return err2
578+
_, err := utils.CopyFile(targetMySQLConfigFileName, c.TemplatesRootPath+SQLDBClientsPath+"/"+MySQLDBConfigFile)
579+
if err != nil {
580+
log.Debugf("error copying mysql config file: %v", err)
581+
return err
581582
}
582583
filePaths = append(filePaths, targetMySQLConfigFileName)
583584
return executor.Execute(filePaths, c.Data)
584585
}
585-
}
586-
// create nosql db config file (common to all resources for specific database)
587-
// No vars in config file as of now but in future they may be there.
588-
if c.IsNoSQLDB {
586+
} else if c.IsNoSQLDB {
587+
// create nosql db config file (common to all resources for specific database)
588+
// No vars in config file as of now but in future they may be there.
589589
if c.NoSQLDB == MongoDB {
590590
var filePaths []string
591591
// client files
592-
targetMongoDBConfigFileName := c.NodeDirectoryName + NOSQLDBClientsPath + "/" + MongoDBConfigFile
593-
_, err2 := utils.CopyFile(targetMongoDBConfigFileName, c.TemplatesRootPath+NOSQLDBClientsPath+"/"+MongoDBConfigFile)
594-
if err2 != nil {
595-
log.Debugf("error copying mongodb config file: %v", err2)
596-
return err2
592+
targetMongoDBConfigFileName := c.NodeDirectoryName + NoSQLDBClientsPath + "/" + MongoDBConfigFile
593+
_, err := utils.CopyFile(targetMongoDBConfigFileName, c.TemplatesRootPath+NoSQLDBClientsPath+"/"+MongoDBConfigFile)
594+
if err != nil {
595+
log.Debugf("error copying mongodb config file: %v", err)
596+
return err
597597
}
598598
filePaths = append(filePaths, targetMongoDBConfigFileName)
599599
return executor.Execute(filePaths, c.Data)

0 commit comments

Comments
 (0)