serve.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright © 2018 NAME HERE <EMAIL ADDRESS>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package cmd
  15. import (
  16. "git.riomhaire.com/gremlin/jrpcserver/infrastructure/api/rpc"
  17. "git.riomhaire.com/gremlin/jrpcserver/model"
  18. "git.riomhaire.com/gremlin/jrpcserver/usecases"
  19. "github.com/spf13/cobra"
  20. )
  21. var configPort int
  22. var configServicename string
  23. var configConsul string
  24. var configHost string
  25. // serveCmd represents the serve command
  26. var serveCmd = &cobra.Command{
  27. Use: "serve",
  28. Short: "Starts up a JSON RPC Service",
  29. Run: func(cmd *cobra.Command, args []string) {
  30. config := model.DefaultConfiguration{
  31. Server: model.ServerConfig{
  32. ServiceName: cmd.Flag("servicename").Value.String(),
  33. BaseURI: "/api/v1/rpc",
  34. Port: configPort,
  35. Commands: usecases.InitializeCommands(),
  36. Version: usecases.Version(),
  37. Consul: configConsul,
  38. Hostname: configHost,
  39. },
  40. }
  41. rpc.StartAPI(config) // Wont return
  42. },
  43. }
  44. func init() {
  45. rootCmd.AddCommand(serveCmd)
  46. serveCmd.Flags().IntVarP(&configPort, "port", "p", 3000, "Port to run on")
  47. serveCmd.Flags().StringVarP(&configServicename, "servicename", "s", "git.riomhaire.com/gremlin/jrpcserver", "Name of service")
  48. serveCmd.Flags().StringVarP(&configConsul, "consul", "c", "", "Consul host. Empty means dont use")
  49. serveCmd.Flags().StringVarP(&configHost, "host", "b", "", "Interface/hostname to bind to")
  50. }