tillkuhn / letitgo

⚽ My personal Go Playground

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🥶 Let it Go - My Personal Go Playground 🖖

Get started

Get Go and - most importantly - install the great golangci-lint and follow the advice of their "Bug Gopher"!

Flower

Cobra CLI Usage

Install and init Cobra CLI for new Project

$ go get -u github.com/spf13/cobra@latest

$ cobra-cli init --author "Till Kuhn"
Your Cobra application is ready at
/Users/tillkuhn/git/hub/letitgo

$ go run main.go
A longer description that spans multiple lines and likely contains

Add a Cobra Command for existing Project

Example to add a 'serve' command, this creates a file cmd/server.go
$ cobra-cli add serve
serve created at /Users/tillkuhn/git/hub/letitgo
Create a dedicated folder / package with at least one .go file for your experiments
$ mkdir charts && echo "package charts" >charts/charts.go
printf "package charts\n\nfunc Run() {}" >charts/charts.go
Open ./cmd/<command>.go and call a public function from your new package
var chartsCmd = &cobra.Command{
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("charts called")
		charts.Run() // Delegate to package function (1st entry point)
  // (...)
main() in main.go delegates to Cobra’s Execute() function in cmd/root.go
$ cat main.go
func main() {
	cmd.Execute()
}
Run your new command For frequently used command, create a dedicated target in Makefile
$ go run main.go serve
Running server

Snippets

Add recent version of a module

$ go get "github.com/kelseyhightower/envconfig"
go get: added github.com/kelseyhightower/envconfig v1.4.0

About

⚽ My personal Go Playground

License:Other


Languages

Language:Go 93.9%Language:Makefile 4.4%Language:Dockerfile 1.7%