Skip to content

Commit

Permalink
Merge pull request #5 from jerry-enebeli/feature/service
Browse files Browse the repository at this point in the history
Feature/service
  • Loading branch information
jerry-enebeli authored Sep 6, 2020
2 parents d85df1c + d6af7b5 commit 5c15ab3
Show file tree
Hide file tree
Showing 10 changed files with 591 additions and 17 deletions.
7 changes: 7 additions & 0 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/jerry-enebeli/grpc-rest-gateway/cmd/gateway"

func main() {
gateway.Execute()
}
7 changes: 0 additions & 7 deletions cmd/gateway/main.go

This file was deleted.

73 changes: 73 additions & 0 deletions cmd/gateway/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package gateway

import (
"fmt"
"github.com/jerry-enebeli/grpc-rest-gateway/pkg/service"
"github.com/jerry-enebeli/grpc-rest-gateway/tools"
"github.com/spf13/cobra"
"log"
"os"
)

var sourceProtoFile string

var s = service.NewService()

var rootCmd = &cobra.Command{
Use: "Gateway",
Short: "gRPC to REST",
Long: `Gateway is a api gateway for gRPC application. gateway maps RESTFUL API to gRPC services.Complete documentation is available at https://github.com/jerry-enebeli/grpc-rest-gateway`,
Run: func(cmd *cobra.Command, args []string) {
output, _ := tools.Shell("bash", "gateway --help")

log.Println(output)
},
}

var serviceCmd = &cobra.Command{
Use: "service",
Short: "manages gRPC services",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("got this", args)
},
}

var serviceListCmd = &cobra.Command{
Use: "list",
Short: "list gRPC services",
Run: func(cmd *cobra.Command, args []string) {
s.GetAllServices()
},
}

var serviceListMethodsCmd = &cobra.Command{
Use: "list-methods",
Short: "list gRPC services methods",
Example: "Gateway service list-methods [service name]",
ValidArgs: []string{"test"},
Run: func(cmd *cobra.Command, args []string) {
s.GetServiceMethods(args[0])
},
}

var serviceCreateCmd = &cobra.Command{
Use: "create",
Short: "create new gRPC services",
Run: func(cmd *cobra.Command, args []string) {
s.CreateService(sourceProtoFile)
},
}

func addServiceCreateFlags() {
serviceCreateCmd.Flags().StringVarP(&sourceProtoFile, "source", "s", "", "Source directory to read proto file from")
}

func Execute() {
addServiceCreateFlags()
serviceCmd.AddCommand(serviceCreateCmd, serviceListCmd, serviceListMethodsCmd)
rootCmd.AddCommand(serviceCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
53 changes: 53 additions & 0 deletions examples/helloworld/test2.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";

package platphom;

// The greeting service definition.
service User {
// Sends a greeting
rpc Login (HelloRequest) returns (HelloReply) {}
rpc Signup (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module github.com/jerry-enebeli/grpc-rest-gateway
go 1.14

require (
github.com/golang/protobuf v1.3.4
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
github.com/golang/protobuf v1.4.2
github.com/jerry-enebeli/proto-parser v0.0.0-20200905173001-3799ff2e04ac
github.com/mitchellh/mapstructure v1.1.2
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra/cobra v0.0.0-20200826151851-02a0d2fbc9e6 // indirect
go.etcd.io/bbolt v1.3.5
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
google.golang.org/grpc v1.27.1
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)
Loading

0 comments on commit 5c15ab3

Please sign in to comment.