getGrpcServer function
Implementation
String getGrpcServer(
String name, {
int port = 8080,
}) {
var content = "import 'package:grpc/grpc.dart' as grpc;"
.add("import 'dart:io';")
.add("import 'service_list.dart';")
.add('')
.add('class Server {')
.add(' Future<void> main(List<String> args) async {')
.add(' final server = grpc.Server(')
.add(' getServices(),')
.add(' const <grpc.Interceptor>[],')
.add(' grpc.CodecRegistry(codecs: [grpc.GzipCodec()]),')
.add(' );')
.add(" var sPort = Platform.environment['PORT'];")
.add(' var port = $port;')
.add(' if ((sPort != null) && (sPort.isNotEmpty)) {')
.add(" print('sPort: \$sPort');")
.add(' port = int.parse(sPort);')
.add(' }')
.add(' await server.serve(port: port);')
.add(" print('Server listening on port \${server.port}...');")
.add(' }')
.add('}');
return content;
}