Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created Oct 7, 2018
Embed
What would you like to do?
Golang cobra example
package cmd
import (
"log"
"os"
server "github.com/org/app/server"
"github.com/spf13/cobra"
)
// Start ...
func Start() {
var (
nodeURL string
contractAddress string
)
rootCmd := &cobra.Command{
Use: "app",
}
startCmd := &cobra.Command{
Use: "start",
Short: "Start the server",
Long: "Start the server",
Run: func(cmd *cobra.Command, args []string) {
svr := server.NewServer(&server.Config{
NodeURL: nodeURL,
ContractAddress: contractAddress,
})
svr.Start()
},
}
startCmd.Flags().StringVarP(&contractAddress, "address", "a", "", "contract address")
startCmd.Flags().StringVarP(&nodeURL, "node-url", "u", "", "node url")
rootCmd.AddCommand(startCmd)
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
os.Exit(1)
}
}
go run main.go start --node-url "https://kovan.infura.io" --address "0xcfbded0bbf3726a056b1d9458308dd338e9eea63"
package main
import (
"github.com/org/app/cmd"
)
func main() {
cmd.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment