github.com/kcmvp/gob@v1.0.17/README.md (about) 1 <p align="center"> 2 Golang Project Boot 3 <br/> 4 <br/> 5 <a href="https://github.com/kcmvp/gob/blob/main/LICENSE"> 6 <img alt="GitHub" src="https://img.shields.io/github/license/kcmvp/gob"/> 7 </a> 8 <a href="https://goreportcard.com/report/github.com/kcmvp/gob"> 9 <img src="https://goreportcard.com/badge/github.com/kcmvp/gob"/> 10 </a> 11 <a href="https://pkg.go.dev/github.com/kcmvp/gob"> 12 <img src="https://pkg.go.dev/badge/github.com/kcmvp/gob.svg" alt="Go Reference"/> 13 </a> 14 <a href="https://github.com/kcmvp/gob/blob/main/.github/workflows/workflow.yml" rel="nofollow"> 15 <img src="https://img.shields.io/github/actions/workflow/status/kcmvp/gob/workflow.yml?branch=main" alt="Build" /> 16 </a> 17 <a href="https://app.codecov.io/gh/kcmvp/gob" ref="nofollow"> 18 <img src ="https://img.shields.io/codecov/c/github/kcmvp/gob" alt="coverage"/> 19 </a> 20 21 </p> 22 23 <span id="nav-1"></span> 24 25 <span id="nav-2"></span> 26 27 ## Introduction 28 29 Although the Golang programming ecosystem is becoming more and more mature, 30 these tools and frameworks exist independently to solve specific problems. 31 Whenever a new Golang project is started, it requires a series of initialization; 32 What’s worse is that whenever your switch the development environment, same process have to be repeated! 33 This project is built to solve this problem by providing a tool named *gbc**, which is similar to [Maven](https://maven.apache.org/) 34 or [Gradle](https://gradle.com/) in the **Java** ecosystem together with a framework(glue) similar to [SpringBoot](https://spring.io/projects/spring-boot). Please refer [documents](#commands) for details 35 36 <span id="nav-3"></span> 37 38 ## Features 39 40 1. Everything is a plugin, you can use any tool you like as a plugin to customize your build process! 41 2. Model driver SQL database DAO(data access object). 42 3. IoC Container support via [samber/do](https://github.com/samber/do). 43 4. Code generation for most popular frameworks scaffolding. 44 5. Environment sensitive profile. **application.yml** for no-test environment and **application-test.yml** for test environment 45 6. Friendly help messages 46 7. More .... 47 48 ## What's a gob based project looks like? 49 Just like[SpringBoot](https://spring.io/projects/spring-boot), the most important part of a gob project is the **configurations** which define your project. 50 There are **two** main configurations 51 1. **gob.yaml** : it acts as the same as **settings.gradle.kts**( [Gradle](https://gradle.com/)) or **pom.xml**([Maven](https://maven.apache.org/)), you can define any thrid party tool as a plugin in this file. 52 2. **application.yaml**: it acts as the same **application.yaml** of [SpringBoot](https://spring.io/projects/spring-boot) 53 54 55 ## Quick Start 56 1. Install `gbc` with below command 57 ```shell 58 go install github.com/kcmvp/gob/cmd/gbc@latest 59 ``` 60 2. Initialize project with below command(in the project home directory) 61 ```shell 62 gbc init 63 ``` 64 65 | Make some changes and commit code | execute `gbc deps` | 66 |--------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------| 67 | <img src="https://github.com/kcmvp/gob/blob/main/docs/commit_hook.gif" height="245" width="400"> | <img src="https://github.com/kcmvp/gob/blob/main/docs/dependency_tree.png" height="245" width="300"> | 68 69 70 71 ## How gbc works 72 `gbc` takes everything defined in the `gob.yaml` as plugin. 73 ```mermaid 74 flowchart TD 75 gbc --> gob.yaml 76 gob.yaml --> plugin1 77 gob.yaml --> plugin2 78 gob.yaml --> plugin3 79 ``` 80 You just need to tell `gbc` 3W(where,when and what) 81 1. **Where** : where to download the tool 82 2. **When** : when to execute to command 83 2. **What** : what to do with the tool 84 85 86 ## Commands 87 88 Build Commands 89 - [gbc init](#gbc-init) 90 - [gbc build](#gbc-build) 91 - [gbc clean](#gbc-clean) 92 - [gbc test](#gbc-test) 93 - [gbc lint](#gbc-lint) 94 - [gbc deps](#gbc-deps) 95 96 Plugin Commands 97 - [gbc plugin install](#gbc-plugin-install) 98 - [gbc plugin list](#gbc-plugin-list) 99 100 Setup Commands 101 - [gbc setup version](#gbc-setup-version) 102 103 ### gbc init 104 ```shell 105 gbc init 106 ``` 107 Initialize gbc for the project, it will do following initializations 108 1. generate file `gob.yaml` 109 2. generate file `.golangci.yaml`, which is the configuration for [golangci-lint](https://github.com/golangci/golangci-lint) 110 3. setup `git hooks`(if project in the source control.) 111 1. commit-msg 112 2. pre-commit 113 3. pre-push 114 115 > This command can be executed at any time. 116 117 Content of `gob.yaml` 118 119 ```yaml 120 exec: 121 commit-msg-hook: ^#[0-9]+:\s*.{10,}$ 122 pre-commit-hook: 123 - lint 124 - test 125 pre-push-hook: 126 - test 127 plugins: 128 golangci-lint: 129 alias: lint #When : when issue `gbc lint` 130 args: run ./... #What: execute `golangci-lint run ./...` 131 url: github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 #Where: where to download the plugin 132 gotestsum: 133 alias: test 134 args: --format testname -- -coverprofile=target/cover.out ./... 135 url: gotest.tools/gotestsum@v1.11.0 136 ``` 137 in most cases you don't need to edit the configuration manually. you can achieve this by [plugin commands](#gbc-plugin-install) 138 139 ### gbc build 140 ```shell 141 gbc build 142 ``` 143 This command would build all the candidate binaries(main methods in main packages) to the `target` folder. 144 1. Final binary name is same as go source file name which contains `main method` 145 2. Would fail if there are same name go main source file 146 147 ### gbc clean 148 ```shell 149 gbc clean 150 ``` 151 This command would clean `target` folder 152 153 ### gbc test 154 ```shell 155 gbc test 156 ``` 157 This command would run all tests for the project and generate coverage report at `target/cover.html` 158 159 ### gbc lint 160 ```shell 161 gbc lint 162 ``` 163 Run `golangci-lint` against project based on the configuration, a report named `target/lint.log` will be generated if there are any violations 164 ### gbc deps 165 ```shell 166 gbc deps 167 ``` 168 List project dependencies tree and indicate there are updates for a specific dependency 169 ### gbc plugin install 170 ```shell 171 gbc plugin install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 lint run ./... 172 ``` 173 It is an advanced version of `go install`, which supports multi-version.(eg:`golangci-lint-v1.55.2`, `golangci-lint-v1.55.1`) 174 1. Install the versioned tool(just the same as `go install`) 175 2. Set up the tool as plugin in `gob.yaml` 176 3. You can update adjust the parameters of the plugin by editing `gob.yaml` 177 178 ### gob plugin list 179 180 ```shell 181 gob plugin list 182 ``` 183 List all the installed plugins 184 185 ### gob setup version 186 ```shell 187 gob setup version 188 ``` 189 This command will generate file `version.go` in `infra` folder, and project version information 190 will be injected into `buildVersion` when build the project with command `gob build` 191 ```go 192 // buildVersion don't change this 193 var buildVersion string 194 ``` 195 196 ## FAQ 197 198 - [When install a plugin, how to find out the url?](#) 199 200 `gob plugin install` work the same way as `go install`, it take the same url as `go install`. 201 202 203 - [How to upgrade a plugin ?](#) 204 205 Just simply edit `gob.yaml` file and update the version you want. 206 ```yaml 207 plugins: 208 golangci-lint: 209 alias: lint 210 args: run ./... 211 url: github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 212 ``` 213 ` 214