Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/tillkuhn/letitgo
- Owner: tillkuhn
- License: other
- Created: 2021-09-16T15:02:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-17T15:01:33.000Z (4 months ago)
- Last Synced: 2024-09-18T08:16:51.340Z (4 months ago)
- Language: Go
- Homepage:
- Size: 420 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
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]