Skip to main content

goctl quickstart

Overview

goctl quickstart is used to quickly generate api, rpc services and start up and can help first go-zero developers quickly get to get started. Once demo starts and accesses, developers can read a simple source directory of services, go-zero engineering structure to get an overview of go-zero.

goctl quickstart directive

$ goctl quickstart --help
quickly start a project

Usage:
goctl quickstart [flags]

Flags:
-h, --help help for quickstart
-t, --service-type string specify the service type, supported values: [mono, micro] (default "mono")
Parameter field Parameter Type Required? Default value Parameter Description
service-typestringNOmonoGenerate demo service type, mono:mono service, micro:microservice

Examples

If the mono type is selected, goctl generates a minimized HTTP service and starts the HTTP service.

1 Generate code

# enter user home
$ cd ~

# mkdir
$ mkdir quickstart && cd quickstart

# generate mono service
$ goctl quickstart --service-type mono
go: creating new go.mod: module greet
>> Generating quickstart api project...
Done.
>> go mod tidy
go: finding module for package github.com/zeromicro/go-zero/core/logx
go: finding module for package github.com/zeromicro/go-zero/rest
go: finding module for package github.com/zeromicro/go-zero/rest/httpx
go: finding module for package github.com/zeromicro/go-zero/core/conf
go: found github.com/zeromicro/go-zero/core/conf in github.com/zeromicro/go-zero v1.4.3
go: found github.com/zeromicro/go-zero/rest in github.com/zeromicro/go-zero v1.4.3
go: found github.com/zeromicro/go-zero/rest/httpx in github.com/zeromicro/go-zero v1.4.3
go: found github.com/zeromicro/go-zero/core/logx in github.com/zeromicro/go-zero v1.4.3
>> Ready to start an API server...
>> Run 'curl http://127.0.0.1:8888/ping' after service startup...
Starting server at 127.0.0.1:8888...

2curl

open a new terminal, execute curl test

$ curl -i http://127.0.0.1:8888/ping
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Traceparent: 00-2102678b8c7c5906b792c618b054c9a1-60194e95cceff37f-00
Date: Fri, 06 Jan 2023 08:52:30 GMT
Content-Length: 14

{"msg":"pong"}%