go-clean-template

Форк
0
223 строки · 6.2 Кб
1
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
2
// This file was generated by swaggo/swag
3
package docs
4

5
import (
6
	"bytes"
7
	"encoding/json"
8
	"strings"
9
	"text/template"
10

11
	"github.com/swaggo/swag"
12
)
13

14
var doc = `{
15
    "schemes": {{ marshal .Schemes }},
16
    "swagger": "2.0",
17
    "info": {
18
        "description": "{{escape .Description}}",
19
        "title": "{{.Title}}",
20
        "contact": {},
21
        "version": "{{.Version}}"
22
    },
23
    "host": "{{.Host}}",
24
    "basePath": "{{.BasePath}}",
25
    "paths": {
26
        "/translation/do-translate": {
27
            "post": {
28
                "description": "Translate a text",
29
                "consumes": [
30
                    "application/json"
31
                ],
32
                "produces": [
33
                    "application/json"
34
                ],
35
                "tags": [
36
                    "translation"
37
                ],
38
                "summary": "Translate",
39
                "operationId": "do-translate",
40
                "parameters": [
41
                    {
42
                        "description": "Set up translation",
43
                        "name": "request",
44
                        "in": "body",
45
                        "required": true,
46
                        "schema": {
47
                            "$ref": "#/definitions/v1.doTranslateRequest"
48
                        }
49
                    }
50
                ],
51
                "responses": {
52
                    "200": {
53
                        "description": "OK",
54
                        "schema": {
55
                            "$ref": "#/definitions/entity.Translation"
56
                        }
57
                    },
58
                    "400": {
59
                        "description": "Bad Request",
60
                        "schema": {
61
                            "$ref": "#/definitions/v1.response"
62
                        }
63
                    },
64
                    "500": {
65
                        "description": "Internal Server Error",
66
                        "schema": {
67
                            "$ref": "#/definitions/v1.response"
68
                        }
69
                    }
70
                }
71
            }
72
        },
73
        "/translation/history": {
74
            "get": {
75
                "description": "Show all translation history",
76
                "consumes": [
77
                    "application/json"
78
                ],
79
                "produces": [
80
                    "application/json"
81
                ],
82
                "tags": [
83
                    "translation"
84
                ],
85
                "summary": "Show history",
86
                "operationId": "history",
87
                "responses": {
88
                    "200": {
89
                        "description": "OK",
90
                        "schema": {
91
                            "$ref": "#/definitions/v1.historyResponse"
92
                        }
93
                    },
94
                    "500": {
95
                        "description": "Internal Server Error",
96
                        "schema": {
97
                            "$ref": "#/definitions/v1.response"
98
                        }
99
                    }
100
                }
101
            }
102
        }
103
    },
104
    "definitions": {
105
        "entity.Translation": {
106
            "type": "object",
107
            "properties": {
108
                "destination": {
109
                    "type": "string",
110
                    "example": "en"
111
                },
112
                "original": {
113
                    "type": "string",
114
                    "example": "текст для перевода"
115
                },
116
                "source": {
117
                    "type": "string",
118
                    "example": "auto"
119
                },
120
                "translation": {
121
                    "type": "string",
122
                    "example": "text for translation"
123
                }
124
            }
125
        },
126
        "v1.doTranslateRequest": {
127
            "type": "object",
128
            "required": [
129
                "destination",
130
                "original",
131
                "source"
132
            ],
133
            "properties": {
134
                "destination": {
135
                    "type": "string",
136
                    "example": "en"
137
                },
138
                "original": {
139
                    "type": "string",
140
                    "example": "текст для перевода"
141
                },
142
                "source": {
143
                    "type": "string",
144
                    "example": "auto"
145
                }
146
            }
147
        },
148
        "v1.historyResponse": {
149
            "type": "object",
150
            "properties": {
151
                "history": {
152
                    "type": "array",
153
                    "items": {
154
                        "$ref": "#/definitions/entity.Translation"
155
                    }
156
                }
157
            }
158
        },
159
        "v1.response": {
160
            "type": "object",
161
            "properties": {
162
                "error": {
163
                    "type": "string",
164
                    "example": "message"
165
                }
166
            }
167
        }
168
    }
169
}`
170

171
type swaggerInfo struct {
172
	Version     string
173
	Host        string
174
	BasePath    string
175
	Schemes     []string
176
	Title       string
177
	Description string
178
}
179

180
// SwaggerInfo holds exported Swagger Info so clients can modify it
181
var SwaggerInfo = swaggerInfo{
182
	Version:     "1.0",
183
	Host:        "localhost:8080",
184
	BasePath:    "/v1",
185
	Schemes:     []string{},
186
	Title:       "Go Clean Template API",
187
	Description: "Using a translation service as an example",
188
}
189

190
type s struct{}
191

192
func (s *s) ReadDoc() string {
193
	sInfo := SwaggerInfo
194
	sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
195

196
	t, err := template.New("swagger_info").Funcs(template.FuncMap{
197
		"marshal": func(v interface{}) string {
198
			a, _ := json.Marshal(v)
199
			return string(a)
200
		},
201
		"escape": func(v interface{}) string {
202
			// escape tabs
203
			str := strings.Replace(v.(string), "\t", "\\t", -1)
204
			// replace " with \", and if that results in \\", replace that with \\\"
205
			str = strings.Replace(str, "\"", "\\\"", -1)
206
			return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
207
		},
208
	}).Parse(doc)
209
	if err != nil {
210
		return doc
211
	}
212

213
	var tpl bytes.Buffer
214
	if err := t.Execute(&tpl, sInfo); err != nil {
215
		return doc
216
	}
217

218
	return tpl.String()
219
}
220

221
func init() {
222
	swag.Register(swag.Name, &s{})
223
}
224

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.