Ver Fonte

Fixed various issues including package name

tag 1.1.1
gremlin há 10 meses atrás
pai
commit
fce938c19e

+ 0 - 2
examples/helloworld/calls.rest

@@ -12,5 +12,3 @@ GET http://localhost:9999/metrics
 ###
 
 GET http://localhost:9999/health
-
-###

+ 4 - 4
examples/helloworld/helloworld.go

@@ -8,10 +8,10 @@ import (
 	"io"
 	"io/ioutil"
 
-	"jrpcserver/infrastructure/api/rpc"
-	"jrpcserver/model"
-	"jrpcserver/model/jrpcerror"
-	"jrpcserver/usecases/defaultcommand"
+	"git.riomhaire.com/gremlin/jrpcserver/infrastructure/api/rpc"
+	"git.riomhaire.com/gremlin/jrpcserver/model"
+	"git.riomhaire.com/gremlin/jrpcserver/model/jrpcerror"
+	"git.riomhaire.com/gremlin/jrpcserver/usecases/defaultcommand"
 )
 
 // A simple example 'helloworld' program to show how use the framework

+ 1 - 1
go.mod

@@ -1,4 +1,4 @@
-module jrpcserver
+module git.riomhaire.com/gremlin/jrpcserver
 
 go 1.21.5
 

+ 1 - 1
infrastructure/api/rpc/dispatcher.go

@@ -3,7 +3,7 @@ package rpc
 import (
 	"io"
 
-	"jrpcserver/model"
+	"git.riomhaire.com/gremlin/jrpcserver/model"
 )
 
 type Dispatcher struct {

+ 3 - 3
infrastructure/api/rpc/rpc.go

@@ -17,9 +17,9 @@ import (
 	lSyslog "github.com/sirupsen/logrus/hooks/syslog"
 	"github.com/urfave/negroni"
 
-	"jrpcserver/infrastructure/serviceregistry"
-	"jrpcserver/infrastructure/serviceregistry/consulagent"
-	"jrpcserver/infrastructure/serviceregistry/none"
+	"git.riomhaire.com/gremlin/jrpcserver/infrastructure/serviceregistry"
+	"git.riomhaire.com/gremlin/jrpcserver/infrastructure/serviceregistry/consulagent"
+	"git.riomhaire.com/gremlin/jrpcserver/infrastructure/serviceregistry/none"
 )
 
 var dispatcher *Dispatcher

+ 83 - 0
infrastructure/application/cmd/root.go

@@ -0,0 +1,83 @@
+// Copyright © 2018 NAME HERE <EMAIL ADDRESS>
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cmd
+
+import (
+	"log"
+	"os"
+
+	homedir "github.com/mitchellh/go-homedir"
+	"github.com/spf13/cobra"
+	"github.com/spf13/viper"
+)
+
+var cfgFile string
+
+// rootCmd represents the base command when called without any subcommands
+var rootCmd = &cobra.Command{
+	Use:   "jrpcserver",
+	Short: "A simple rpc server",
+	// Uncomment the following line if your bare application
+	// has an action associated with it:
+	//	Run: func(cmd *cobra.Command, args []string) { },
+}
+
+// Execute adds all child commands to the root command and sets flags appropriately.
+// This is called by main.main(). It only needs to happen once to the rootCmd.
+func Execute() {
+	if err := rootCmd.Execute(); err != nil {
+		log.Println(err)
+		os.Exit(1)
+	}
+}
+
+func init() {
+	cobra.OnInitialize(initConfig)
+
+	// Here you will define your flags and configuration settings.
+	// Cobra supports persistent flags, which, if defined here,
+	// will be global for your application.
+	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.jrpcserver.yaml)")
+
+	// Cobra also supports local flags, which will only run
+	// when this action is called directly.
+	rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
+}
+
+// initConfig reads in config file and ENV variables if set.
+func initConfig() {
+	if cfgFile != "" {
+		// Use config file from the flag.
+		viper.SetConfigFile(cfgFile)
+	} else {
+		// Find home directory.
+		home, err := homedir.Dir()
+		if err != nil {
+			log.Println(err)
+			os.Exit(1)
+		}
+
+		// Search config in home directory with name ".jrpcserver" (without extension).
+		viper.AddConfigPath(home)
+		viper.SetConfigName(".jrpcserver")
+	}
+
+	viper.AutomaticEnv() // read in environment variables that match
+
+	// If a config file is found, read it in.
+	if err := viper.ReadInConfig(); err == nil {
+		log.Println("Using config file:", viper.ConfigFileUsed())
+	}
+}

+ 58 - 0
infrastructure/application/cmd/serve.go

