Skip to content

Commit

Permalink
Merge pull request #174 from intelops/generate-only-specified-methods
Browse files Browse the repository at this point in the history
feat: Generate code for selected methods for REST and GRPC in golang
  • Loading branch information
mahendraintelops authored Oct 30, 2023
2 parents 0e43621 + 7bfcdc6 commit 49d0f77
Show file tree
Hide file tree
Showing 138 changed files with 2,391 additions and 15,420 deletions.
248 changes: 91 additions & 157 deletions app/package-lock.json

Large diffs are not rendered by default.

29 changes: 13 additions & 16 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,35 @@
"keywords": [],
"license": "MIT",
"dependencies": {
"@grpc/grpc-js": "^1.9.5",
"@grpc/grpc-js": "^1.9.8",
"@grpc/proto-loader": "^0.7.10",
"@kubernetes/client-node": "^0.19.0",
"@types/body-parser": "^1.19.3",
"@types/express": "^4.17.18",
"@types/js-yaml": "^4.0.6",
"@types/morgan": "^1.9.6",
"@types/multer": "^1.4.8",
"@types/node": "^18.18.3",
"@types/ws": "^8.5.5",
"axios": "^1.5.1",
"@types/body-parser": "^1.19.4",
"@types/express": "^4.17.20",
"@types/morgan": "^1.9.7",
"@types/multer": "^1.4.9",
"@types/node": "^18.18.7",
"axios": "^1.6.0",
"cassandra-driver": "^4.7.2",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"helmet": "^7.0.0",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"nodemon": "^3.0.1",
"rimraf": "^5.0.1",
"rimraf": "^5.0.5",
"simple-git": "^3.20.0",
"sqlite3": "^5.1.6",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"uuid": "^9.0.0",
"winston": "^3.10.0"
"uuid": "^9.0.1",
"winston": "^3.11.0"
},
"devDependencies": {
"@types/jest": "^29.5.5",
"@types/react-redux-toastr": "^7.6.3",
"@types/supertest": "^2.0.12",
"@types/tar": "^6.1.6",
"@types/uuid": "^9.0.3",
"@types/supertest": "^2.0.15",
"@types/tar": "^6.1.7",
"@types/uuid": "^9.0.6",
"jest": "^29.7.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
Expand Down
1 change: 1 addition & 0 deletions app/src/models/code.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface Resource {
name: string;
allowedMethods: string[];
// the below map can contain metadata about the field.
fields: Map<string, FieldMetadata>;
}
Expand Down
30 changes: 15 additions & 15 deletions core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ require (
github.com/gertd/go-pluralize v0.2.1
github.com/iancoleman/strcase v0.3.0
github.com/sirupsen/logrus v1.9.3
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.44.0
go.opentelemetry.io/otel v1.18.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0
go.opentelemetry.io/otel/sdk v1.18.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
go.opentelemetry.io/otel/sdk v1.19.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/text v0.13.0
google.golang.org/grpc v1.58.1
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
)

require (
cloud.google.com/go/compute v1.23.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
)
32 changes: 32 additions & 0 deletions core/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cloud.google.com/go v0.110.7 h1:rJyC7nWRg2jWGZ4wSJ5nY65GTdYJkg0cd/uXb+ACI6o=
cloud.google.com/go v0.110.8 h1:tyNdfIxjzaWctIiLYOTalaLKZ17SI44SKFW26QbOhME=
cloud.google.com/go/compute v1.23.0 h1:tP41Zoavr8ptEqaW6j+LQOnyBBhO7OkOMAGrgLopTwY=
cloud.google.com/go/compute v1.23.0/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM=
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
Expand All @@ -17,10 +18,13 @@ github.com/gertd/go-pluralize v0.2.1/go.mod h1:rbYaKDbsXxmRfr8uygAEKhOWsjyrrqrkH
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE=
github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
Expand All @@ -41,44 +45,72 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.44.0 h1:b8xjZxHbLrXAum4SxJd1Rlm7Y/fKaB+6ACI7/e5EfSA=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.44.0/go.mod h1:1ei0a32xOGkFoySu7y1DAHfcuIhC0pNZpvY2huXuMy4=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 h1:RsQi0qJ2imFfCvZabqzM9cNXBG8k6gXMv1A0cXRmH6A=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0/go.mod h1:vsh3ySueQCiKPxFLvjWC4Z135gIa34TQ/NSqkDTZYUM=
go.opentelemetry.io/otel v1.18.0 h1:TgVozPGZ01nHyDZxK5WGPFB9QexeTMXEH7+tIClWfzs=
go.opentelemetry.io/otel v1.18.0/go.mod h1:9lWqYO0Db579XzVuCKFNPDl4s73Voa+zEck3wHaAYQI=
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 h1:IAtl+7gua134xcV3NieDhJHjjOVeJhXAnYf/0hswjUY=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0/go.mod h1:w+pXobnBzh95MNIkeIuAKcHe/Uu/CX2PKIvBP6ipKRA=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 h1:yE32ay7mJG2leczfREEhoW3VfSZIvHaB+gvVo1o8DQ8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0/go.mod h1:G17FHPDLt74bCI7tJ4CMitEk4BXTYG4FW6XUpkPBXa4=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 h1:3d+S281UTjM+AbF31XSOYn1qXn3BgIdWl8HNEpx08Jk=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0/go.mod h1:0+KuTDyKL4gjKCF75pHOX4wuzYDUZYfAQdSu43o+Z2I=
go.opentelemetry.io/otel/metric v1.18.0 h1:JwVzw94UYmbx3ej++CwLUQZxEODDj/pOuTCvzhtRrSQ=
go.opentelemetry.io/otel/metric v1.18.0/go.mod h1:nNSpsVDjWGfb7chbRLUNW+PBNdcSTHD4Uu5pfFMOI0k=
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
go.opentelemetry.io/otel/sdk v1.18.0 h1:e3bAB0wB3MljH38sHzpV/qWrOTCFrdZF2ct9F8rBkcY=
go.opentelemetry.io/otel/sdk v1.18.0/go.mod h1:1RCygWV7plY2KmdskZEDDBs4tJeHG92MdHZIluiYs/M=
go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o=
go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A=
go.opentelemetry.io/otel/trace v1.18.0 h1:NY+czwbHbmndxojTEKiSMHkG2ClNH2PwmcHrdo0JY10=
go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5nS8Mjvzckz+0=
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4=
golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY=
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4=
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a h1:fwgW9j3vHirt4ObdHoYNwuO24BEZjSzbh+zPaNWoiY8=
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:EMfReVxb80Dq1hhioy0sOsY9jCE46YDgHlJ7fWVUWRE=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k=
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb h1:Isk1sSH7bovx8Rti2wZK0UZF6oraBDK74uoyLEEVFN0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
google.golang.org/grpc v1.58.1 h1:OL+Vz23DTtrrldqHK49FUOPHyY75rvFqJfXC84NYW58=
google.golang.org/grpc v1.58.1/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
Expand Down
15 changes: 8 additions & 7 deletions core/internal/core/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Node struct {
type ConsumerData struct {
// Language node's(component) language.
Language string `json:"language"`
// Name of component (required, this will be service and deployment name).
// Name of a component (required, this will be service and deployment name).
Name string `json:"name"`
// RestConfig holds all config related to REST. If nil, it means that the node is not REST server or has REST clients.
RestConfig *RestConfig `json:"restConfig,omitempty"`
Expand All @@ -21,7 +21,7 @@ type ConsumerData struct {
WsConfig *WsConfig `json:"wsConfig,omitempty"`
// Metadata holds misc information about the node.
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Annotations holds annotations for the node.
// Annotations hold annotations for the node.
Annotations map[string]string `json:"annotations,omitempty"`
}

Expand All @@ -38,7 +38,7 @@ type RestClient struct {
SourceNodeName string `json:"sourceNodeName"`
SourceNodeID string `json:"sourceNodeId"`
Port string `json:"port"`
// below two keys are populated in language node and are used to create server's clients.
// The below given, two keys are populated in language node and are used to create server's clients.
Resources []*Resource `json:"resources"`
OpenAPIFileYamlContent string `json:"openAPIFileYamlContent,omitempty"`
}
Expand All @@ -63,7 +63,7 @@ type GrpcClient struct {
SourceNodeName string `json:"sourceNodeName"`
SourceNodeID string `json:"sourceNodeId"`
Port string `json:"port"`
// below two keys are populated in language node and are used to create server's clients.
// the below given, two keys are populated in language node and are used to create server's clients.
Resources []*Resource `json:"resources"`
ProtoFileContent string `json:"protoFileContent,omitempty"`
}
Expand All @@ -84,7 +84,7 @@ type WsClient struct {
SourceNodeName string `json:"sourceNodeName"`
SourceNodeID string `json:"sourceNodeId"`
Port string `json:"port"`
// below two keys are populated in language node and are used to create server's clients.
// the below given, two keys are populated in language node and are used to create server's clients.
Resources []Resource `json:"resources"`
}

Expand All @@ -102,7 +102,8 @@ type FieldMetadata struct {

// Resource depicts the endpoints(e.g. /users, /accounts)
type Resource struct {
Name string `json:"name"`
// resources fields (e.g. name, age in user)
Name string `json:"name"`
AllowedMethods []*string `json:"allowedMethods"`
// resource fields (e.g., name, age in user)
Fields map[string]FieldMetadata `json:"fields"`
}
38 changes: 14 additions & 24 deletions core/internal/languages/golang/frameworks/common-files/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/gertd/go-pluralize"
corenode "github.com/intelops/compage/core/internal/core/node"
"github.com/intelops/compage/core/internal/languages/executor"
"github.com/intelops/compage/core/internal/languages/golang/frameworks"
commonUtils "github.com/intelops/compage/core/internal/languages/utils"
"github.com/intelops/compage/core/internal/utils"
"golang.org/x/text/cases"
Expand Down Expand Up @@ -37,22 +38,6 @@ type Copier struct {
PluralizeClient *pluralize.Client
}

type restResourceData struct {
SmallResourceNameSingular string
SmallResourceNamePlural string
CapsResourceNameSingular string
CapsResourceNamePlural string
ResourcePostBody string
ResourcePutBody string
}

type grpcResourceData struct {
SmallResourceNameSingular string
SmallResourceNamePlural string
CapsResourceNameSingular string
CapsResourceNamePlural string
}

type clientData struct {
SourceNodeID string
}
Expand All @@ -69,33 +54,38 @@ func NewCopier(gitPlatformURL, gitPlatformUserName, gitRepositoryName, nodeName,
"GitPlatformURL": strings.Replace(gitPlatformURL, "https://", "", -1),
}
// set all grpcResources for main.go.tmpl
var grpcResourcesData []grpcResourceData
var grpcResourcesData []frameworks.GrpcResourceData
for _, r := range grpcResources {
grpcResourcesData = append(grpcResourcesData, grpcResourceData{
grpcResourceData := frameworks.GrpcResourceData{
SmallResourceNameSingular: strings.ToLower(r.Name),
SmallResourceNamePlural: pluralizeClient.Plural(strings.ToLower(r.Name)),
CapsResourceNameSingular: r.Name,
CapsResourceNamePlural: pluralizeClient.Plural(r.Name),
})
}
frameworks.AddGRPCAllowedMethods(&grpcResourceData, r.AllowedMethods)
grpcResourcesData = append(grpcResourcesData, grpcResourceData)
}

data["GrpcResources"] = grpcResourcesData
data["GrpcServerPort"] = grpcServerPort
data["IsGrpcServer"] = isGrpcServer
// if grpcClients slice has elements
HasGrpcClients := len(grpcClients) > 0
data["HasGrpcClients"] = HasGrpcClients

// set all grpcResources for main.go.tmpl
var restResourcesData []restResourceData
// set all restResources for main.go.tmpl
var restResourcesData []frameworks.RestResourceData
for _, r := range restResources {
restResourcesData = append(restResourcesData, restResourceData{
resourceData := frameworks.RestResourceData{
SmallResourceNameSingular: strings.ToLower(r.Name),
SmallResourceNamePlural: pluralizeClient.Plural(strings.ToLower(r.Name)),
CapsResourceNameSingular: r.Name,
CapsResourceNamePlural: pluralizeClient.Plural(r.Name),
ResourcePostBody: getResourcePostBody(r),
ResourcePutBody: getResourcePutBody(r),
})
}
frameworks.AddRESTAllowedMethods(&resourceData, r.AllowedMethods)
restResourcesData = append(restResourcesData, resourceData)
}
data["RestResources"] = restResourcesData
data["RestServerPort"] = restServerPort
Expand Down Expand Up @@ -189,7 +179,7 @@ func getResourcePutBody(r *corenode.Resource) string {
return putBody
}

// CreateCommonFiles creates/copies relevant files to generated project
// CreateCommonFiles creates/copies relevant files to a generated project
func (c Copier) CreateCommonFiles() error {
var filePaths []string
targetMainGoFileName := c.NodeDirectoryName + "/" + MainGoFile
Expand Down
Loading

0 comments on commit 49d0f77

Please sign in to comment.