• Stars
    star
    176
  • Rank 209,330 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

goctl-swagger

1. 编译goctl-swagger插件

GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/goctl-swagger@latest

2. 配置环境

将$GOPATH/bin中的goctl-swagger添加到环境变量

3. 使用姿势

  • 创建api文件

    info(
     title: "type title here"
     desc: "type desc here"
     author: "type author here"
     email: "type email here"
     version: "type version here"
    )
    
    
    type (
     RegisterReq {
      Username string `json:"username"`
      Password string `json:"password"`
      Mobile string `json:"mobile"`
     }
     
     LoginReq {
      Username string `json:"username"`
      Password string `json:"password"`
     }
     
     UserInfoReq {
      Id string `path:"id"`
     }
     
     UserInfoReply {
      Name string `json:"name"`
      Age int `json:"age"`
      Birthday string `json:"birthday"`
      Description string `json:"description"`
      Tag []string `json:"tag"`
     }
     
     UserSearchReq {
      KeyWord string `form:"keyWord"`
     }
    )
    
    service user-api {
     @doc(
      summary: "注册"
     )
     @handler register
     post /api/user/register (RegisterReq)
     
     @doc(
      summary: "登录"
     )
     @handler login
     post /api/user/login (LoginReq)
     
     @doc(
      summary: "获取用户信息"
     )
     @handler getUserInfo
     get /api/user/:id (UserInfoReq) returns (UserInfoReply)
     
     @doc(
      summary: "用户搜索"
     )
     @handler searchUser
     get /api/user/search (UserSearchReq) returns (UserInfoReply)
    }
  • 生成swagger.json 文件

    goctl api plugin -plugin goctl-swagger="swagger -filename user.json" -api user.api -dir .
  • 指定Host,basePath api-host-and-base-path

    goctl api plugin -plugin goctl-swagger="swagger -filename user.json -host 127.0.0.2 -basepath /api" -api user.api -dir .
  • swagger ui 查看生成的文档

     docker run --rm -p 8083:8080 -e SWAGGER_JSON=/foo/user.json -v $PWD:/foo swaggerapi/swagger-ui
  • Swagger Codegen 生成客户端调用代码(go,javascript,php)

    for l in go javascript php; do
      docker run --rm -v "$(pwd):/go-work" swaggerapi/swagger-codegen-cli generate \
        -i "/go-work/rest.swagger.json" \
        -l "$l" \
        -o "/go-work/clients/$l"
    done

More Repositories

1

go-zero

A cloud-native Go microservices framework with cli tool for productivity.
Go
27,635
star
2

cds

Data syncing in golang for ClickHouse.
Go
952
star
3

zero-examples

go-zero examples
Go
822
star
4

go-queue

Kafka, Beanstalkd Pub/Sub framework.
Go
644
star
5

zero-doc

The docs for go-zero
JavaScript
528
star
6

zeromall

The mall/eshop system based on go-zero.
Go
277
star
7

awesome-zero

A curated list of awesome projects that powered by go-zero.
225
star
8

zero-contrib

A collection of extensions and tools for go-zero.
Go
162
star
9

go-zero-demo

the source code of the go-zero-doc
Go
70
star
10

goctl-go-compact

Go
32
star
11

portal

go-zero official documentation
TypeScript
25
star
12

goctl-intellij

A intellij plugin of goctl
Java
22
star
13

goctl-php

goctl php plugin
Go
21
star
14

go-zero-pages

go-zero-pages is the gitbook document of go-zero. This repository is a managed repository on github pages. Please do not try to add or update files in this repository, because this repository is hosted by https://github.com/zeromicro/go-zero-pages -Doc’s github action is automatically built, if you need to submit or update the document, please fork go-zero-doc to modify and submit pr
HTML
18
star
15

goctl-vscode

goctl extension for Visual Studio Code
TypeScript
17
star
16

ddl-parser

A tool to parse mysql ddl.
ANTLR
14
star
17

x

This repository is part of the go-zero project but outside the main tree. It's developed under looser compatibility requirements than the go-zero project.
Go
13
star
18

zero-api

zero-api is a RESTful API description language.
12
star
19

go-zero-doc

The gitbook source for go-zero document
JavaScript
12
star
20

goctl-android

goctl android plugin demo
Go
12
star
21

go-zero-template

A golang template repo for go-zero, Do not accept pr!
Smarty
6
star
22

zero-test

The repo for integration test of go-zero project.
5
star
23

protoc-gen-zrpc-gateway

5
star
24

goctl-plugins

goctl plugins for languages and platforms.
4
star
25

zero-legacy

The legacy mongo/mongoc packages from go-zero.
Go
4
star
26

antlr

forked from antlr/antlr4 and remove another useless code, in order to solve the antlr official module conflict bug
Go
4
star
27

grpc-mock

A gRPC mocking tool.
Go
4
star
28

zero-ci

go-zero continuous integration.
Go
3
star
29

goctl-restclient

Generate Visual Studio Code REST Client plugin files for zero-api
Go
3
star
30

go-zero.dev

go-zero.dev
JavaScript
1
star
31

goctl-vue-element-admin

生成vue-element-admin,api/views文件
1
star