@@ -0,0 +1,58 @@
+// Copyright © 2018 NAME HERE <EMAIL ADDRESS>
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cmd
+
+import (
+	"git.riomhaire.com/gremlin/jrpcserver/infrastructure/api/rpc"
+	"git.riomhaire.com/gremlin/jrpcserver/model"
+	"git.riomhaire.com/gremlin/jrpcserver/usecases"
+
+	"github.com/spf13/cobra"
+)
+
+var configPort int
+var configServicename string
+var configConsul string
+var configHost string
+
+// serveCmd represents the serve command
+var serveCmd = &cobra.Command{
+	Use:   "serve",
+	Short: "Starts up a JSON RPC Service",
+	Run: func(cmd *cobra.Command, args []string) {
+
+		config := model.DefaultConfiguration{
+			Server: model.ServerConfig{
+				ServiceName: cmd.Flag("servicename").Value.String(),
+				BaseURI:     "/api/v1/rpc",
+				Port:        configPort,
+				Commands:    usecases.InitializeCommands(),
+				Version:     usecases.Version(),
+				Consul:      configConsul,
+				Hostname:    configHost,
+			},
+		}
+		rpc.StartAPI(config) // Wont return
+	},
+}
+
+func init() {
+	rootCmd.AddCommand(serveCmd)
+	serveCmd.Flags().IntVarP(&configPort, "port", "p", 3000, "Port to run on")
+	serveCmd.Flags().StringVarP(&configServicename, "servicename", "s", "git.riomhaire.com/gremlin/jrpcserver", "Name of service")
+	serveCmd.Flags().StringVarP(&configConsul, "consul", "c", "", "Consul host. Empty means dont use")
+	serveCmd.Flags().StringVarP(&configHost, "host", "b", "", "Interface/hostname to bind to")
+
+}

+ 36 - 0
infrastructure/application/cmd/version.go

@@ -0,0 +1,36 @@
+// Copyright © 2018 NAME HERE <EMAIL ADDRESS>
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cmd
+
+import (
+	log "github.com/sirupsen/logrus"
+
+	"git.riomhaire.com/gremlin/jrpcserver/usecases"
+
+	"github.com/spf13/cobra"
+)
+
+// versionCmd represents the version command
+var versionCmd = &cobra.Command{
+	Use:   "version",
+	Short: "Displays which version of application this is",
+	Run: func(cmd *cobra.Command, args []string) {
+		log.Println(usecases.Version())
+	},
+}
+
+func init() {
+	rootCmd.AddCommand(versionCmd)
+}

+ 21 - 0
infrastructure/application/jrpcserver.go

@@ -0,0 +1,21 @@
+// Copyright © 2018 NAME HERE <EMAIL ADDRESS>
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import "git.riomhaire.com/gremlin/jrpcserver/infrastructure/application/cmd"
+
+func main() {
+	cmd.Execute()
+}

+ 4 - 4
makefile

@@ -7,8 +7,8 @@ dependencies:
 build: dependencies
 	@echo Compiling Apps
 	@echo   --- jrpcserver 
-	@go build jrpcserver/infrastructure/application/riomhaire/jrpcserver
-	@go install jrpcserver/infrastructure/application/riomhaire/jrpcserver
+	@go build infrastructure/application/jrpcserver.go
+	@go install infrastructure/application/jrpcserver.go
 	@echo Done Compiling Apps
 
 test:
@@ -24,6 +24,6 @@ everything: clean build test
 	@echo Done
 
 devrun: 
-	@cd infrastructure/application/riomhaire/jrpcserver
-	@go run main.go
+	@cd infrastructure/application
+	@go run jrpcserver.go
 

+ 1 - 1
model/rpccommand.go

@@ -3,7 +3,7 @@ package model
 import (
 	"io"
 
-	"jrpcserver/model/jrpcerror"
+	"git.riomhaire.com/gremlin/jrpcserver/model/jrpcerror"
 )
 
 // TODO: Schema

+ 2 - 2
usecases/defaultcommand/commands.go

@@ -6,8 +6,8 @@ import (
 	"io"
 	"io/ioutil"
 
-	"jrpcserver/model"
-	"jrpcserver/model/jrpcerror"
+	"git.riomhaire.com/gremlin/jrpcserver/model"
+	"git.riomhaire.com/gremlin/jrpcserver/model/jrpcerror"
 )
 
 func PingCommand(config interface{}, metadata map[string]string, payload io.ReadCloser) (interface{}, jrpcerror.JrpcError) {

+ 2 - 2
usecases/initialize.go

@@ -1,8 +1,8 @@
 package usecases
 
 import (
-	"jrpcserver/model"
-	"jrpcserver/usecases/defaultcommand"
+	"git.riomhaire.com/gremlin/jrpcserver/model"
+	"git.riomhaire.com/gremlin/jrpcserver/usecases/defaultcommand"
 )
 
 var Commands []model.JRPCCommand