Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tillkuhn/letitgo

⚽ My personal Go Playground
https://github.com/tillkuhn/letitgo

Last synced: about 2 months ago
JSON representation

⚽ My personal Go Playground

Awesome Lists containing this project

README

        

= 🥶 Let it Go - My Personal Go Playground :vulcan_salute:

== Get started

Get https://golang.org/doc/install[Go] and - most importantly - install the great https://github.com/golangci/golangci-lint[golangci-lint]
and follow the advice of their "Bug Gopher"!

image:https://raw.githubusercontent.com/golangci/golangci-lint/master/assets/go.png[alt=Flower,width=240,height=240]

== 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/.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
----

=== Setup Git Pre-commit hook

* https://freshman.tech/linting-golang/#setting-up-a-pre-commit-hook[]
* https://pre-commit.com/#install[Install pre-commit to manage multi-language pre-commit hooks (python based)]
* https://github.com/TekWizely/pre-commit-golang[a complete repo full of golang pre-commit hooks]

== Links

* https://github.com/tillkuhn/letitgo[Let it Go - My Personal Go Playground]
* https://carlosvin.github.io/langs/en/posts/rest-service-go-vs-java/[Golang over Java for REST services]
* http://www.inanzzz.com/index.php/post/fb0m/mocking-and-testing-http-clients-in-golang[Mocking and testing HTTP clients in Golang]
* https://github.com/cybersamx/go-recipes[Collection of Golang Recipes]

=== Cobra

* https://github.com/spf13/cobra-cli/blob/main/README.md[Official README]
* https://towardsdatascience.com/how-to-create-a-cli-in-golang-with-cobra-d729641c7177[How to create a CLI in golang with cobra]
* https://github.com/spf13/cobra/blob/master/user_guide.md#using-the-cobra-library[Using the Cobra Library]