Skip to content

Commit 1c55301

Browse files
swagger docs added
1 parent 56dddec commit 1c55301

File tree

16 files changed

+479
-268
lines changed

16 files changed

+479
-268
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919

2020
# Go workspace file
2121
go.work
22+
23+
pkg/
24+
bin/

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
## Writing a basic HTTP server is easy using Gin package
33

4-
# To run http server
4+
# To run http server
55

66
cd simple-http-server
7+
78
```
89
for gin
910
@@ -24,11 +25,6 @@ go run main.go
2425
# to call api endpoint in postman
2526
2627
```
27-
for gin-server
28-
http://localhost:3000
29-
30-
for simpe-http-server
31-
http://localhost:3000
3228

3329

3430
for folder gin-web-app
@@ -39,5 +35,10 @@ http://localhost:3000/user/testuser
3935
http://localhost:3000/contact
4036

4137

38+
```
39+
40+
# You can go to swagger doc
4241
4342
```
43+
http://localhost:3001/swagger/index.html
44+
```

gin-web-app/docs/docs.go

+154-12
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,173 @@ const docTemplate = `{
99
"info": {
1010
"description": "{{escape .Description}}",
1111
"title": "{{.Title}}",
12-
"termsOfService": "https://tos.santoshk.dev",
1312
"contact": {
14-
"name": "Santosh Kumar",
15-
"url": "https://twitter.com/sntshk",
16-
"email": "sntshkmr60@gmail.com"
17-
},
18-
"license": {
19-
"name": "Apache 2.0",
20-
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
13+
"name": "vinod",
14+
"url": "http://www.swagger.io/support",
15+
"email": "support@swagger.io"
2116
},
2217
"version": "{{.Version}}"
2318
},
2419
"host": "{{.Host}}",
2520
"basePath": "{{.BasePath}}",
26-
"paths": {}
21+
"paths": {
22+
"/": {
23+
"get": {
24+
"description": "Hello",
25+
"consumes": [
26+
"application/json"
27+
],
28+
"produces": [
29+
"application/json"
30+
],
31+
"tags": [
32+
"example"
33+
],
34+
"summary": "hellow example",
35+
"responses": {
36+
"200": {
37+
"description": "OK",
38+
"schema": {
39+
"type": "string"
40+
}
41+
}
42+
}
43+
}
44+
},
45+
"/about": {
46+
"get": {
47+
"description": "about",
48+
"consumes": [
49+
"application/json"
50+
],
51+
"produces": [
52+
"application/json"
53+
],
54+
"tags": [
55+
"about"
56+
],
57+
"summary": "about routes",
58+
"responses": {
59+
"200": {
60+
"description": "OK",
61+
"schema": {
62+
"type": "string"
63+
}
64+
}
65+
}
66+
}
67+
},
68+
"/user": {
69+
"get": {
70+
"description": "users list",
71+
"consumes": [
72+
"application/json"
73+
],
74+
"produces": [
75+
"application/json"
76+
],
77+
"summary": "users list",
78+
"responses": {
79+
"200": {
80+
"description": "OK"
81+
},
82+
"400": {
83+
"description": "Bad Request"
84+
},
85+
"404": {
86+
"description": "Not Found"
87+
},
88+
"500": {
89+
"description": "Internal Server Error"
90+
}
91+
}
92+
}
93+
},
94+
"/user/{id}": {
95+
"get": {
96+
"description": "user get by id",
97+
"consumes": [
98+
"application/json"
99+
],
100+
"produces": [
101+
"application/json"
102+
],
103+
"summary": "get user id",
104+
"operationId": "get-string-by-int",
105+
"parameters": [
106+
{
107+
"type": "integer",
108+
"description": "userid ID",
109+
"name": "id",
110+
"in": "path",
111+
"required": true
112+
}
113+
],
114+
"responses": {
115+
"200": {
116+
"description": "OK"
117+
},
118+
"400": {
119+
"description": "Bad Request"
120+
},
121+
"404": {
122+
"description": "Not Found"
123+
},
124+
"500": {
125+
"description": "Internal Server Error"
126+
}
127+
}
128+
}
129+
},
130+
"/user/{name}": {
131+
"get": {
132+
"consumes": [
133+
"application/json"
134+
],
135+
"produces": [
136+
"application/json"
137+
],
138+
"summary": "get user name",
139+
"parameters": [
140+
{
141+
"type": "string",
142+
"description": "usernmae",
143+
"name": "name",
144+
"in": "path",
145+
"required": true
146+
}
147+
],
148+
"responses": {
149+
"200": {
150+
"description": "OK"
151+
},
152+
"400": {
153+
"description": "Bad Request"
154+
},
155+
"404": {
156+
"description": "Not Found"
157+
},
158+
"500": {
159+
"description": "Internal Server Error"
160+
}
161+
}
162+
}
163+
}
164+
},
165+
"externalDocs": {
166+
"description": "OpenAPI",
167+
"url": "https://swagger.io/resources/open-api/"
168+
}
27169
}`
28170

29171
// SwaggerInfo holds exported Swagger Info so clients can modify it
30172
var SwaggerInfo = &swag.Spec{
31173
Version: "1.0",
32174
Host: "localhost:3001",
33-
BasePath: "",
175+
BasePath: "/",
34176
Schemes: []string{},
35-
Title: "Gin Book Service",
36-
Description: "A book management service API in Go using Gin framework.",
177+
Title: "Swagger Example API",
178+
Description: "This is a sample gin web server",
37179
InfoInstanceName: "swagger",
38180
SwaggerTemplate: docTemplate,
39181
LeftDelim: "{{",

0 commit comments

Comments
 (0)