goctl api

Overview

goctl api is one of the core modules in goctl, which can quickly generate an api service with the .api file first key. If only an api demonstration project is started, you can complete an api service development and run it without even encoding.In the traditional api project, we will create directories at all levels, write structures, define routes, add logical files, a series of operations that will take between 5 and 6 minutes if the entire coding is calculated in accordance with the business requirements of a protocol to actually enter the preparation of the business log. This does not take into account any errors that may arise in the preparation process, which, as the number of services increases, will take a positive step up as the protocol increases, and goctl api will completely replace you to do this part, regardless of how many of your agreements are, and eventually, only 10 seconds to complete it.

goctl api directive

  1. $ goctl api --help
  2. Generate api related files
  3. Usage:
  4. goctl api [flags]
  5. goctl api [command]
  6. Available Commands:
  7. dart Generate dart files for provided api in api file
  8. doc Generate doc files
  9. format Format api files
  10. go Generate go files for provided api in api file
  11. kt Generate kotlin code for provided api file
  12. new Fast create api service
  13. plugin Custom file generator
  14. ts Generate ts files for provided api in api file
  15. validate Validate api file
  16. Flags:
  17. --branch string The branch of the remote repo, it does work with --remote
  18. -h, --help help for api
  19. --home string The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  20. --o string Output a sample api file
  21. --remote string The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  22. The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
  23. Use "goctl api [command] --help" for more information about a command.
goctl api - 图1 Parameter fieldgoctl api - 图2 Parameter Typegoctl api - 图3 Required?goctl api - 图4 Default valuegoctl api - 图5 Parameter Description
branchstringNOEmpty stringTemplate repository branch, with —remote usage
homestringNO~/.goctlTemplate repository local path higher than —remote
ostringNOEmpty stringOutput api file
remotestringNOEmpty stringTemplate repository remote path

dart

Generate date code from api file.

  1. $ goctl api dart --help
  2. Generate dart files for provided api in api file
  3. Usage:
  4. goctl api dart [flags]
  5. Flags:
  6. --api string The api file
  7. --dir string The target dir
  8. -h, --help help for dart
  9. --hostname string hostname of the server
  10. --legacy Legacy generator for flutter v1
goctl api - 图6 Parameter fieldgoctl api - 图7 Parameter Typegoctl api - 图8 Required?goctl api - 图9 Default valuegoctl api - 图10 Parameter Description
apistringYESEmpty stringapi file
dirstringYESEmpty stringGenerate Code Output Directory
hostnamestringNOgo-zero.devhost 值
legacybooleanNOfalseWhether or not older versions

doc

Generate markdown documentation based on api file.

  1. $ goctl api doc --help
  2. Generate doc files
  3. Usage:
  4. goctl api doc [flags]
  5. Flags:
  6. --dir string The target dir
  7. -h, --help help for doc
  8. --o string The output markdown directory
goctl api - 图11 Parameter fieldgoctl api - 图12 Parameter Typegoctl api - 图13 Required?goctl api - 图14 Default valuegoctl api - 图15 Parameter Description
dirstringYESEmpty stringapi file directory
ostringNOCurrent work dirDocument Output Directory

format

Api files in recursive formatting directory.

  1. $ goctl api format --help
  2. Format api files
  3. Usage:
  4. goctl api format [flags]
  5. Flags:
  6. --declare Use to skip check api types already declare
  7. --dir string The format target dir
  8. -h, --help help for format
  9. --iu Ignore update
  10. --stdin Use stdin to input api doc content, press "ctrl + d" to send EOF
goctl api - 图16 Parameter fieldgoctl api - 图17 Parameter Typegoctl api - 图18 Required?goctl api - 图19 Default valuegoctl api - 图20 Parameter Description
declarebooleanNOfalseWhether to detect context
dirstringYESEmpty stringapi file directory
iu---Unused fields pending removal
stdinbooleanNOfalseFormat api content for terminal input

go

Generate Go HTTP code from api file.

  1. $ goctl api go --help
  2. Generate go files for provided api in api file
  3. Usage:
  4. goctl api go [flags]
  5. Flags:
  6. --api string The api file
  7. --branch string The branch of the remote repo, it does work with --remote
  8. --dir string The target dir
  9. -h, --help help for go
  10. --home string The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  11. --remote string The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  12. The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
  13. --style string The file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md] (default "gozero")
