|
| 1 | +# Go CLI Boilerplate |
| 2 | + |
| 3 | +A powerful Golang CLI application scaffold integrated with logrus, go-arg, config, testify and Github Action. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +### 1. Use as template |
| 8 | + |
| 9 | +Click `Use this template` button to create a new repository. Then clone the new repository to your local machine. |
| 10 | + |
| 11 | +### 2. Do some changes |
| 12 | + |
| 13 | +1. Change the package name |
| 14 | + + Replace `example.com/m` with your own package name. |
| 15 | + + The default is `example.com/m` You can replace by `sed`: |
| 16 | + |
| 17 | + ```bash |
| 18 | + sed -i 's/example.com\/m/your.package.name/g' $(find . -type f) |
| 19 | + ``` |
| 20 | + |
| 21 | + Or use global search and replace in your IDE. |
| 22 | + |
| 23 | +2. Change the module name |
| 24 | + + The default application name is `greet` |
| 25 | + + Rename `cmd/greet` to `cmd/YOUR_APP_NAME` |
| 26 | + + Rename inside `Makefile` for `BIN_NAMES` |
| 27 | + + Rename inside `conf/*.toml` for logger file name |
| 28 | + + Rename insdie `.vscode` for debugging |
| 29 | + |
| 30 | +3. Add more application if needed |
| 31 | + + Add more application in `cmd` folder just like `greet` app. |
| 32 | + + Add more application name in `Makefile` for `BIN_NAMES`, for example: |
| 33 | + |
| 34 | + ```makefile |
| 35 | + BIN_NAMES=app1 app2 |
| 36 | + ``` |
| 37 | + |
| 38 | +4. Enable write permission for workflow |
| 39 | + + Click `Settings` tab of your repository. |
| 40 | + + Select `Action -> General` in left sidebar. |
| 41 | + + Locate `Workflow permissions` section. |
| 42 | + + Check `Read and write permission` |
| 43 | + |
| 44 | +### 3. Release |
| 45 | + |
| 46 | +1. Edit `README.md`. Switch `LICENSE` to your own license. |
| 47 | +2. Coding for your application. |
| 48 | +3. Run `make dev` to build for your local machine. |
| 49 | +4. Run `make test` to run unit tests. |
| 50 | +5. Run `make package` to cross compile for different platforms. |
| 51 | +6. Click `Action` tab of your repository to see the Github Action workflow. In release workflow, click `Run workflow` button to release your application. |
| 52 | + |
| 53 | +## Run Example |
| 54 | + |
| 55 | +```bash |
| 56 | +go run cmd/greet/main.go Jack -v -c ./dist/config.example.toml |
| 57 | +``` |
| 58 | + |
| 59 | +## Features |
| 60 | + |
| 61 | ++ [x] Logrus logger. JSON format |
| 62 | ++ [x] Multiple logging output: file, stdout, stderr |
| 63 | ++ [x] Command line args, such as `--verbose` and `--config` |
| 64 | ++ [x] Config file, such as `./dist/config.example.toml` |
| 65 | ++ [x] Log rotation |
| 66 | + |
| 67 | +Use `| jq` to pretty print JSON log. |
| 68 | + |
| 69 | +Generate structs for your config file: [Toml to Go](https://xuri.me/toml-to-go/) |
0 commit comments