Skip to main content

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

$ goctl api --help
Generate api related files

Usage:
goctl api [flags]
goctl api [command]

Available Commands:
dart Generate dart files for provided api in api file
doc Generate doc files
format Format api files
go Generate go files for provided api in api file
kt Generate kotlin code for provided api file
new Fast create api service
plugin Custom file generator
ts Generate ts files for provided api in api file
validate Validate api file

Flags:
--branch string The branch of the remote repo, it does work with --remote
-h, --help help for api
--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
--o string Output a sample api file
--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
The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure


Use "goctl api [command] --help" for more information about a command.
Parameter field Parameter Type Required? Default value 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.

$ goctl api dart --help
Generate dart files for provided api in api file

Usage:
goctl api dart [flags]

Flags:
--api string The api file
--dir string The target dir
-h, --help help for dart
--hostname string hostname of the server
--legacy Legacy generator for flutter v1
Parameter field Parameter Type Required? Default value 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.

$ goctl api doc --help
Generate doc files

Usage:
goctl api doc [flags]

Flags:
--dir string The target dir
-h, --help help for doc
--o string The output markdown directory
Parameter field Parameter Type Required? Default value Parameter Description
dirstringYESEmpty stringapi file directory
ostringNOCurrent work dirDocument Output Directory

format

Api files in recursive formatting directory.

$ goctl api format --help
Format api files

Usage:
goctl api format [flags]

Flags:
--declare Use to skip check api types already declare
--dir string The format target dir
-h, --help help for format
--iu Ignore update
--stdin Use stdin to input api doc content, press "ctrl + d" to send EOF
Parameter field Parameter Type Required? Default value 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.

$ goctl api go --help
Generate go files for provided api in api file

Usage:
goctl api go [flags]

Flags:
--api string The api file
--branch string The branch of the remote repo, it does work with --remote
--dir string The target dir
-h, --help help for go
--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
--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
The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
--style string The file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md] (default "gozero")
Parameter field Parameter Type Required? Default value 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, see file style

new

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

$ goctl api new --help
Fast create api service

Usage:
goctl api new [flags]

Examples:
goctl api new [options] service-name

Flags:
--branch string The branch of the remote repo, it does work with --remote
-h, --help help for new
--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
--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
The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
--style string The file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md] (default "gozero")
Parameter field Parameter Type Required? Default value 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, see file style
reminder

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:

$ 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.

$ goctl api plugin --help
Custom file generator

Usage:
goctl api plugin [flags]

Flags:
--api string The api file
--dir string The target dir
-h, --help help for plugin
-p, --plugin string The plugin file
--style string The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]
Parameter field Parameter Type Required? Default value 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, see file style

Plugin resource reference goctl plugin resource

ts

Generate TypeScript code from api file.

$ goctl api ts --help
Generate ts files for provided api in api file

Usage:
goctl api ts [flags]

Flags:
--api string The api file
--caller string The web api caller
--dir string The target dir
-h, --help help for ts
--unwrap Unwrap the webapi caller for import
--webapi string The web api file path
Parameter field Parameter Type Required? Default value 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, see file style

validate

Verify that api files meet the specifications.

goctl api validate --help
Validate api file

Usage:
goctl api validate [flags]

Flags:
--api string Validate target api file
-h, --help help for validate
Parameter field Parameter Type Required? Default value Parameter Description
apistringYESEmpty stringapi file