goctl api - 图21 Parameter fieldgoctl api - 图22 Parameter Typegoctl api - 图23 Required?goctl api - 图24 Default valuegoctl api - 图25 Parameter Description
apistringYESEmpty stringapi file
branchstringNOEmpty stringRemote template name is used only if remote has value
dirstringNOCurrent working directoryGenerate Code Output Directory
homestringNO${HOME}/.goctlLocal Template File Directory
remotestringNOEmpty stringRemote template is a git repository address. Priority is higher than home field value when this field is passed
stylestringNOgozeroNamed style symbols for output files and directories, seefile style

new

Quickly generate Go HTTP service. Developers need to specify service name parameters at the terminal, output directory as the current working directory.

  1. $ goctl api new --help
  2. Fast create api service
  3. Usage:
  4. goctl api new [flags]
  5. Examples:
  6. goctl api new [options] service-name
  7. Flags:
  8. --branch string The branch of the remote repo, it does work with --remote
  9. -h, --help help for new
  10. --home string The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  11. --remote string The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  12. The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
  13. --style string The file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md] (default "gozero")
goctl api - 图26 Parameter fieldgoctl api - 图27 Parameter Typegoctl api - 图28 Required?goctl api - 图29 Default valuegoctl api - 图30 Parameter Description
branchstringNOEmpty stringRemote template name is used only if remote has value
homestringNO${HOME}/.goctlLocal Template File Directory
remotestringNOEmpty stringRemote template is a git repository address. Priority is higher than home field value when this field is passed
stylestringNOgozeroNamed style symbols for output files and directories, seefile style
goctl api - 图31reminder

goctl api new requires a terminal parameter to specify the name of the service to be generated, output directory to the current work directory, e.g. demo service generated instructions below:

  1. $ goctl api new demo

plugin

The goctl api plugin command is used to generate code with plugins. Developers need to specify plugin names, parameters, etc. at the terminal.

  1. $ goctl api plugin --help
  2. Custom file generator
  3. Usage:
  4. goctl api plugin [flags]
  5. Flags:
  6. --api string The api file
  7. --dir string The target dir
  8. -h, --help help for plugin
  9. -p, --plugin string The plugin file
  10. --style string The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]
goctl api - 图32 Parameter fieldgoctl api - 图33 Parameter Typegoctl api - 图34 Required?goctl api - 图35 Default valuegoctl api - 图36 Parameter Description
apistringYESEmpty stringapi file
dirstringNOCurrent working directoryapi file
pluginstringYESEmpty stringPath to plugin executable, support local and HTML files
stylestringNOgozeroNamed style symbols for output files and directories, seefile style

Plugin resource reference goctl plugin resource

ts

Generate TypeScript code from api file.

  1. $ goctl api ts --help
  2. Generate ts files for provided api in api file
  3. Usage:
  4. goctl api ts [flags]
  5. Flags:
  6. --api string The api file
  7. --caller string The web api caller
  8. --dir string The target dir
  9. -h, --help help for ts
  10. --unwrap Unwrap the webapi caller for import
  11. --webapi string The web api file path
goctl api - 图37 Parameter fieldgoctl api - 图38 Parameter Typegoctl api - 图39 Required?goctl api - 图40 Default valuegoctl api - 图41 Parameter Description
apistringYESEmpty stringapi file
dirstringNOCurrent working directoryapi file
callerstringNOwebapiweb caller,
pluginstringYESEmpty stringPath to plugin executable, support local and HTML files
stylestringNOgozeroNamed style symbols for output files and directories, seefile style

validate

Verify that api files meet the specifications.

  1. goctl api validate --help
  2. Validate api file
  3. Usage:
  4. goctl api validate [flags]
  5. Flags:
  6. --api string Validate target api file
  7. -h, --help help for validate
goctl api - 图42 Parameter fieldgoctl api - 图43 Parameter Typegoctl api - 图44 Required?goctl api - 图45 Default valuegoctl api - 图46 Parameter Description
apistringYESEmpty stringapi file