Skip to content
Marcello DeSales edited this page Apr 25, 2022 · 6 revisions

Dev Environment

Getting Started

Considering your GO_PATH is ~/dev/go, setup each new project independently if needed:

$ ln -s ~/dev/github.com/marcellodesales/cloner ~/dev/go/src/github.com/marcellodesales/cloner

$ ls -la ~/dev/go/src/github.com/marcellodesales/cloner
lrwxr-xr-x  1 mdesales  CORP\Domain Users  55 Sep  4 10:46 
   /Users/marcellodesales/dev/go/src/github.com/marcellodesales/cloner ->
   /Users/marcellodesales/dev/github.com/marcellodesales/cloner

GOLand IDE Setup

Go Modules Setup

$ go run main.go init
build command-line-arguments: cannot load github.com/marcellodesales/cloner/cmd: 
      cannot find module providing package github.com/marcellodesales/cloner/cmd

We need to use Go Modules with newer versions as follows:

$ go mod init github.com/marcellodesales/cloner
go: creating new go.mod: module github.com/marcellodesales/cloner
  • Downloading dependencies
$ go mod download
go: finding github.com/spf13/viper v1.4.0
go: downloading github.com/spf13/viper v1.4.0
go: extracting github.com/spf13/viper v1.4.0
go: finding github.com/coreos/bbolt v1.3.2
go: finding github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
go: finding github.com/google/btree v1.0.0
go: finding github.com/prometheus/client_golang v0.9.3
go: finding github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5
go: finding github.com/jonboulle/clockwork v0.1.0
go: finding github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef
go: finding github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
go: finding github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
go: finding github.com/dgrijalva/jwt-go v3.2.0+incompatible
go: finding github.com/ugorji/go v1.1.4
go: finding github.com/gorilla/websocket v1.4.0
go: finding github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2
go: finding github.com/soheilhy/cmux v0.1.4
go: finding github.com/gogo/protobuf v1.2.1
go: finding github.com/grpc-ecosystem/grpc-gateway v1.9.0
go: finding github.com/prometheus/tsdb v0.7.1
go: finding github.com/beorn7/perks v1.0.0
go: finding golang.org/x/net v0.0.0-20190522155817-f3200d17e092
go: finding go.etcd.io/bbolt v1.3.2
go: finding golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
go: finding github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
go: finding github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084
go: finding github.com/prometheus/common v0.4.0
go: finding github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
go: finding github.com/go-logfmt/logfmt v0.4.0
go: finding github.com/kr/pretty v0.1.0
go: finding gopkg.in/resty.v1 v1.12.0
go: finding gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7
go: finding github.com/cespare/xxhash v1.1.0
go: finding github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d
go: finding github.com/go-kit/kit v0.8.0
go: finding github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
go: finding gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
go: finding github.com/go-stack/stack v1.8.0
go: finding github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af
go: finding github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954
go: finding github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc
go: finding gopkg.in/yaml.v2 v2.2.1
go: finding github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
go: finding github.com/julienschmidt/httprouter v1.2.0
go: finding github.com/OneOfOne/xxhash v1.2.2
go: finding golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
go: finding google.golang.org/grpc v1.19.0
go: finding github.com/pkg/errors v0.8.0
go: finding github.com/go-logfmt/logfmt v0.3.0
go: finding github.com/gogo/protobuf v1.1.1
go: finding golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
go: finding github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf
go: finding github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
go: finding github.com/matttproud/golang_protobuf_extensions v1.0.1
go: finding golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8
go: finding github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223
go: finding github.com/ghodss/yaml v1.0.0
go: finding gopkg.in/alecthomas/kingpin.v2 v2.2.6
go: finding github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72
go: finding github.com/kisielk/errcheck v1.1.0
go: finding github.com/kr/text v0.1.0
go: finding golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5
go: finding github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce
go: finding github.com/oklog/ulid v1.3.1
go: finding golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
go: finding github.com/sirupsen/logrus v1.2.0
go: finding golang.org/x/tools v0.0.0-20190114222345-bf090417da8b
go: finding github.com/prometheus/client_golang v0.9.1
go: finding golang.org/x/net v0.0.0-20181220203305-927f97764cc3
go: finding golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
go: finding golang.org/x/net v0.0.0-20180826012351-8a410e7b638d
go: finding golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3
go: finding golang.org/x/tools v0.0.0-20180221164845-07fd8470d635
go: finding github.com/kr/pty v1.1.1
go: finding github.com/kisielk/gotool v1.0.0
go: finding golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33
go: finding github.com/stretchr/objx v0.1.1
go: finding golang.org/x/crypto v0.0.0-20180904163835-0709b304e793
go: finding github.com/konsorten/go-windows-terminal-sequences v1.0.1
go: downloading golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: extracting golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a

Cobra CLI Development

  • Created commands
$ cobra add init
config created at /Users/marcellodesales/dev/github.com/marcellodesales/cloner%

$ cobra add git
init created at /Users/marcellodesales/dev/github.com/marcellodesales/cloner%

$ tree
.
├── LICENSE
├── cmd
│   ├── init.go
│   ├── git.go
└── main.go

Running Commands

  • Existing commands
$ go run main.go init
init called
  • Non-existent commands
$ go run main.go marcello
Error: unknown command "marcello" for "cloner"
Run 'iprotos --help' for usage.
unknown command "marcello" for "cloner"
exit status 1
  • Showing the Help
$ go run main.go --help
A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.

Usage:
  iprotos [command]

Available Commands:
  init    A brief description of your command
  help        Help about any command
  git        A brief description of your command

Flags:
      --config string   config file (default is $HOME/cloner.yaml)
  -h, --help            help for iprotos
  -t, --toggle          Help message for toggle

Use "iprotos [command] --help" for more information about a command.
Clone this wiki locally