History

feat: support for gzip middleware (#53)

Josef Hák committed 7 years ago

Commit dbf6ef41 parent 966821010 files · +87 −10Browse files

Showing the changes to example/basic (4 of 10 files). Show all

Unified · Split

4 files
  1. example/basic/api/api.go +40 −0
  2. example/basic/docs/docs.go +161 −0
  3. example/basic/main.go +32 −0
  4. example/basic/web/handler.go +27 −0
example/basic/api/api.go+40−0
@@ -0,0 +1,40 @@
1package api
2
3import (
4 "fmt"
5 "github.com/gin-gonic/gin"
6 "github.com/swaggo/swag/example/basic/web"
7)
8
9//
10// @Summary Add a new pet to the store
11// @Description get string by ID
12// @Accept json
13// @Produce json
14// @Param some_id path int true "Some ID"
15// @Success 200 {string} string "ok"
16// @Failure 400 {object} web.APIError "We need ID!!"
17// @Failure 404 {object} web.APIError "Can not find ID"
18// @Router /testapi/get-string-by-int/{some_id} [get]
19func GetStringByInt(c *gin.Context) {
20 err := web.APIError{}
21 fmt.Println(err)
22}
23
24// @Description get struct array by ID
25// @Accept json
26// @Produce json
27// @Param some_id path string true "Some ID"
28// @Param offset query int true "Offset"
29// @Param limit query int true "Offset"
30// @Success 200 {string} string "ok"
31// @Failure 400 {object} web.APIError "We need ID!!"
32// @Failure 404 {object} web.APIError "Can not find ID"
33// @Router /testapi/get-struct-array-by-string/{some_id} [get]
34func GetStructArrayByString(c *gin.Context) {
35
36}
37
38type Pet3 struct {
39 ID int `json:"id"`
40}
example/basic/docs/docs.go+161−0
@@ -0,0 +1,161 @@
1// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
2// This file was generated by swaggo/swag at
3// 2017-06-25 01:25:37.872454531 +0800 CST
4
5package docs
6
7import (
8 "github.com/swaggo/swag"
9)
10
11var doc = `{
12 "swagger": "2.0",
13 "info": {
14 "description": "This is a sample server Petstore server.",
15 "title": "Swagger Example API",
16 "termsOfService": "http://swagger.io/terms/",
17 "contact": {
18 "name": "API Support",
19 "url": "http://www.swagger.io/support",
20 "email": "support@swagger.io"
21 },
22 "license": {
23 "name": "Apache 2.0",
24 "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
25 },
26 "version": "1.0"
27 },
28 "host": "petstore.swagger.io",
29 "basePath": "/v2",
30 "paths": {
31 "/testapi/get-string-by-int/{some_id}": {
32 "get": {
33 "description": "get string by ID",
34 "consumes": [
35 "application/json"
36 ],
37 "produces": [
38 "application/json"
39 ],
40 "summary": "Add a new pet to the store",
41 "parameters": [
42 {
43 "description": "Some ID",
44 "name": "some_id",
45 "in": "path",
46 "required": true,
47 "schema": {
48 "type": "int"
49 }
50 }
51 ],
52 "responses": {
53 "200": {
54 "description": "ok",
55 "schema": {
56 "type": "string"
57 }
58 },
59 "400": {
60 "description": "We need ID!!",
61 "schema": {
62 "type": "object",
63 "$ref": "#/definitions/web.APIError"
64 }
65 },
66 "404": {
67 "description": "Can not find ID",
68 "schema": {
69 "type": "object",
70 "$ref": "#/definitions/web.APIError"
71 }
72 }
73 }
74 }
75 },
76 "/testapi/get-struct-array-by-string/{some_id}": {
77 "get": {
78 "description": "get struct array by ID",
79 "consumes": [
80 "application/json"
81 ],
82 "produces": [
83 "application/json"
84 ],
85 "parameters": [
86 {
87 "description": "Some ID",
88 "name": "some_id",
89 "in": "path",
90 "required": true,
91 "schema": {
92 "type": "string"
93 }
94 },
95 {
96 "description": "Offset",
97 "name": "offset",
98 "in": "query",
99 "required": true,
100 "schema": {
101 "type": "int"
102 }
103 },
104 {
105 "description": "Offset",
106 "name": "limit",
107 "in": "query",
108 "required": true,
109 "schema": {
110 "type": "int"
111 }
112 }
113 ],
114 "responses": {
115 "200": {
116 "description": "ok",
117 "schema": {
118 "type": "string"
119 }
120 },
121 "400": {
122 "description": "We need ID!!",
123 "schema": {
124 "type": "object",
125 "$ref": "#/definitions/web.APIError"
126 }
127 },
128 "404": {
129 "description": "Can not find ID",
130 "schema": {
131 "type": "object",
132 "$ref": "#/definitions/web.APIError"
133 }
134 }
135 }
136 }
137 }
138 },
139 "definitions": {
140 "web.APIError": {
141 "type": "object",
142 "properties": {
143 "ErrorCode": {
144 "type": "int"
145 },
146 "ErrorMessage": {
147 "type": "string"
148 }
149 }
150 }
151 }
152}`
153
154type s struct{}
155
156func (s *s) ReadDoc() string {
157 return doc
158}
159func init() {
160 swag.Register(swag.Name, &s{})
161}
example/basic/main.go+32−0
@@ -0,0 +1,32 @@
1package main
2
3import (
4 "github.com/gin-gonic/gin"
5 "github.com/swaggo/gin-swagger"
6 "github.com/swaggo/gin-swagger/swaggerFiles"
7
8 _ "github.com/swaggo/gin-swagger/example/basic/docs"
9)
10
11// @title Swagger Example API
12// @version 1.0
13// @description This is a sample server Petstore server.
14// @termsOfService http://swagger.io/terms/
15
16// @contact.name API Support
17// @contact.url http://www.swagger.io/support
18// @contact.email support@swagger.io
19
20// @license.name Apache 2.0
21// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
22
23// @host petstore.swagger.io
24// @BasePath /v2
25func main() {
26 r := gin.New()
27
28 url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") //The url pointing to API definition
29 r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
30
31 r.Run()
32}
example/basic/web/handler.go+27−0
@@ -0,0 +1,27 @@
1package web
2
3// @hello
4// yo yo yo yo
5type Pet struct {
6 ID int `json:"id"`
7 Category struct {
8 ID int `json:"id"`
9 Name string `json:"name"`
10 } `json:"category"`
11 Name string `json:"name"`
12 PhotoUrls []string `json:"photoUrls"`
13 Tags []struct {
14 ID int `json:"id"`
15 Name string `json:"name"`
16 } `json:"tags"`
17 Status string `json:"status"`
18}
19
20type Pet2 struct {
21 ID int `json:"id"`
22}
23
24type APIError struct {
25 ErrorCode int
26 ErrorMessage string
27}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t