You've already forked golang-base-project
Initial commit
This commit is contained in:
3
vendor/github.com/swaggo/files/.gitmodules
generated
vendored
Normal file
3
vendor/github.com/swaggo/files/.gitmodules
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "swagger-ui"]
|
||||
path = swagger-ui
|
||||
url = https://github.com/swagger-api/swagger-ui.git
|
21
vendor/github.com/swaggo/files/LICENSE
generated
vendored
Normal file
21
vendor/github.com/swaggo/files/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Swaggo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
5
vendor/github.com/swaggo/files/Makefile
generated
vendored
Normal file
5
vendor/github.com/swaggo/files/Makefile
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
all: build
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
fileb0x fileb0x/b0x.yaml
|
7
vendor/github.com/swaggo/files/README.md
generated
vendored
Normal file
7
vendor/github.com/swaggo/files/README.md
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# swaggerFiles
|
||||
|
||||
|
||||
Generate swagger ui embedded files by using:
|
||||
```
|
||||
make
|
||||
```
|
139
vendor/github.com/swaggo/files/ab0x.go
generated
vendored
Normal file
139
vendor/github.com/swaggo/files/ab0x.go
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
// Code generated by fileb0x at "2021-08-11 21:14:46.428511689 +0300 EEST m=+0.096329763" from config file "b0x.yaml" DO NOT EDIT.
|
||||
// modification hash(37610a5b0ca328f5072d5ee653766db2.84893f7d7f6af7d7916db9fe20160151)
|
||||
|
||||
package swaggerFiles
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"golang.org/x/net/webdav"
|
||||
)
|
||||
|
||||
var (
|
||||
// CTX is a context for webdav vfs
|
||||
CTX = context.Background()
|
||||
|
||||
// FS is a virtual memory file system
|
||||
FS = webdav.NewMemFS()
|
||||
|
||||
// Handler is used to server files through a http handler
|
||||
Handler *webdav.Handler
|
||||
|
||||
// HTTP is the http file system
|
||||
HTTP http.FileSystem = new(HTTPFS)
|
||||
)
|
||||
|
||||
// HTTPFS implements http.FileSystem
|
||||
type HTTPFS struct {
|
||||
// Prefix allows to limit the path of all requests. F.e. a prefix "css" would allow only calls to /css/*
|
||||
Prefix string
|
||||
}
|
||||
|
||||
func init() {
|
||||
err := CTX.Err()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Handler = &webdav.Handler{
|
||||
FileSystem: FS,
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Open a file
|
||||
func (hfs *HTTPFS) Open(path string) (http.File, error) {
|
||||
path = hfs.Prefix + path
|
||||
|
||||
f, err := FS.OpenFile(CTX, path, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// ReadFile is adapTed from ioutil
|
||||
func ReadFile(path string) ([]byte, error) {
|
||||
f, err := FS.OpenFile(CTX, path, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(make([]byte, 0, bytes.MinRead))
|
||||
|
||||
// If the buffer overflows, we will get bytes.ErrTooLarge.
|
||||
// Return that as an error. Any other panic remains.
|
||||
defer func() {
|
||||
e := recover()
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
if panicErr, ok := e.(error); ok && panicErr == bytes.ErrTooLarge {
|
||||
err = panicErr
|
||||
} else {
|
||||
panic(e)
|
||||
}
|
||||
}()
|
||||
_, err = buf.ReadFrom(f)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
// WriteFile is adapTed from ioutil
|
||||
func WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||
f, err := FS.OpenFile(CTX, filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := f.Write(data)
|
||||
if err == nil && n < len(data) {
|
||||
err = io.ErrShortWrite
|
||||
}
|
||||
if err1 := f.Close(); err == nil {
|
||||
err = err1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// WalkDirs looks for files in the given dir and returns a list of files in it
|
||||
// usage for all files in the b0x: WalkDirs("", false)
|
||||
func WalkDirs(name string, includeDirsInList bool, files ...string) ([]string, error) {
|
||||
f, err := FS.OpenFile(CTX, name, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileInfos, err := f.Readdir(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, info := range fileInfos {
|
||||
filename := path.Join(name, info.Name())
|
||||
|
||||
if includeDirsInList || !info.IsDir() {
|
||||
files = append(files, filename)
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
files, err = WalkDirs(filename, includeDirsInList, files...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
30
vendor/github.com/swaggo/files/b0xfile__favicon-16x16.png.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__favicon-16x16.png.go
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
// Code generaTed by fileb0x at "2021-08-11 21:11:48.973787292 +0300 EEST m=+0.273940433" from config file "b0x.yaml" DO NOT EDIT.
|
||||
// modified(2021-08-11 21:10:36.055919109 +0300 EEST)
|
||||
// original path: swagger-ui/dist/favicon-16x16.png
|
||||
|
||||
package swaggerFiles
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// FileFavicon16x16Png is "/favicon-16x16.png"
|
||||
var FileFavicon16x16Png = []byte("\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\x00\x00\x10\x00\x00\x00\x10\x08\x03\x00\x00\x00\x28\x2d\x0f\x53\x00\x00\x01\x35\x50\x4c\x54\x45\x62\xb1\x34\x61\xb1\x34\x5e\xab\x35\x5b\xa5\x35\x57\xa0\x37\x55\x9d\x37\x52\x97\x38\x51\x96\x38\x2f\x5e\x40\x2e\x5d\x40\x2d\x5a\x41\x2b\x57\x41\x33\x66\x3e\x34\x66\x3f\x39\x6f\x3d\x25\x4e\x43\x24\x4d\x43\x24\x4f\x43\x26\x4d\x42\x24\x4b\x42\x23\x4c\x42\x21\x49\x43\x24\x4b\x42\x24\x4c\x42\x24\x4d\x42\x25\x4d\x42\x24\x4e\x43\x25\x4e\x43\x1c\x41\x44\x1c\x3f\x45\x1f\x43\x44\x1d\x43\x44\x1f\x44\x44\x20\x45\x43\x22\x49\x43\x22\x49\x43\x23\x4a\x42\x27\x53\x41\x24\x4c\x43\x26\x50\x41\x22\x47\x42\x22\x48\x43\x29\x56\x41\x2b\x59\x3f\x24\x4d\x41\x25\x4d\x42\x14\x36\x46\x15\x34\x44\x15\x32\x47\x11\x33\x44\x12\x35\x46\x10\x31\x42\x0c\x31\x49\x15\x2b\x40\x00\x24\x49\x00\x33\x4d\x00\x33\x33\x00\x00\x00\x00\x00\x00\x85\xea\x2d\x84\xe9\x2c\x83\xe8\x2c\x82\xe6\x2d\x81\xe5\x2c\x7f\xe2\x2e\x80\xe1\x2e\x7d\xdd\x2e\x7c\xdd\x2e\x76\xd2\x30\x74\xd0\x30\x72\xca\x31\x71\xc9\x31\x70\xc8\x31\x6f\xc6\x32\x6d\xc5\x31\x6d\xc4\x31\x6c\xc3\x32\x6b\xc0\x32\x6a\xbf\x32\x69\xbe\x33\x68\xbb\x33\x68\xba\x33\x67\xb8\x33\x4b\x8d\x39\x4a\x8a\x3a\x4a\x89\x3a\x44\x7f\x3b\x43\x7f\x3c\x40\x79\x3d\x3e\x77\x3d\x39\x6e\x3e\x38\x6d\x3e\x38\x6e\x3f\x36\x6a\x3f\x35\x68\x3f\x33\x65\x3f\x1b\x3d\x45\x1b\x3e\x45\x1c\x3f\x45\x1c\x3d\x45\x1e\x43\x45\x1f\x44\x44\x20\x46\x44\x60\x25\x11\x2f\x00\x00\x00\x3b\x74\x52\x4e\x53\xf4\xf4\xf5\xf5\xf6\xf5\xf7\xf6\xee\xee\xef\xf0\xea\xea\xe7\xe1\xe1\xe0\xe0\xe3\xe3\xdf\xdc\xdb\xdb\xda\xd9\xd8\xd8\xdb\xcf\xbf\xbc\xba\xac\xab\xa9\xa9\xa1\x99\x96\x94\x8e\x89\x85\x84\x4c\x31\x24\x1e\x1d\x1f\x15\x0c\x07\x0a\x05\x01\x00\x07\x07\xae\xc9\x00\x00\x00\xd8\x49\x44\x41\x54\x78\xda\x3d\xcf\xd9\x2e\x43\x51\x18\x86\xe1\xcf\x6e\x8a\x8d\x52\x69\xa9\x22\x86\xb6\x31\xcf\x73\xd6\xbb\x5b\xb3\x84\x12\x1b\x41\x8c\x35\x94\x3b\x75\xe0\x86\xa4\x12\xc1\x5a\xcd\x4e\x9f\xa3\xff\xff\xce\x5e\x19\x6b\x2e\x97\x49\x76\x0f\x4c\x2d\xb9\x5b\xc6\xac\x0f\x77\x94\x4b\x50\x3a\x4e\x8c\xae\xba\x61\x63\x30\x4e\xa4\x69\x68\xcd\x0e\x85\x96\xe8\xdd\xdb\x24\x96\x37\x9a\xf7\xe1\xf2\x01\xeb\xf1\x1e\xda\x16\x54\x08\xe1\x7d\x0b\x6b\xe7\x0d\xc2\x49\xf5\x04\xf0\x1a\xe0\xbc\x40\xd0\xa7\x14\x5c\xdd\xec\x9f\x1f\x9c\x1e\x9e\x54\x2e\x20\xed\xfd\x49\xbf\x71\xff\xcb\xaf\xf9\xb5\xef\x98\xf4\xa3\x6c\x00\x4f\x45\x9c\xe7\x22\x41\xaf\xc6\x43\xa8\xee\x62\x6d\x57\xe1\x6c\x42\xcb\xad\x70\x5b\xc1\xba\xbb\x86\xf6\x45\x99\x31\x8f\x86\xe6\x9c\xf1\x94\xca\x7f\x28\xf2\x99\x49\x4b\x36\x70\xba\xf3\xc8\xc5\x95\x13\x23\xf5\x38\x6b\x65\x36\x9b\xec\xea\x9f\xa9\xe7\xff\x03\xcd\x4a\x39\x84\xc0\xe4\xbb\xd1\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82")
|
||||
|
||||
func init() {
|
||||
|
||||
f, err := FS.OpenFile(CTX, "/favicon-16x16.png", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = f.Write(FileFavicon16x16Png)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
30
vendor/github.com/swaggo/files/b0xfile__favicon-32x32.png.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__favicon-32x32.png.go
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
// Code generaTed by fileb0x at "2021-08-11 21:11:49.069266556 +0300 EEST m=+0.369419692" from config file "b0x.yaml" DO NOT EDIT.
|
||||
// modified(2021-08-11 21:10:36.055919109 +0300 EEST)
|
||||
// original path: swagger-ui/dist/favicon-32x32.png
|
||||
|
||||
package swaggerFiles
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// FileFavicon32x32Png is "/favicon-32x32.png"
|
||||
var FileFavicon32x32Png = []byte("\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\x00\x00\x20\x00\x00\x00\x20\x08\x03\x00\x00\x00\x44\xa4\x8a\xc6\x00\x00\x00\x90\x50\x4c\x54\x45\x00\x00\x00\x10\x33\x44\x16\x35\x46\x16\x36\x46\x17\x36\x46\x00\x2e\x3a\x16\x35\x46\x18\x38\x45\x17\x37\x46\x1a\x3c\x45\x0f\x31\x40\x14\x33\x44\x15\x35\x46\x16\x36\x46\x16\x35\x46\x16\x35\x45\x16\x35\x46\x15\x34\x46\x16\x36\x46\x16\x35\x46\x16\x33\x47\x85\xea\x2d\x17\x36\x47\x21\x47\x43\x81\xe5\x2c\x33\x66\x3f\x70\xc9\x31\x2f\x5e\x40\x37\x6b\x3e\x5a\xa5\x36\x7e\xe0\x2e\x43\x80\x3b\x77\xd4\x2f\x5f\xae\x35\x39\x6f\x3e\x6e\xc5\x32\x3f\x78\x3c\x73\xce\x30\x26\x4f\x42\x2c\x59\x41\x1e\x42\x45\x65\xb7\x34\x7a\xd9\x2e\x83\xe8\x2c\x48\x87\x3a\x4a\x8a\x3a\x49\x88\x3a\x4e\x90\x39\x78\x6f\x8d\xe5\x00\x00\x00\x15\x74\x52\x4e\x53\x00\x15\xcd\xf4\xe1\x07\x99\xfe\xf8\xfe\x10\x20\x77\xc4\xa9\x46\x8a\x53\xd7\xbd\x2d\x8a\x6b\xf8\x74\x00\x00\x01\x7e\x49\x44\x41\x54\x78\xda\x85\x53\xd9\x76\x82\x30\x10\x1d\x25\x10\x22\xee\x96\x09\x6b\x64\x07\xc5\xb6\xff\xff\x77\x2d\x49\x20\x14\x3d\xf6\xbe\x4c\x72\xe6\xce\x3e\x03\x06\xf6\x69\xbf\x26\xae\x4b\xd6\xfb\x93\x0d\xcf\x58\x39\x16\xb2\xb0\xfa\x7c\x54\x21\x43\xd7\x59\x2d\xf5\x5b\x0b\x93\x3c\xf0\x25\x82\x3c\x44\x6b\xfb\xc7\xcb\x66\x87\x49\xe4\xcf\x10\x25\xb8\xdb\x18\xbd\x47\xd8\xcd\x5f\x20\x67\xc4\x9b\xec\x09\x37\xe6\xc6\x09\x27\x3a\x11\x7b\x4d\x4b\xff\x05\x4a\xba\xb6\x55\x7e\x98\x0e\xff\xbe\x5c\xba\x49\xf1\x28\x03\x58\xc9\xf0\xab\x39\xc6\xa3\xa6\xa5\x71\x36\xc8\xc4\x1d\x82\x1c\xa9\xfc\x54\x58\xa4\x93\x69\x8c\x57\x69\x44\x9d\x5f\x82\x25\xdf\x7e\x8c\x99\x71\x5e\x63\x2b\xe5\xd5\xb5\xe1\x80\xaa\xc2\x06\xc5\xa4\xef\x05\x36\xf2\x71\xc3\x03\x38\x4c\xf5\x8f\xa3\x94\x1a\x94\x4b\x11\x30\x07\x2e\xb1\x7a\x62\xe7\xcf\xd0\x50\x45\x8f\x2f\x40\x0a\xd5\x38\x4c\xe6\x84\x02\x53\x25\xcf\xa0\xf2\x0d\x91\xd7\x7d\xdb\x65\x41\xc3\x85\xe0\x4d\x5f\x73\x0c\x65\x96\x16\xb8\x23\x21\x0b\x38\xbf\x0b\xce\x83\xac\x6b\xfb\xa8\x1b\x09\x3a\x84\xf8\x36\x21\x94\xc1\x97\xd0\x21\x76\x3a\x49\xca\xe6\x04\x36\x26\xb9\x03\x87\xf5\xba\x4c\xe1\x1b\x60\x37\x95\x79\xc2\x9b\x26\xdc\x8d\x5e\x20\x9f\x1a\x65\xbb\x57\xdd\xc9\xda\x10\xee\xb3\x56\xc3\x7e\x1c\x56\x6c\x86\x55\x60\x35\xc8\x4c\x0e\xcb\xa3\xa1\x34\x2a\xd8\x20\xf5\xe0\x78\x29\x6b\x91\xe3\x86\xa3\xee\x9a\x41\x54\xf6\xb3\x85\x01\xfb\xfc\xcf\xca\x81\x67\xbd\x5f\x5a\x80\x83\xc5\xf2\xa5\x3e\xa7\xc4\x83\x09\x1f\xe4\xfd\xe1\x00\xac\x2e\xf8\xf6\xf4\x86\x30\x67\x1c\x8e\xf7\xf1\x7c\xbc\x26\xce\xf6\xd5\xf9\xff\x00\xc6\x8c\x46\x7b\xbe\xb8\x05\x67\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82")
|
||||
|
||||
func init() {
|
||||
|
||||
f, err := FS.OpenFile(CTX, "/favicon-32x32.png", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = f.Write(FileFavicon32x32Png)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
30
vendor/github.com/swaggo/files/b0xfile__index.html.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__index.html.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__oauth2-redirect.html.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__oauth2-redirect.html.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-bundle.js.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-bundle.js.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-bundle.js.map.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-bundle.js.map.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle-core.js.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle-core.js.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle-core.js.map.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle-core.js.map.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle.js.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle.js.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle.js.map.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-es-bundle.js.map.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-standalone-preset.js.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-standalone-preset.js.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-standalone-preset.js.map.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui-standalone-preset.js.map.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.css.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.css.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.css.map.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.css.map.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.js.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.js.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.js.map.go
generated
vendored
Normal file
30
vendor/github.com/swaggo/files/b0xfile__swagger-ui.js.map.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
5
vendor/github.com/swaggo/files/go.mod
generated
vendored
Normal file
5
vendor/github.com/swaggo/files/go.mod
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
module github.com/swaggo/files
|
||||
|
||||
go 1.15
|
||||
|
||||
require golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d
|
7
vendor/github.com/swaggo/files/go.sum
generated
vendored
Normal file
7
vendor/github.com/swaggo/files/go.sum
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
16
vendor/github.com/swaggo/gin-swagger/.gitignore
generated
vendored
Normal file
16
vendor/github.com/swaggo/gin-swagger/.gitignore
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
dist
|
||||
|
||||
.idea
|
||||
vendor
|
||||
.envrc
|
10
vendor/github.com/swaggo/gin-swagger/.goreleaser.yml
generated
vendored
Normal file
10
vendor/github.com/swaggo/gin-swagger/.goreleaser.yml
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
builds:
|
||||
- skip: true
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-next"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
21
vendor/github.com/swaggo/gin-swagger/LICENSE
generated
vendored
Normal file
21
vendor/github.com/swaggo/gin-swagger/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Swaggo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
8
vendor/github.com/swaggo/gin-swagger/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
8
vendor/github.com/swaggo/gin-swagger/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
**Describe the PR**
|
||||
e.g. add cool parser.
|
||||
|
||||
**Relation issue**
|
||||
e.g. https://github.com/swaggo/gin-swagger/pull/123/files
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
168
vendor/github.com/swaggo/gin-swagger/README.md
generated
vendored
Normal file
168
vendor/github.com/swaggo/gin-swagger/README.md
generated
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
# gin-swagger
|
||||
|
||||
gin middleware to automatically generate RESTFUL API documentation with Swagger 2.0.
|
||||
|
||||
[](https://github.com/features/actions)
|
||||
[](https://codecov.io/gh/swaggo/gin-swagger)
|
||||
[](https://goreportcard.com/report/github.com/swaggo/gin-swagger)
|
||||
[](https://godoc.org/github.com/swaggo/gin-swagger)
|
||||
[](https://github.com/swaggo/gin-swagger/releases)
|
||||
|
||||
## Usage
|
||||
|
||||
### Start using it
|
||||
|
||||
1. Add comments to your API source code, [See Declarative Comments Format](https://swaggo.github.io/swaggo.io/declarative_comments_format/).
|
||||
2. Download [Swag](https://github.com/swaggo/swag) for Go by using:
|
||||
|
||||
```sh
|
||||
go get -u github.com/swaggo/swag/cmd/swag
|
||||
```
|
||||
|
||||
3. Run the [Swag](https://github.com/swaggo/swag) at your Go project root path(for instance `~/root/go-peoject-name`),
|
||||
[Swag](https://github.com/swaggo/swag) will parse comments and generate required files(`docs` folder and `docs/doc.go`)
|
||||
at `~/root/go-peoject-name/docs`.
|
||||
|
||||
```sh
|
||||
swag init
|
||||
```
|
||||
|
||||
4. Download [gin-swagger](https://github.com/swaggo/gin-swagger) by using:
|
||||
|
||||
```sh
|
||||
go get -u github.com/swaggo/gin-swagger
|
||||
go get -u github.com/swaggo/files
|
||||
```
|
||||
|
||||
Import following in your code:
|
||||
|
||||
```go
|
||||
import "github.com/swaggo/gin-swagger" // gin-swagger middleware
|
||||
import "github.com/swaggo/files" // swagger embed files
|
||||
|
||||
```
|
||||
|
||||
### Canonical example:
|
||||
|
||||
Now assume you have implemented a simple api as following:
|
||||
|
||||
```go
|
||||
// A get function which returns a hello world string by json
|
||||
func Helloworld(g *gin.Context) {
|
||||
g.JSON(http.StatusOK,"helloworld")
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
So how to use gin-swagger on api above? Just follow the following guide.
|
||||
|
||||
1. Add Comments for apis and main function with gin-swagger rules like following:
|
||||
|
||||
```go
|
||||
// @BasePath /api/v1
|
||||
|
||||
// PingExample godoc
|
||||
// @Summary ping example
|
||||
// @Schemes
|
||||
// @Description do ping
|
||||
// @Tags example
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} Helloworld
|
||||
// @Router /example/helloworld [get]
|
||||
func Helloworld(g *gin.Context) {
|
||||
g.JSON(http.StatusOK,"helloworld")
|
||||
}
|
||||
```
|
||||
|
||||
2. Use `swag init` command to generate a docs, docs generated will be stored at
|
||||
3. import the docs like this:
|
||||
I assume your project named `github.com/go-project-name/docs`.
|
||||
|
||||
```go
|
||||
import (
|
||||
docs "github.com/go-project-name/docs"
|
||||
)
|
||||
```
|
||||
|
||||
4. build your application and after that, go to http://localhost:8080/swagger/index.html ,you to see your Swagger UI.
|
||||
|
||||
5. The full code and folder relatives here:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
docs "github.com/go-project-name/docs"
|
||||
swaggerfiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"net/http"
|
||||
)
|
||||
// @BasePath /api/v1
|
||||
|
||||
// PingExample godoc
|
||||
// @Summary ping example
|
||||
// @Schemes
|
||||
// @Description do ping
|
||||
// @Tags example
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} Helloworld
|
||||
// @Router /example/helloworld [get]
|
||||
func Helloworld(g *gin.Context) {
|
||||
g.JSON(http.StatusOK,"helloworld")
|
||||
}
|
||||
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
docs.SwaggerInfo.BasePath = "/api/v1"
|
||||
v1 := r.Group("/api/v1")
|
||||
{
|
||||
eg := v1.Group("/example")
|
||||
{
|
||||
eg.GET("/helloworld",Helloworld)
|
||||
}
|
||||
}
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
|
||||
r.Run(":8080")
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Demo project tree, `swag init` is run at relative `.`
|
||||
|
||||
```
|
||||
.
|
||||
├── docs
|
||||
│ ├── docs.go
|
||||
│ ├── swagger.json
|
||||
│ └── swagger.yaml
|
||||
├── go.mod
|
||||
├── go.sum
|
||||
└── main.go
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
You can configure Swagger using different configuration options
|
||||
|
||||
```go
|
||||
func main() {
|
||||
r := gin.New()
|
||||
|
||||
ginSwagger.WrapHandler(swaggerFiles.Handler,
|
||||
ginSwagger.URL("http://localhost:8080/swagger/doc.json"),
|
||||
ginSwagger.DefaultModelsExpandDepth(-1))
|
||||
|
||||
r.Run()
|
||||
}
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| ------------------------ | ------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| URL | string | "doc.json" | URL pointing to API definition |
|
||||
| DocExpantion | string | "list" | Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). |
|
||||
| DeepLinking | bool | true | If set to true, enables deep linking for tags and operations. See the Deep Linking documentation for more information. |
|
||||
| DefaultModelsExpandDepth | int | 1 | Default expansion depth for models (set to -1 completely hide the models). |
|
||||
| InstanceName | string | "swagger" | The instance name of the swagger document. If multiple different swagger instances should be deployed on one gin router, ensure that each instance has a unique name (use the _--instanceName_ parameter to generate swagger documents with _swag init_). |
|
84
vendor/github.com/swaggo/gin-swagger/b0x.yml
generated
vendored
Normal file
84
vendor/github.com/swaggo/gin-swagger/b0x.yml
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
# all folders and files are relative to the path
|
||||
# where fileb0x was run at!
|
||||
|
||||
# default: main
|
||||
pkg: swaggerFiles
|
||||
|
||||
# destination
|
||||
dest: "./swaggerFiles/"
|
||||
|
||||
# gofmt
|
||||
# type: bool
|
||||
# default: false
|
||||
fmt: true
|
||||
|
||||
# compress files
|
||||
# at the moment, only supports gzip
|
||||
#
|
||||
# type: object
|
||||
compression:
|
||||
# activates the compression
|
||||
#
|
||||
# type: bool
|
||||
# default: false
|
||||
compress: false
|
||||
|
||||
# valid values are:
|
||||
# -> "NoCompression"
|
||||
# -> "BestSpeed"
|
||||
# -> "BestCompression"
|
||||
# -> "DefaultCompression" or ""
|
||||
#
|
||||
# type: string
|
||||
# default: "DefaultCompression" # when: Compress == true && Method == ""
|
||||
method: ""
|
||||
|
||||
# true = do it yourself (the file is written as gzip compressed file into the memory file system)
|
||||
# false = decompress files at run time (while writing file into memory file system)
|
||||
#
|
||||
# type: bool
|
||||
# default: false
|
||||
keep: false
|
||||
|
||||
# ---------------
|
||||
# -- DANGEROUS --
|
||||
# ---------------
|
||||
#
|
||||
# cleans the destination folder (only b0xfiles)
|
||||
# you should use this when using the spread function
|
||||
# type: bool
|
||||
# default: false
|
||||
clean: true
|
||||
|
||||
# default: ab0x.go
|
||||
output: "ab0x.go"
|
||||
|
||||
# [unexporTed] builds non-exporTed functions, variables and types...
|
||||
# type: bool
|
||||
# default: false
|
||||
unexporTed: false
|
||||
|
||||
# [spread] means it will make a file to hold all fileb0x data
|
||||
# and each file into a separaTed .go file
|
||||
#
|
||||
# example:
|
||||
# theres 2 files in the folder assets, they're: hello.json and world.txt
|
||||
# when spread is activaTed, fileb0x will make a file:
|
||||
# b0x.go or [output]'s data, assets_hello.json.go and assets_world.txt.go
|
||||
#
|
||||
#
|
||||
# type: bool
|
||||
# default: false
|
||||
spread: true
|
||||
|
||||
# type: array of objects
|
||||
custom:
|
||||
|
||||
- files:
|
||||
# everything inside the folder
|
||||
# type: array of strings
|
||||
- "./dist/"
|
||||
|
||||
# base is the path that will be removed from all files' path
|
||||
# type: string
|
||||
base: "dist"
|
12
vendor/github.com/swaggo/gin-swagger/go.mod
generated
vendored
Normal file
12
vendor/github.com/swaggo/gin-swagger/go.mod
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
module github.com/swaggo/gin-swagger
|
||||
|
||||
require (
|
||||
github.com/gin-contrib/gzip v0.0.3
|
||||
github.com/gin-gonic/gin v1.7.4
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
|
||||
github.com/swaggo/swag v1.7.4
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
|
||||
)
|
||||
|
||||
go 1.13
|
134
vendor/github.com/swaggo/gin-swagger/go.sum
generated
vendored
Normal file
134
vendor/github.com/swaggo/gin-swagger/go.sum
generated
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gin-contrib/gzip v0.0.3 h1:etUaeesHhEORpZMp18zoOhepboiWnFtXrBZxszWUn4k=
|
||||
github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||
github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM=
|
||||
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM=
|
||||
github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg=
|
||||
github.com/go-openapi/spec v0.20.3 h1:uH9RQ6vdyPSs2pSy9fL8QPspDF2AMIMPtmK5coSSjtQ=
|
||||
github.com/go-openapi/spec v0.20.3/go.mod h1:gG4F8wdEDN+YPBMVnzE85Rbhf+Th2DTvA9nFPQ5AYEg=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
|
||||
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
|
||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
|
||||
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM=
|
||||
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E=
|
||||
github.com/swaggo/swag v1.7.4 h1:up+ixy8yOqJKiFcuhMgkuYuF4xnevuhnFAXXF8OSfNg=
|
||||
github.com/swaggo/swag v1.7.4/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI=
|
||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
290
vendor/github.com/swaggo/gin-swagger/swagger.go
generated
vendored
Normal file
290
vendor/github.com/swaggo/gin-swagger/swagger.go
generated
vendored
Normal file
@ -0,0 +1,290 @@
|
||||
package ginSwagger
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/net/webdav"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/swag"
|
||||
)
|
||||
|
||||
type swaggerConfig struct {
|
||||
URL string
|
||||
DeepLinking bool
|
||||
DocExpansion string
|
||||
DefaultModelsExpandDepth int
|
||||
Oauth2RedirectURL template.JS
|
||||
}
|
||||
|
||||
// Config stores ginSwagger configuration variables.
|
||||
type Config struct {
|
||||
//The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
|
||||
URL string
|
||||
DeepLinking bool
|
||||
DocExpansion string
|
||||
DefaultModelsExpandDepth int
|
||||
InstanceName string
|
||||
}
|
||||
|
||||
// Convert the config to a swagger one in order to fill unexposed template values.
|
||||
func (c Config) ToSwaggerConfig() swaggerConfig {
|
||||
return swaggerConfig{
|
||||
URL: c.URL,
|
||||
DeepLinking: c.DeepLinking,
|
||||
DocExpansion: c.DocExpansion,
|
||||
DefaultModelsExpandDepth: c.DefaultModelsExpandDepth,
|
||||
Oauth2RedirectURL: template.JS(
|
||||
"`${window.location.protocol}//${window.location.host}$" +
|
||||
"{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" +
|
||||
"/oauth2-redirect.html`",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
|
||||
func URL(url string) func(c *Config) {
|
||||
return func(c *Config) {
|
||||
c.URL = url
|
||||
}
|
||||
}
|
||||
|
||||
// DocExpansion list, full, none.
|
||||
func DocExpansion(docExpansion string) func(c *Config) {
|
||||
return func(c *Config) {
|
||||
c.DocExpansion = docExpansion
|
||||
}
|
||||
}
|
||||
|
||||
// DeepLinking set the swagger deeplinking configuration
|
||||
func DeepLinking(deepLinking bool) func(c *Config) {
|
||||
return func(c *Config) {
|
||||
c.DeepLinking = deepLinking
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultModelsExpandDepth set the default expansion depth for models
|
||||
// (set to -1 completely hide the models).
|
||||
func DefaultModelsExpandDepth(depth int) func(c *Config) {
|
||||
return func(c *Config) {
|
||||
c.DefaultModelsExpandDepth = depth
|
||||
}
|
||||
}
|
||||
|
||||
// InstanceName set the instance name that was used to generate the swagger documents.
|
||||
// Defaults to swag.Name ("swagger").
|
||||
func InstanceName(name string) func(c *Config) {
|
||||
return func(c *Config) {
|
||||
c.InstanceName = name
|
||||
}
|
||||
}
|
||||
|
||||
// WrapHandler wraps `http.Handler` into `gin.HandlerFunc`.
|
||||
func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {
|
||||
defaultConfig := &Config{
|
||||
URL: "doc.json",
|
||||
DeepLinking: true,
|
||||
DocExpansion: "list",
|
||||
DefaultModelsExpandDepth: 1,
|
||||
InstanceName: swag.Name,
|
||||
}
|
||||
|
||||
for _, c := range confs {
|
||||
c(defaultConfig)
|
||||
}
|
||||
|
||||
return CustomWrapHandler(defaultConfig, h)
|
||||
}
|
||||
|
||||
// CustomWrapHandler wraps `http.Handler` into `gin.HandlerFunc`
|
||||
func CustomWrapHandler(config *Config, handler *webdav.Handler) gin.HandlerFunc {
|
||||
var once sync.Once
|
||||
|
||||
if config.InstanceName == "" {
|
||||
config.InstanceName = swag.Name
|
||||
}
|
||||
|
||||
// create a template with name
|
||||
t := template.New("swagger_index.html")
|
||||
index, _ := t.Parse(swagger_index_templ)
|
||||
|
||||
var rexp = regexp.MustCompile(`(.*)(index\.html|doc\.json|favicon-16x16\.png|favicon-32x32\.png|/oauth2-redirect\.html|swagger-ui\.css|swagger-ui\.css\.map|swagger-ui\.js|swagger-ui\.js\.map|swagger-ui-bundle\.js|swagger-ui-bundle\.js\.map|swagger-ui-standalone-preset\.js|swagger-ui-standalone-preset\.js\.map)[\?|.]*`)
|
||||
|
||||
return func(c *gin.Context) {
|
||||
matches := rexp.FindStringSubmatch(c.Request.RequestURI)
|
||||
|
||||
if len(matches) != 3 {
|
||||
c.Status(http.StatusNotFound)
|
||||
_, _ = c.Writer.Write([]byte("404 page not found"))
|
||||
return
|
||||
}
|
||||
|
||||
path := matches[2]
|
||||
once.Do(func() {
|
||||
handler.Prefix = matches[1]
|
||||
})
|
||||
|
||||
switch filepath.Ext(path) {
|
||||
case ".html":
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
case ".css":
|
||||
c.Header("Content-Type", "text/css; charset=utf-8")
|
||||
case ".js":
|
||||
c.Header("Content-Type", "application/javascript")
|
||||
case ".png":
|
||||
c.Header("Content-Type", "image/png")
|
||||
case ".json":
|
||||
c.Header("Content-Type", "application/json; charset=utf-8")
|
||||
}
|
||||
|
||||
switch path {
|
||||
case "index.html":
|
||||
_ = index.Execute(c.Writer, config.ToSwaggerConfig())
|
||||
case "doc.json":
|
||||
doc, err := swag.ReadDoc(config.InstanceName)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
}
|
||||
_, _ = c.Writer.Write([]byte(doc))
|
||||
default:
|
||||
handler.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DisablingWrapHandler turn handler off
|
||||
// if specified environment variable passed
|
||||
func DisablingWrapHandler(h *webdav.Handler, envName string) gin.HandlerFunc {
|
||||
eFlag := os.Getenv(envName)
|
||||
if eFlag != "" {
|
||||
return func(c *gin.Context) {
|
||||
// Simulate behavior when route unspecified and
|
||||
// return 404 HTTP code
|
||||
c.String(http.StatusNotFound, "")
|
||||
}
|
||||
}
|
||||
|
||||
return WrapHandler(h)
|
||||
}
|
||||
|
||||
// DisablingCustomWrapHandler turn handler off
|
||||
// if specified environment variable passed
|
||||
func DisablingCustomWrapHandler(config *Config, h *webdav.Handler, envName string) gin.HandlerFunc {
|
||||
eFlag := os.Getenv(envName)
|
||||
if eFlag != "" {
|
||||
return func(c *gin.Context) {
|
||||
// Simulate behavior when route unspecified and
|
||||
// return 404 HTTP code
|
||||
c.String(http.StatusNotFound, "")
|
||||
}
|
||||
}
|
||||
|
||||
return CustomWrapHandler(config, h)
|
||||
}
|
||||
|
||||
const swagger_index_templ = `<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||
<defs>
|
||||
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="locked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="close">
|
||||
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||
</symbol>
|
||||
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="expand">
|
||||
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||
</symbol>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="./swagger-ui-bundle.js"> </script>
|
||||
<script src="./swagger-ui-standalone-preset.js"> </script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "{{.URL}}",
|
||||
dom_id: '#swagger-ui',
|
||||
validatorUrl: null,
|
||||
oauth2RedirectUrl: {{.Oauth2RedirectURL}},
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout",
|
||||
docExpansion: "{{.DocExpansion}}",
|
||||
deepLinking: {{.DeepLinking}},
|
||||
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}
|
||||
})
|
||||
|
||||
window.ui = ui
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
`
|
22
vendor/github.com/swaggo/swag/.gitignore
generated
vendored
Normal file
22
vendor/github.com/swaggo/swag/.gitignore
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
dist
|
||||
testdata/simple*/docs
|
||||
testdata/quotes/docs
|
||||
testdata/quotes/quotes.so
|
||||
example/basic/docs/*
|
||||
example/celler/docs/*
|
||||
cover.out
|
||||
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
# Etc
|
||||
.DS_Store
|
||||
|
||||
/swag
|
||||
/swag.exe
|
31
vendor/github.com/swaggo/swag/.goreleaser.yml
generated
vendored
Normal file
31
vendor/github.com/swaggo/swag/.goreleaser.yml
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
build:
|
||||
main: cmd/swag/main.go
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
- 386
|
||||
ignore:
|
||||
- goos: darwin
|
||||
goarch: arm64
|
||||
archives:
|
||||
-
|
||||
replacements:
|
||||
darwin: Darwin
|
||||
linux: Linux
|
||||
windows: Windows
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
arm64: aarch64
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-next"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
46
vendor/github.com/swaggo/swag/CODE_OF_CONDUCT.md
generated
vendored
Normal file
46
vendor/github.com/swaggo/swag/CODE_OF_CONDUCT.md
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [gitter.im/swaggo/swag](https://gitter.im/swaggo/swag).The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
16
vendor/github.com/swaggo/swag/CONTRIBUTING.md
generated
vendored
Normal file
16
vendor/github.com/swaggo/swag/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# Contributing
|
||||
|
||||
When contributing to this repository, please first discuss the change you wish to make via issue,
|
||||
email, or any other method with the owners of this repository before making a change.
|
||||
|
||||
Please note we have a code of conduct, please follow it in all your interactions with the project.
|
||||
|
||||
## Pull Request Process
|
||||
|
||||
1. Fork it
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create new Pull Request
|
||||
|
||||
Please make an issue first if the change is likely to increase.
|
29
vendor/github.com/swaggo/swag/Dockerfile
generated
vendored
Normal file
29
vendor/github.com/swaggo/swag/Dockerfile
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# Dockerfile References: https://docs.docker.com/engine/reference/builder/
|
||||
|
||||
# Start from the latest golang base image
|
||||
FROM golang:1.14-alpine as builder
|
||||
|
||||
# Set the Current Working Directory inside the container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source from the current directory to the Working Directory inside the container
|
||||
COPY . .
|
||||
|
||||
# Build the Go app
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o swag cmd/swag/main.go
|
||||
|
||||
|
||||
######## Start a new stage from scratch #######
|
||||
FROM scratch
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the Pre-built binary file from the previous stage
|
||||
COPY --from=builder /app/swag .
|
||||
|
94
vendor/github.com/swaggo/swag/Makefile
generated
vendored
Normal file
94
vendor/github.com/swaggo/swag/Makefile
generated
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
GOCMD:=$(shell which go)
|
||||
GOLINT:=$(shell which golint)
|
||||
GOIMPORT:=$(shell which goimports)
|
||||
GOFMT:=$(shell which gofmt)
|
||||
GOBUILD:=$(GOCMD) build
|
||||
GOINSTALL:=$(GOCMD) install
|
||||
GOCLEAN:=$(GOCMD) clean
|
||||
GOTEST:=$(GOCMD) test
|
||||
GOGET:=$(GOCMD) get
|
||||
GOLIST:=$(GOCMD) list
|
||||
GOVET:=$(GOCMD) vet
|
||||
GOPATH:=$(shell $(GOCMD) env GOPATH)
|
||||
u := $(if $(update),-u)
|
||||
|
||||
BINARY_NAME:=swag
|
||||
PACKAGES:=$(shell $(GOLIST) github.com/swaggo/swag github.com/swaggo/swag/cmd/swag github.com/swaggo/swag/gen)
|
||||
GOFILES:=$(shell find . -name "*.go" -type f)
|
||||
|
||||
export GO111MODULE := on
|
||||
|
||||
all: test build
|
||||
|
||||
.PHONY: build
|
||||
build: deps
|
||||
$(GOBUILD) -o $(BINARY_NAME) ./cmd/swag
|
||||
|
||||
.PHONY: install
|
||||
install: deps
|
||||
$(GOINSTALL) ./cmd/swag
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
echo "mode: count" > coverage.out
|
||||
for PKG in $(PACKAGES); do \
|
||||
$(GOCMD) test -v -covermode=count -coverprofile=profile.out $$PKG > tmp.out; \
|
||||
cat tmp.out; \
|
||||
if grep -q "^--- FAIL" tmp.out; then \
|
||||
rm tmp.out; \
|
||||
exit 1; \
|
||||
elif grep -q "build failed" tmp.out; then \
|
||||
rm tmp.out; \
|
||||
exit; \
|
||||
fi; \
|
||||
if [ -f profile.out ]; then \
|
||||
cat profile.out | grep -v "mode:" >> coverage.out; \
|
||||
rm profile.out; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(GOCLEAN)
|
||||
rm -f $(BINARY_NAME)
|
||||
|
||||
.PHONY: deps
|
||||
deps:
|
||||
$(GOGET) github.com/swaggo/cli
|
||||
$(GOGET) github.com/ghodss/yaml
|
||||
$(GOGET) github.com/KyleBanks/depth
|
||||
$(GOGET) github.com/go-openapi/jsonreference
|
||||
$(GOGET) github.com/go-openapi/spec
|
||||
$(GOGET) github.com/stretchr/testify/assert
|
||||
$(GOGET) golang.org/x/tools/go/loader
|
||||
|
||||
.PHONY: devel-deps
|
||||
devel-deps:
|
||||
GO111MODULE=off $(GOGET) -v -u \
|
||||
golang.org/x/lint/golint
|
||||
|
||||
.PHONY: lint
|
||||
lint: devel-deps
|
||||
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
|
||||
|
||||
.PHONY: vet
|
||||
vet: deps devel-deps
|
||||
$(GOVET) $(PACKAGES)
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
$(GOFMT) -s -w $(GOFILES)
|
||||
|
||||
.PHONY: fmt-check
|
||||
fmt-check:
|
||||
@diff=$$($(GOFMT) -s -d $(GOFILES)); \
|
||||
if [ -n "$$diff" ]; then \
|
||||
echo "Please run 'make fmt' and commit the result:"; \
|
||||
echo "$${diff}"; \
|
||||
exit 1; \
|
||||
fi;
|
||||
|
||||
.PHONY: view-covered
|
||||
view-covered:
|
||||
$(GOTEST) -coverprofile=cover.out $(TARGET)
|
||||
$(GOCMD) tool cover -html=cover.out
|
8
vendor/github.com/swaggo/swag/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
8
vendor/github.com/swaggo/swag/PULL_REQUEST_TEMPLATE.md
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
**Describe the PR**
|
||||
e.g. add cool parser.
|
||||
|
||||
**Relation issue**
|
||||
e.g. https://github.com/swaggo/swag/pull/118/files
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
796
vendor/github.com/swaggo/swag/README.md
generated
vendored
Normal file
796
vendor/github.com/swaggo/swag/README.md
generated
vendored
Normal file
@ -0,0 +1,796 @@
|
||||
# swag
|
||||
|
||||
🌍 *[English](README.md) ∙ [简体中文](README_zh-CN.md)*
|
||||
|
||||
<img align="right" width="180px" src="https://raw.githubusercontent.com/swaggo/swag/master/assets/swaggo.png">
|
||||
|
||||
[](https://github.com/features/actions)
|
||||
[](https://codecov.io/gh/swaggo/swag)
|
||||
[](https://goreportcard.com/report/github.com/swaggo/swag)
|
||||
[](https://codebeat.co/projects/github-com-swaggo-swag-master)
|
||||
[](https://godoc.org/github.com/swaggo/swag)
|
||||
[](#backers)
|
||||
[](#sponsors) [](https://app.fossa.io/projects/git%2Bgithub.com%2Fswaggo%2Fswag?ref=badge_shield)
|
||||
[](https://github.com/swaggo/swag/releases)
|
||||
|
||||
|
||||
Swag converts Go annotations to Swagger Documentation 2.0. We've created a variety of plugins for popular [Go web frameworks](#supported-web-frameworks). This allows you to quickly integrate with an existing Go project (using Swagger UI).
|
||||
|
||||
## Contents
|
||||
- [Getting started](#getting-started)
|
||||
- [Supported Web Frameworks](#supported-web-frameworks)
|
||||
- [How to use it with Gin](#how-to-use-it-with-gin)
|
||||
- [Implementation Status](#implementation-status)
|
||||
- [Declarative Comments Format](#declarative-comments-format)
|
||||
- [General API Info](#general-api-info)
|
||||
- [API Operation](#api-operation)
|
||||
- [Security](#security)
|
||||
- [Examples](#examples)
|
||||
- [Descriptions over multiple lines](#descriptions-over-multiple-lines)
|
||||
- [User defined structure with an array type](#user-defined-structure-with-an-array-type)
|
||||
- [Model composition in response](#model-composition-in-response)
|
||||
- [Add a headers in response](#add-a-headers-in-response)
|
||||
- [Use multiple path params](#use-multiple-path-params)
|
||||
- [Example value of struct](#example-value-of-struct)
|
||||
- [Description of struct](#description-of-struct)
|
||||
- [Use swaggertype tag to supported custom type](#use-swaggertype-tag-to-supported-custom-type)
|
||||
- [Use swaggerignore tag to exclude a field](#use-swaggerignore-tag-to-exclude-a-field)
|
||||
- [Add extension info to struct field](#add-extension-info-to-struct-field)
|
||||
- [Rename model to display](#rename-model-to-display)
|
||||
- [How to using security annotations](#how-to-using-security-annotations)
|
||||
- [Add a description for enum items](#add-a-description-for-enum-items)
|
||||
- [About the Project](#about-the-project)
|
||||
|
||||
## Getting started
|
||||
|
||||
1. Add comments to your API source code, See [Declarative Comments Format](#declarative-comments-format).
|
||||
|
||||
2. Download swag by using:
|
||||
```sh
|
||||
$ go get -u github.com/swaggo/swag/cmd/swag
|
||||
|
||||
# 1.16 or newer
|
||||
$ go install github.com/swaggo/swag/cmd/swag@latest
|
||||
```
|
||||
To build from source you need [Go](https://golang.org/dl/) (1.13 or newer).
|
||||
|
||||
Or download a pre-compiled binary from the [release page](https://github.com/swaggo/swag/releases).
|
||||
|
||||
3. Run `swag init` in the project's root folder which contains the `main.go` file. This will parse your comments and generate the required files (`docs` folder and `docs/docs.go`).
|
||||
```sh
|
||||
$ swag init
|
||||
```
|
||||
|
||||
Make sure to import the generated `docs/docs.go` so that your specific configuration gets `init`'ed. If your General API annotations do not live in `main.go`, you can let swag know with `-g` flag.
|
||||
```sh
|
||||
swag init -g http/api.go
|
||||
```
|
||||
|
||||
## swag cli
|
||||
|
||||
```sh
|
||||
$ swag init -h
|
||||
NAME:
|
||||
swag init - Create docs.go
|
||||
|
||||
USAGE:
|
||||
swag init [command options] [arguments...]
|
||||
|
||||
OPTIONS:
|
||||
--generalInfo value, -g value Go file path in which 'swagger general API Info' is written (default: "main.go")
|
||||
--dir value, -d value Directory you want to parse (default: "./")
|
||||
--exclude value Exclude directories and files when searching, comma separated
|
||||
--propertyStrategy value, -p value Property Naming Strategy like snakecase,camelcase,pascalcase (default: "camelcase")
|
||||
--output value, -o value Output directory for all the generated files(swagger.json, swagger.yaml and doc.go) (default: "./docs")
|
||||
--parseVendor Parse go files in 'vendor' folder, disabled by default (default: false)
|
||||
--parseDependency Parse go files in outside dependency folder, disabled by default (default: false)
|
||||
--markdownFiles value, --md value Parse folder containing markdown files to use as description, disabled by default
|
||||
--codeExampleFiles value, --cef value Parse folder containing code example files to use for the x-codeSamples extension, disabled by default
|
||||
--parseInternal Parse go files in internal packages, disabled by default (default: false)
|
||||
--generatedTime Generate timestamp at the top of docs.go, disabled by default (default: false)
|
||||
--parseDepth value Dependency parse depth (default: 100)
|
||||
--instanceName value Set the swagger document instance name (default: "swagger")
|
||||
--help, -h show help (default: false)
|
||||
```
|
||||
|
||||
## Supported Web Frameworks
|
||||
|
||||
- [gin](http://github.com/swaggo/gin-swagger)
|
||||
- [echo](http://github.com/swaggo/echo-swagger)
|
||||
- [buffalo](https://github.com/swaggo/buffalo-swagger)
|
||||
- [net/http](https://github.com/swaggo/http-swagger)
|
||||
- [flamingo](https://github.com/i-love-flamingo/swagger)
|
||||
- [fiber](https://github.com/arsmn/fiber-swagger)
|
||||
- [atreugo](https://github.com/Nerzal/atreugo-swagger)
|
||||
|
||||
## How to use it with Gin
|
||||
|
||||
Find the example source code [here](https://github.com/swaggo/swag/tree/master/example/celler).
|
||||
|
||||
1. After using `swag init` to generate Swagger 2.0 docs, import the following packages:
|
||||
```go
|
||||
import "github.com/swaggo/gin-swagger" // gin-swagger middleware
|
||||
import "github.com/swaggo/files" // swagger embed files
|
||||
```
|
||||
|
||||
2. Add [General API](#general-api-info) annotations in `main.go` code:
|
||||
|
||||
```go
|
||||
// @title Swagger Example API
|
||||
// @version 1.0
|
||||
// @description This is a sample server celler server.
|
||||
// @termsOfService http://swagger.io/terms/
|
||||
|
||||
// @contact.name API Support
|
||||
// @contact.url http://www.swagger.io/support
|
||||
// @contact.email support@swagger.io
|
||||
|
||||
// @license.name Apache 2.0
|
||||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
// @host localhost:8080
|
||||
// @BasePath /api/v1
|
||||
// @query.collection.format multi
|
||||
|
||||
// @securityDefinitions.basic BasicAuth
|
||||
|
||||
// @securityDefinitions.apikey ApiKeyAuth
|
||||
// @in header
|
||||
// @name Authorization
|
||||
|
||||
// @securitydefinitions.oauth2.application OAuth2Application
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @securitydefinitions.oauth2.implicit OAuth2Implicit
|
||||
// @authorizationurl https://example.com/oauth/authorize
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @securitydefinitions.oauth2.password OAuth2Password
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @scope.read Grants read access
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @securitydefinitions.oauth2.accessCode OAuth2AccessCode
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @authorizationurl https://example.com/oauth/authorize
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @x-extension-openapi {"example": "value on a json format"}
|
||||
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
|
||||
c := controller.NewController()
|
||||
|
||||
v1 := r.Group("/api/v1")
|
||||
{
|
||||
accounts := v1.Group("/accounts")
|
||||
{
|
||||
accounts.GET(":id", c.ShowAccount)
|
||||
accounts.GET("", c.ListAccounts)
|
||||
accounts.POST("", c.AddAccount)
|
||||
accounts.DELETE(":id", c.DeleteAccount)
|
||||
accounts.PATCH(":id", c.UpdateAccount)
|
||||
accounts.POST(":id/images", c.UploadAccountImage)
|
||||
}
|
||||
//...
|
||||
}
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
r.Run(":8080")
|
||||
}
|
||||
//...
|
||||
```
|
||||
|
||||
Additionally some general API info can be set dynamically. The generated code package `docs` exports `SwaggerInfo` variable which we can use to set the title, description, version, host and base path programmatically. Example using Gin:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/files"
|
||||
"github.com/swaggo/gin-swagger"
|
||||
|
||||
"./docs" // docs is generated by Swag CLI, you have to import it.
|
||||
)
|
||||
|
||||
// @contact.name API Support
|
||||
// @contact.url http://www.swagger.io/support
|
||||
// @contact.email support@swagger.io
|
||||
|
||||
// @license.name Apache 2.0
|
||||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
// @termsOfService http://swagger.io/terms/
|
||||
|
||||
func main() {
|
||||
|
||||
// programmatically set swagger info
|
||||
docs.SwaggerInfo.Title = "Swagger Example API"
|
||||
docs.SwaggerInfo.Description = "This is a sample server Petstore server."
|
||||
docs.SwaggerInfo.Version = "1.0"
|
||||
docs.SwaggerInfo.Host = "petstore.swagger.io"
|
||||
docs.SwaggerInfo.BasePath = "/v2"
|
||||
docs.SwaggerInfo.Schemes = []string{"http", "https"}
|
||||
|
||||
r := gin.New()
|
||||
|
||||
// use ginSwagger middleware to serve the API docs
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
r.Run()
|
||||
}
|
||||
```
|
||||
|
||||
3. Add [API Operation](#api-operation) annotations in `controller` code
|
||||
|
||||
``` go
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/swag/example/celler/httputil"
|
||||
"github.com/swaggo/swag/example/celler/model"
|
||||
)
|
||||
|
||||
// ShowAccount godoc
|
||||
// @Summary Show a account
|
||||
// @Description get string by ID
|
||||
// @ID get-string-by-int
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "Account ID"
|
||||
// @Success 200 {object} model.Account
|
||||
// @Header 200 {string} Token "qwerty"
|
||||
// @Failure 400,404 {object} httputil.HTTPError
|
||||
// @Failure 500 {object} httputil.HTTPError
|
||||
// @Failure default {object} httputil.DefaultError
|
||||
// @Router /accounts/{id} [get]
|
||||
func (c *Controller) ShowAccount(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
aid, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
httputil.NewError(ctx, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
account, err := model.AccountOne(aid)
|
||||
if err != nil {
|
||||
httputil.NewError(ctx, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, account)
|
||||
}
|
||||
|
||||
// ListAccounts godoc
|
||||
// @Summary List accounts
|
||||
// @Description get accounts
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param q query string false "name search by q"
|
||||
// @Success 200 {array} model.Account
|
||||
// @Header 200 {string} Token "qwerty"
|
||||
// @Failure 400,404 {object} httputil.HTTPError
|
||||
// @Failure 500 {object} httputil.HTTPError
|
||||
// @Failure default {object} httputil.DefaultError
|
||||
// @Router /accounts [get]
|
||||
func (c *Controller) ListAccounts(ctx *gin.Context) {
|
||||
q := ctx.Request.URL.Query().Get("q")
|
||||
accounts, err := model.AccountsAll(q)
|
||||
if err != nil {
|
||||
httputil.NewError(ctx, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, accounts)
|
||||
}
|
||||
|
||||
//...
|
||||
```
|
||||
|
||||
```console
|
||||
$ swag init
|
||||
```
|
||||
|
||||
4. Run your app, and browse to http://localhost:8080/swagger/index.html. You will see Swagger 2.0 Api documents as shown below:
|
||||
|
||||

|
||||
|
||||
## Implementation Status
|
||||
|
||||
[Swagger 2.0 document](https://swagger.io/docs/specification/2-0/basic-structure/)
|
||||
|
||||
- [x] Basic Structure
|
||||
- [x] API Host and Base Path
|
||||
- [x] Paths and Operations
|
||||
- [x] Describing Parameters
|
||||
- [x] Describing Request Body
|
||||
- [x] Describing Responses
|
||||
- [x] MIME Types
|
||||
- [x] Authentication
|
||||
- [x] Basic Authentication
|
||||
- [x] API Keys
|
||||
- [x] Adding Examples
|
||||
- [x] File Upload
|
||||
- [x] Enums
|
||||
- [x] Grouping Operations With Tags
|
||||
- [ ] Swagger Extensions
|
||||
|
||||
# Declarative Comments Format
|
||||
|
||||
## General API Info
|
||||
|
||||
**Example**
|
||||
[celler/main.go](https://github.com/swaggo/swag/blob/master/example/celler/main.go)
|
||||
|
||||
| annotation | description | example |
|
||||
|-------------|--------------------------------------------|---------------------------------|
|
||||
| title | **Required.** The title of the application.| // @title Swagger Example API |
|
||||
| version | **Required.** Provides the version of the application API.| // @version 1.0 |
|
||||
| description | A short description of the application. |// @description This is a sample server celler server. |
|
||||
| tag.name | Name of a tag.| // @tag.name This is the name of the tag |
|
||||
| tag.description | Description of the tag | // @tag.description Cool Description |
|
||||
| tag.docs.url | Url of the external Documentation of the tag | // @tag.docs.url https://example.com|
|
||||
| tag.docs.description | Description of the external Documentation of the tag| // @tag.docs.description Best example documentation |
|
||||
| termsOfService | The Terms of Service for the API.| // @termsOfService http://swagger.io/terms/ |
|
||||
| contact.name | The contact information for the exposed API.| // @contact.name API Support |
|
||||
| contact.url | The URL pointing to the contact information. MUST be in the format of a URL. | // @contact.url http://www.swagger.io/support|
|
||||
| contact.email| The email address of the contact person/organization. MUST be in the format of an email address.| // @contact.email support@swagger.io |
|
||||
| license.name | **Required.** The license name used for the API.|// @license.name Apache 2.0|
|
||||
| license.url | A URL to the license used for the API. MUST be in the format of a URL. | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html |
|
||||
| host | The host (name or ip) serving the API. | // @host localhost:8080 |
|
||||
| BasePath | The base path on which the API is served. | // @BasePath /api/v1 |
|
||||
| accept | A list of MIME types the APIs can consume. Note that Accept only affects operations with a request body, such as POST, PUT and PATCH. Value MUST be as described under [Mime Types](#mime-types). | // @accept json |
|
||||
| produce | A list of MIME types the APIs can produce. Value MUST be as described under [Mime Types](#mime-types). | // @produce json |
|
||||
| query.collection.format | The default collection(array) param format in query,enums:csv,multi,pipes,tsv,ssv. If not set, csv is the default.| // @query.collection.format multi
|
||||
| schemes | The transfer protocol for the operation that separated by spaces. | // @schemes http https |
|
||||
| x-name | The extension key, must be start by x- and take only json value | // @x-example-key {"key": "value"} |
|
||||
|
||||
### Using markdown descriptions
|
||||
When a short string in your documentation is insufficient, or you need images, code examples and things like that you may want to use markdown descriptions. In order to use markdown descriptions use the following annotations.
|
||||
|
||||
|
||||
| annotation | description | example |
|
||||
|-------------|--------------------------------------------|---------------------------------|
|
||||
| title | **Required.** The title of the application.| // @title Swagger Example API |
|
||||
| version | **Required.** Provides the version of the application API.| // @version 1.0 |
|
||||
| description.markdown | A short description of the application. Parsed from the api.md file. This is an alternative to @description |// @description.markdown No value needed, this parses the description from api.md |
|
||||
| tag.name | Name of a tag.| // @tag.name This is the name of the tag |
|
||||
| tag.description.markdown | Description of the tag this is an alternative to tag.description. The description will be read from a file named like tagname.md | // @tag.description.markdown |
|
||||
|
||||
|
||||
## API Operation
|
||||
|
||||
**Example**
|
||||
[celler/controller](https://github.com/swaggo/swag/tree/master/example/celler/controller)
|
||||
|
||||
|
||||
| annotation | description |
|
||||
|-------------|----------------------------------------------------------------------------------------------------------------------------|
|
||||
| description | A verbose explanation of the operation behavior. |
|
||||
| description.markdown | A short description of the application. The description will be read from a file named like endpointname.md| // @description.file endpoint.description.markdown |
|
||||
| id | A unique string used to identify the operation. Must be unique among all API operations. |
|
||||
| tags | A list of tags to each API operation that separated by commas. |
|
||||
| summary | A short summary of what the operation does. |
|
||||
| accept | A list of MIME types the APIs can consume. Note that Accept only affects operations with a request body, such as POST, PUT and PATCH. Value MUST be as described under [Mime Types](#mime-types). |
|
||||
| produce | A list of MIME types the APIs can produce. Value MUST be as described under [Mime Types](#mime-types). |
|
||||
| param | Parameters that separated by spaces. `param name`,`param type`,`data type`,`is mandatory?`,`comment` `attribute(optional)` |
|
||||
| security | [Security](#security) to each API operation. |
|
||||
| success | Success response that separated by spaces. `return code or default`,`{param type}`,`data type`,`comment` |
|
||||
| failure | Failure response that separated by spaces. `return code or default`,`{param type}`,`data type`,`comment` |
|
||||
| response | As same as `success` and `failure` |
|
||||
| header | Header in response that separated by spaces. `return code`,`{param type}`,`data type`,`comment` |
|
||||
| router | Path definition that separated by spaces. `path`,`[httpMethod]` |
|
||||
| x-name | The extension key, must be start by x- and take only json value. |
|
||||
| x-codeSample | Optional Markdown usage. take `file` as parameter. This will then search for a file named like the summary in the given folder. |
|
||||
| deprecated | Mark endpoint as deprecated. |
|
||||
|
||||
|
||||
|
||||
## Mime Types
|
||||
|
||||
`swag` accepts all MIME Types which are in the correct format, that is, match `*/*`.
|
||||
Besides that, `swag` also accepts aliases for some MIME Types as follows:
|
||||
|
||||
| Alias | MIME Type |
|
||||
|-----------------------|-----------------------------------|
|
||||
| json | application/json |
|
||||
| xml | text/xml |
|
||||
| plain | text/plain |
|
||||
| html | text/html |
|
||||
| mpfd | multipart/form-data |
|
||||
| x-www-form-urlencoded | application/x-www-form-urlencoded |
|
||||
| json-api | application/vnd.api+json |
|
||||
| json-stream | application/x-json-stream |
|
||||
| octet-stream | application/octet-stream |
|
||||
| png | image/png |
|
||||
| jpeg | image/jpeg |
|
||||
| gif | image/gif |
|
||||
|
||||
|
||||
|
||||
## Param Type
|
||||
|
||||
- query
|
||||
- path
|
||||
- header
|
||||
- body
|
||||
- formData
|
||||
|
||||
## Data Type
|
||||
|
||||
- string (string)
|
||||
- integer (int, uint, uint32, uint64)
|
||||
- number (float32)
|
||||
- boolean (bool)
|
||||
- user defined struct
|
||||
|
||||
## Security
|
||||
| annotation | description | parameters | example |
|
||||
|------------|-------------|------------|---------|
|
||||
| securitydefinitions.basic | [Basic](https://swagger.io/docs/specification/2-0/authentication/basic-authentication/) auth. | | // @securityDefinitions.basic BasicAuth |
|
||||
| securitydefinitions.apikey | [API key](https://swagger.io/docs/specification/2-0/authentication/api-keys/) auth. | in, name | // @securityDefinitions.apikey ApiKeyAuth |
|
||||
| securitydefinitions.oauth2.application | [OAuth2 application](https://swagger.io/docs/specification/authentication/oauth2/) auth. | tokenUrl, scope | // @securitydefinitions.oauth2.application OAuth2Application |
|
||||
| securitydefinitions.oauth2.implicit | [OAuth2 implicit](https://swagger.io/docs/specification/authentication/oauth2/) auth. | authorizationUrl, scope | // @securitydefinitions.oauth2.implicit OAuth2Implicit |
|
||||
| securitydefinitions.oauth2.password | [OAuth2 password](https://swagger.io/docs/specification/authentication/oauth2/) auth. | tokenUrl, scope | // @securitydefinitions.oauth2.password OAuth2Password |
|
||||
| securitydefinitions.oauth2.accessCode | [OAuth2 access code](https://swagger.io/docs/specification/authentication/oauth2/) auth. | tokenUrl, authorizationUrl, scope | // @securitydefinitions.oauth2.accessCode OAuth2AccessCode |
|
||||
|
||||
|
||||
| parameters annotation | example |
|
||||
|-----------------------|----------------------------------------------------------|
|
||||
| in | // @in header |
|
||||
| name | // @name Authorization |
|
||||
| tokenUrl | // @tokenUrl https://example.com/oauth/token |
|
||||
| authorizationurl | // @authorizationurl https://example.com/oauth/authorize |
|
||||
| scope.hoge | // @scope.write Grants write access |
|
||||
|
||||
|
||||
## Attribute
|
||||
|
||||
```go
|
||||
// @Param enumstring query string false "string enums" Enums(A, B, C)
|
||||
// @Param enumint query int false "int enums" Enums(1, 2, 3)
|
||||
// @Param enumnumber query number false "int enums" Enums(1.1, 1.2, 1.3)
|
||||
// @Param string query string false "string valid" minlength(5) maxlength(10)
|
||||
// @Param int query int false "int valid" minimum(1) maximum(10)
|
||||
// @Param default query string false "string default" default(A)
|
||||
// @Param collection query []string false "string collection" collectionFormat(multi)
|
||||
// @Param extensions query []string false "string collection" extensions(x-example=test,x-nullable)
|
||||
|
||||
```
|
||||
|
||||
It also works for the struct fields:
|
||||
|
||||
```go
|
||||
type Foo struct {
|
||||
Bar string `minLength:"4" maxLength:"16"`
|
||||
Baz int `minimum:"10" maximum:"20" default:"15"`
|
||||
Qux []string `enums:"foo,bar,baz"`
|
||||
}
|
||||
```
|
||||
|
||||
### Available
|
||||
|
||||
Field Name | Type | Description
|
||||
---|:---:|---
|
||||
<a name="validate"></a>validate | `string` | Determines the validation for the parameter. Possible values are: `required`.
|
||||
<a name="parameterDefault"></a>default | * | Declares the value of the parameter that the server will use if none is provided, for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. (Note: "default" has no meaning for required parameters.) See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2. Unlike JSON Schema this value MUST conform to the defined [`type`](#parameterType) for this parameter.
|
||||
<a name="parameterMaximum"></a>maximum | `number` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.
|
||||
<a name="parameterMinimum"></a>minimum | `number` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.
|
||||
<a name="parameterMultipleOf"></a>multipleOf | `number` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.
|
||||
<a name="parameterMaxLength"></a>maxLength | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.
|
||||
<a name="parameterMinLength"></a>minLength | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.
|
||||
<a name="parameterEnums"></a>enums | [\*] | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1.
|
||||
<a name="parameterFormat"></a>format | `string` | The extending format for the previously mentioned [`type`](#parameterType). See [Data Type Formats](https://swagger.io/specification/v2/#dataTypeFormat) for further details.
|
||||
<a name="parameterCollectionFormat"></a>collectionFormat | `string` |Determines the format of the array if type array is used. Possible values are: <ul><li>`csv` - comma separated values `foo,bar`. <li>`ssv` - space separated values `foo bar`. <li>`tsv` - tab separated values `foo\tbar`. <li>`pipes` - pipe separated values <code>foo|bar</code>. <li>`multi` - corresponds to multiple parameter instances instead of multiple values for a single instance `foo=bar&foo=baz`. This is valid only for parameters [`in`](#parameterIn) "query" or "formData". </ul> Default value is `csv`.
|
||||
<a name="parameterExtensions"></a>extensions | `string` | Add extension to parameters.
|
||||
|
||||
### Future
|
||||
|
||||
Field Name | Type | Description
|
||||
---|:---:|---
|
||||
<a name="parameterPattern"></a>pattern | `string` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.
|
||||
<a name="parameterMaxItems"></a>maxItems | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.2.
|
||||
<a name="parameterMinItems"></a>minItems | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.3.
|
||||
<a name="parameterUniqueItems"></a>uniqueItems | `boolean` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.
|
||||
|
||||
## Examples
|
||||
|
||||
### Descriptions over multiple lines
|
||||
|
||||
You can add descriptions spanning multiple lines in either the general api description or routes definitions like so:
|
||||
|
||||
```go
|
||||
// @description This is the first line
|
||||
// @description This is the second line
|
||||
// @description And so forth.
|
||||
```
|
||||
|
||||
### User defined structure with an array type
|
||||
|
||||
```go
|
||||
// @Success 200 {array} model.Account <-- This is a user defined struct.
|
||||
```
|
||||
|
||||
```go
|
||||
package model
|
||||
|
||||
type Account struct {
|
||||
ID int `json:"id" example:"1"`
|
||||
Name string `json:"name" example:"account name"`
|
||||
}
|
||||
```
|
||||
|
||||
### Model composition in response
|
||||
```go
|
||||
// JSONResult's data field will be overridden by the specific type proto.Order
|
||||
@success 200 {object} jsonresult.JSONResult{data=proto.Order} "desc"
|
||||
```
|
||||
|
||||
```go
|
||||
type JSONResult struct {
|
||||
Code int `json:"code" `
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type Order struct { //in `proto` package
|
||||
Id uint `json:"id"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
```
|
||||
|
||||
- also support array of objects and primitive types as nested response
|
||||
```go
|
||||
@success 200 {object} jsonresult.JSONResult{data=[]proto.Order} "desc"
|
||||
@success 200 {object} jsonresult.JSONResult{data=string} "desc"
|
||||
@success 200 {object} jsonresult.JSONResult{data=[]string} "desc"
|
||||
```
|
||||
|
||||
- overriding multiple fields. field will be added if not exists
|
||||
```go
|
||||
@success 200 {object} jsonresult.JSONResult{data1=string,data2=[]string,data3=proto.Order,data4=[]proto.Order} "desc"
|
||||
```
|
||||
- overriding deep-level fields
|
||||
```go
|
||||
type DeepObject struct { //in `proto` package
|
||||
...
|
||||
}
|
||||
@success 200 {object} jsonresult.JSONResult{data1=proto.Order{data=proto.DeepObject},data2=[]proto.Order{data=[]proto.DeepObject}} "desc"
|
||||
```
|
||||
### Add a headers in response
|
||||
|
||||
```go
|
||||
// @Success 200 {string} string "ok"
|
||||
// @failure 400 {string} string "error"
|
||||
// @response default {string} string "other error"
|
||||
// @Header 200 {string} Location "/entity/1"
|
||||
// @Header 200,400,default {string} Token "token"
|
||||
// @Header all {string} Token2 "token2"
|
||||
```
|
||||
|
||||
### Use multiple path params
|
||||
|
||||
```go
|
||||
/// ...
|
||||
// @Param group_id path int true "Group ID"
|
||||
// @Param account_id path int true "Account ID"
|
||||
// ...
|
||||
// @Router /examples/groups/{group_id}/accounts/{account_id} [get]
|
||||
```
|
||||
|
||||
### Add multiple paths
|
||||
|
||||
```go
|
||||
/// ...
|
||||
// @Param group_id path int true "Group ID"
|
||||
// @Param user_id path int true "User ID"
|
||||
// ...
|
||||
// @Router /examples/groups/{group_id}/user/{user_id}/address [put]
|
||||
// @Router /examples/user/{user_id}/address [put]
|
||||
```
|
||||
|
||||
### Example value of struct
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
ID int `json:"id" example:"1"`
|
||||
Name string `json:"name" example:"account name"`
|
||||
PhotoUrls []string `json:"photo_urls" example:"http://test/image/1.jpg,http://test/image/2.jpg"`
|
||||
}
|
||||
```
|
||||
|
||||
### Description of struct
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
// ID this is userid
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"` // This is Name
|
||||
}
|
||||
```
|
||||
|
||||
### Use swaggertype tag to supported custom type
|
||||
[#201](https://github.com/swaggo/swag/issues/201#issuecomment-475479409)
|
||||
|
||||
```go
|
||||
type TimestampTime struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
///implement encoding.JSON.Marshaler interface
|
||||
func (t *TimestampTime) MarshalJSON() ([]byte, error) {
|
||||
bin := make([]byte, 16)
|
||||
bin = strconv.AppendInt(bin[:0], t.Time.Unix(), 10)
|
||||
return bin, nil
|
||||
}
|
||||
|
||||
func (t *TimestampTime) UnmarshalJSON(bin []byte) error {
|
||||
v, err := strconv.ParseInt(string(bin), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.Time = time.Unix(v, 0)
|
||||
return nil
|
||||
}
|
||||
///
|
||||
|
||||
type Account struct {
|
||||
// Override primitive type by simply specifying it via `swaggertype` tag
|
||||
ID sql.NullInt64 `json:"id" swaggertype:"integer"`
|
||||
|
||||
// Override struct type to a primitive type 'integer' by specifying it via `swaggertype` tag
|
||||
RegisterTime TimestampTime `json:"register_time" swaggertype:"primitive,integer"`
|
||||
|
||||
// Array types can be overridden using "array,<prim_type>" format
|
||||
Coeffs []big.Float `json:"coeffs" swaggertype:"array,number"`
|
||||
}
|
||||
```
|
||||
|
||||
[#379](https://github.com/swaggo/swag/issues/379)
|
||||
```go
|
||||
type CerticateKeyPair struct {
|
||||
Crt []byte `json:"crt" swaggertype:"string" format:"base64" example:"U3dhZ2dlciByb2Nrcw=="`
|
||||
Key []byte `json:"key" swaggertype:"string" format:"base64" example:"U3dhZ2dlciByb2Nrcw=="`
|
||||
}
|
||||
```
|
||||
generated swagger doc as follows:
|
||||
```go
|
||||
"api.MyBinding": {
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"crt":{
|
||||
"type":"string",
|
||||
"format":"base64",
|
||||
"example":"U3dhZ2dlciByb2Nrcw=="
|
||||
},
|
||||
"key":{
|
||||
"type":"string",
|
||||
"format":"base64",
|
||||
"example":"U3dhZ2dlciByb2Nrcw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Use swaggerignore tag to exclude a field
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Ignored int `swaggerignore:"true"`
|
||||
}
|
||||
```
|
||||
|
||||
### Add extension info to struct field
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
ID string `json:"id" extensions:"x-nullable,x-abc=def,!x-omitempty"` // extensions fields must start with "x-"
|
||||
}
|
||||
```
|
||||
|
||||
generate swagger doc as follows:
|
||||
|
||||
```go
|
||||
"Account": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"x-nullable": true,
|
||||
"x-abc": "def",
|
||||
"x-omitempty": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
### Rename model to display
|
||||
|
||||
```golang
|
||||
type Resp struct {
|
||||
Code int
|
||||
}//@name Response
|
||||
```
|
||||
|
||||
### How to using security annotations
|
||||
|
||||
General API info.
|
||||
|
||||
```go
|
||||
// @securityDefinitions.basic BasicAuth
|
||||
|
||||
// @securitydefinitions.oauth2.application OAuth2Application
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
```
|
||||
|
||||
Each API operation.
|
||||
|
||||
```go
|
||||
// @Security ApiKeyAuth
|
||||
```
|
||||
|
||||
Make it AND condition
|
||||
|
||||
```go
|
||||
// @Security ApiKeyAuth
|
||||
// @Security OAuth2Application[write, admin]
|
||||
```
|
||||
|
||||
### Add a description for enum items
|
||||
|
||||
```go
|
||||
type Example struct {
|
||||
// Sort order:
|
||||
// * asc - Ascending, from A to Z.
|
||||
// * desc - Descending, from Z to A.
|
||||
Order string `enums:"asc,desc"`
|
||||
}
|
||||
```
|
||||
|
||||
## About the Project
|
||||
This project was inspired by [yvasiyarov/swagger](https://github.com/yvasiyarov/swagger) but we simplified the usage and added support a variety of [web frameworks](#supported-web-frameworks). Gopher image source is [tenntenn/gopher-stickers](https://github.com/tenntenn/gopher-stickers). It has licenses [creative commons licensing](http://creativecommons.org/licenses/by/3.0/deed.en).
|
||||
## Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||
<a href="https://github.com/swaggo/swag/graphs/contributors"><img src="https://opencollective.com/swag/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
|
||||
## Backers
|
||||
|
||||
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/swag#backer)]
|
||||
|
||||
<a href="https://opencollective.com/swag#backers" target="_blank"><img src="https://opencollective.com/swag/backers.svg?width=890"></a>
|
||||
|
||||
|
||||
## Sponsors
|
||||
|
||||
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/swag#sponsor)]
|
||||
|
||||
<a href="https://opencollective.com/swag/sponsor/0/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/1/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/2/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/3/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/4/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/5/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/6/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/7/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/8/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/9/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/9/avatar.svg"></a>
|
||||
|
||||
|
||||
|
||||
|
||||
## License
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fswaggo%2Fswag?ref=badge_large)
|
750
vendor/github.com/swaggo/swag/README_zh-CN.md
generated
vendored
Normal file
750
vendor/github.com/swaggo/swag/README_zh-CN.md
generated
vendored
Normal file
@ -0,0 +1,750 @@
|
||||
# swag
|
||||
|
||||
🌍 *[English](README.md) ∙ [简体中文](README_zh-CN.md)*
|
||||
|
||||
<img align="right" width="180px" src="https://raw.githubusercontent.com/swaggo/swag/master/assets/swaggo.png">
|
||||
|
||||
[](https://travis-ci.org/swaggo/swag)
|
||||
[](https://codecov.io/gh/swaggo/swag)
|
||||
[](https://goreportcard.com/report/github.com/swaggo/swag)
|
||||
[](https://codebeat.co/projects/github-com-swaggo-swag-master)
|
||||
[](https://godoc.org/github.com/swaggo/swag)
|
||||
[](#backers)
|
||||
[](#sponsors) [](https://app.fossa.io/projects/git%2Bgithub.com%2Fswaggo%2Fswag?ref=badge_shield)
|
||||
[](https://github.com/swaggo/swag/releases)
|
||||
|
||||
Swag将Go的注释转换为Swagger2.0文档。我们为流行的 [Go Web Framework](#支持的Web框架) 创建了各种插件,这样可以与现有Go项目快速集成(使用Swagger UI)。
|
||||
|
||||
## 目录
|
||||
|
||||
- [快速开始](#快速开始)
|
||||
- [支持的Web框架](#支持的web框架)
|
||||
- [如何与Gin集成](#如何与gin集成)
|
||||
- [开发现状](#开发现状)
|
||||
- [声明式注释格式](#声明式注释格式)
|
||||
- [通用API信息](#通用api信息)
|
||||
- [API操作](#api操作)
|
||||
- [安全性](#安全性)
|
||||
- [样例](#样例)
|
||||
- [多行的描述](#多行的描述)
|
||||
- [用户自定义的具有数组类型的结构](#用户自定义的具有数组类型的结构)
|
||||
- [响应对象中的模型组合](#响应对象中的模型组合)
|
||||
- [在响应中增加头字段](#在响应中增加头字段)
|
||||
- [使用多路径参数](#使用多路径参数)
|
||||
- [结构体的示例值](#结构体的示例值)
|
||||
- [结构体描述](#结构体描述)
|
||||
- [使用`swaggertype`标签更改字段类型](#使用`swaggertype`标签更改字段类型)
|
||||
- [使用`swaggerignore`标签排除字段](#使用swaggerignore标签排除字段)
|
||||
- [将扩展信息添加到结构字段](#将扩展信息添加到结构字段)
|
||||
- [对展示的模型重命名](#对展示的模型重命名)
|
||||
- [如何使用安全性注释](#如何使用安全性注释)
|
||||
- [项目相关](#项目相关)
|
||||
|
||||
## 快速开始
|
||||
|
||||
1. 将注释添加到API源代码中,请参阅声明性注释格式。
|
||||
2. 使用如下命令下载swag:
|
||||
|
||||
```bash
|
||||
$ go get -u github.com/swaggo/swag/cmd/swag
|
||||
|
||||
# 1.16 及以上版本
|
||||
$ go install github.com/swaggo/swag/cmd/swag@latest
|
||||
```
|
||||
|
||||
从源码开始构建的话,需要有Go环境(1.13及以上版本)。
|
||||
|
||||
或者从github的release页面下载预编译好的二进制文件。
|
||||
|
||||
3. 在包含`main.go`文件的项目根目录运行`swag init`。这将会解析注释并生成需要的文件(`docs`文件夹和`docs/docs.go`)。
|
||||
|
||||
```bash
|
||||
swag init
|
||||
```
|
||||
|
||||
确保导入了生成的`docs/docs.go`文件,这样特定的配置文件才会被初始化。如果通用API指数没有写在`main.go`中,可以使用`-g`标识符来告知swag。
|
||||
|
||||
```bash
|
||||
swag init -g http/api.go
|
||||
```
|
||||
|
||||
## swag cli
|
||||
|
||||
```bash
|
||||
swag init -h
|
||||
NAME:
|
||||
swag init - Create docs.go
|
||||
|
||||
USAGE:
|
||||
swag init [command options] [arguments...]
|
||||
|
||||
OPTIONS:
|
||||
--generalInfo value, -g value API通用信息所在的go源文件路径,如果是相对路径则基于API解析目录 (默认: "main.go")
|
||||
--dir value, -d value API解析目录 (默认: "./")
|
||||
--propertyStrategy value, -p value 结构体字段命名规则,三种:snakecase,camelcase,pascalcase (默认: "camelcase")
|
||||
--output value, -o value 文件(swagger.json, swagger.yaml and doc.go)输出目录 (默认: "./docs")
|
||||
--parseVendor 是否解析vendor目录里的go源文件,默认不
|
||||
--parseDependency 是否解析依赖目录中的go源文件,默认不
|
||||
--markdownFiles value, --md value 指定API的描述信息所使用的markdown文件所在的目录
|
||||
--generatedTime 是否输出时间到输出文件docs.go的顶部,默认是
|
||||
```
|
||||
|
||||
## 支持的Web框架
|
||||
|
||||
- [gin](http://github.com/swaggo/gin-swagger)
|
||||
- [echo](http://github.com/swaggo/echo-swagger)
|
||||
- [buffalo](https://github.com/swaggo/buffalo-swagger)
|
||||
- [net/http](https://github.com/swaggo/http-swagger)
|
||||
|
||||
## 如何与Gin集成
|
||||
|
||||
[点击此处](https://github.com/swaggo/swag/tree/master/example/celler)查看示例源代码。
|
||||
|
||||
1. 使用`swag init`生成Swagger2.0文档后,导入如下代码包:
|
||||
|
||||
```go
|
||||
import "github.com/swaggo/gin-swagger" // gin-swagger middleware
|
||||
import "github.com/swaggo/files" // swagger embed files
|
||||
```
|
||||
|
||||
2. 在`main.go`源代码中添加通用的API注释:
|
||||
|
||||
```go
|
||||
// @title Swagger Example API
|
||||
// @version 1.0
|
||||
// @description This is a sample server celler server.
|
||||
// @termsOfService http://swagger.io/terms/
|
||||
|
||||
// @contact.name API Support
|
||||
// @contact.url http://www.swagger.io/support
|
||||
// @contact.email support@swagger.io
|
||||
|
||||
// @license.name Apache 2.0
|
||||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
// @host localhost:8080
|
||||
// @BasePath /api/v1
|
||||
// @query.collection.format multi
|
||||
|
||||
// @securityDefinitions.basic BasicAuth
|
||||
|
||||
// @securityDefinitions.apikey ApiKeyAuth
|
||||
// @in header
|
||||
// @name Authorization
|
||||
|
||||
// @securitydefinitions.oauth2.application OAuth2Application
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @securitydefinitions.oauth2.implicit OAuth2Implicit
|
||||
// @authorizationurl https://example.com/oauth/authorize
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @securitydefinitions.oauth2.password OAuth2Password
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @scope.read Grants read access
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @securitydefinitions.oauth2.accessCode OAuth2AccessCode
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @authorizationurl https://example.com/oauth/authorize
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
|
||||
// @x-extension-openapi {"example": "value on a json format"}
|
||||
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
|
||||
c := controller.NewController()
|
||||
|
||||
v1 := r.Group("/api/v1")
|
||||
{
|
||||
accounts := v1.Group("/accounts")
|
||||
{
|
||||
accounts.GET(":id", c.ShowAccount)
|
||||
accounts.GET("", c.ListAccounts)
|
||||
accounts.POST("", c.AddAccount)
|
||||
accounts.DELETE(":id", c.DeleteAccount)
|
||||
accounts.PATCH(":id", c.UpdateAccount)
|
||||
accounts.POST(":id/images", c.UploadAccountImage)
|
||||
}
|
||||
//...
|
||||
}
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
r.Run(":8080")
|
||||
}
|
||||
//...
|
||||
```
|
||||
|
||||
此外,可以动态设置一些通用的API信息。生成的代码包`docs`导出`SwaggerInfo`变量,使用该变量可以通过编码的方式设置标题、描述、版本、主机和基础路径。使用Gin的示例:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/files"
|
||||
"github.com/swaggo/gin-swagger"
|
||||
|
||||
"./docs" // docs is generated by Swag CLI, you have to import it.
|
||||
)
|
||||
|
||||
// @contact.name API Support
|
||||
// @contact.url http://www.swagger.io/support
|
||||
// @contact.email support@swagger.io
|
||||
|
||||
// @license.name Apache 2.0
|
||||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
// @termsOfService http://swagger.io/terms/
|
||||
|
||||
func main() {
|
||||
|
||||
// programatically set swagger info
|
||||
docs.SwaggerInfo.Title = "Swagger Example API"
|
||||
docs.SwaggerInfo.Description = "This is a sample server Petstore server."
|
||||
docs.SwaggerInfo.Version = "1.0"
|
||||
docs.SwaggerInfo.Host = "petstore.swagger.io"
|
||||
docs.SwaggerInfo.BasePath = "/v2"
|
||||
docs.SwaggerInfo.Schemes = []string{"http", "https"}
|
||||
|
||||
r := gin.New()
|
||||
|
||||
// use ginSwagger middleware to serve the API docs
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
r.Run()
|
||||
}
|
||||
```
|
||||
|
||||
3. 在`controller`代码中添加API操作注释:
|
||||
|
||||
```go
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/swag/example/celler/httputil"
|
||||
"github.com/swaggo/swag/example/celler/model"
|
||||
)
|
||||
|
||||
// ShowAccount godoc
|
||||
// @Summary Show a account
|
||||
// @Description get string by ID
|
||||
// @ID get-string-by-int
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "Account ID"
|
||||
// @Success 200 {object} model.Account
|
||||
// @Header 200 {string} Token "qwerty"
|
||||
// @Failure 400,404 {object} httputil.HTTPError
|
||||
// @Failure 500 {object} httputil.HTTPError
|
||||
// @Failure default {object} httputil.DefaultError
|
||||
// @Router /accounts/{id} [get]
|
||||
func (c *Controller) ShowAccount(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
aid, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
httputil.NewError(ctx, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
account, err := model.AccountOne(aid)
|
||||
if err != nil {
|
||||
httputil.NewError(ctx, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, account)
|
||||
}
|
||||
|
||||
// ListAccounts godoc
|
||||
// @Summary List accounts
|
||||
// @Description get accounts
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param q query string false "name search by q"
|
||||
// @Success 200 {array} model.Account
|
||||
// @Header 200 {string} Token "qwerty"
|
||||
// @Failure 400,404 {object} httputil.HTTPError
|
||||
// @Failure 500 {object} httputil.HTTPError
|
||||
// @Failure default {object} httputil.DefaultError
|
||||
// @Router /accounts [get]
|
||||
func (c *Controller) ListAccounts(ctx *gin.Context) {
|
||||
q := ctx.Request.URL.Query().Get("q")
|
||||
accounts, err := model.AccountsAll(q)
|
||||
if err != nil {
|
||||
httputil.NewError(ctx, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, accounts)
|
||||
}
|
||||
|
||||
//...
|
||||
```
|
||||
|
||||
```bash
|
||||
swag init
|
||||
```
|
||||
|
||||
4. 运行程序,然后在浏览器中访问 http://localhost:8080/swagger/index.html 。将看到Swagger 2.0 Api文档,如下所示:
|
||||
|
||||

|
||||
|
||||
## 开发现状
|
||||
|
||||
[Swagger 2.0 文档](https://swagger.io/docs/specification/2-0/basic-structure/)
|
||||
|
||||
- [x] Basic Structure
|
||||
- [x] API Host and Base Path
|
||||
- [x] Paths and Operations
|
||||
- [x] Describing Parameters
|
||||
- [x] Describing Request Body
|
||||
- [x] Describing Responses
|
||||
- [x] MIME Types
|
||||
- [x] Authentication
|
||||
- [x] Basic Authentication
|
||||
- [x] API Keys
|
||||
- [x] Adding Examples
|
||||
- [x] File Upload
|
||||
- [x] Enums
|
||||
- [x] Grouping Operations With Tags
|
||||
- [ ] Swagger Extensions
|
||||
|
||||
## 声明式注释格式
|
||||
|
||||
## 通用API信息
|
||||
|
||||
**示例** [`celler/main.go`](https://github.com/swaggo/swag/blob/master/example/celler/main.go)
|
||||
|
||||
| 注释 | 说明 | 示例 |
|
||||
| ----------------------- | ----------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
|
||||
| title | **必填** 应用程序的名称。 | // @title Swagger Example API |
|
||||
| version | **必填** 提供应用程序API的版本。 | // @version 1.0 |
|
||||
| description | 应用程序的简短描述。 | // @description This is a sample server celler server. |
|
||||
| tag.name | 标签的名称。 | // @tag.name This is the name of the tag |
|
||||
| tag.description | 标签的描述。 | // @tag.description Cool Description |
|
||||
| tag.docs.url | 标签的外部文档的URL。 | // @tag.docs.url https://example.com |
|
||||
| tag.docs.description | 标签的外部文档说明。 | // @tag.docs.description Best example documentation |
|
||||
| termsOfService | API的服务条款。 | // @termsOfService http://swagger.io/terms/ |
|
||||
| contact.name | 公开的API的联系信息。 | // @contact.name API Support |
|
||||
| contact.url | 联系信息的URL。 必须采用网址格式。 | // @contact.url http://www.swagger.io/support |
|
||||
| contact.email | 联系人/组织的电子邮件地址。 必须采用电子邮件地址的格式。 | // @contact.email support@swagger.io |
|
||||
| license.name | **必填** 用于API的许可证名称。 | // @license.name Apache 2.0 |
|
||||
| license.url | 用于API的许可证的URL。 必须采用网址格式。 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html |
|
||||
| host | 运行API的主机(主机名或IP地址)。 | // @host localhost:8080 |
|
||||
| BasePath | 运行API的基本路径。 | // @BasePath /api/v1 |
|
||||
| accept | API 可以使用的 MIME 类型列表。 请注意,Accept 仅影响具有请求正文的操作,例如 POST、PUT 和 PATCH。 值必须如“[Mime类型](#mime-types)”中所述。 | // @accept json |
|
||||
| produce | API可以生成的MIME类型的列表。值必须如“[Mime类型](#mime-types)”中所述。 | // @produce json |
|
||||
| query.collection.format | 请求URI query里数组参数的默认格式:csv,multi,pipes,tsv,ssv。 如果未设置,则默认为csv。 | // @query.collection.format multi |
|
||||
| schemes | 用空格分隔的请求的传输协议。 | // @schemes http https |
|
||||
| x-name | 扩展的键必须以x-开头,并且只能使用json值 | // @x-example-key {"key": "value"} |
|
||||
|
||||
### 使用Markdown描述
|
||||
|
||||
如果文档中的短字符串不足以完整表达,或者需要展示图片,代码示例等类似的内容,则可能需要使用Markdown描述。要使用Markdown描述,请使用一下注释。
|
||||
|
||||
| 注释 | 说明 | 示例 |
|
||||
| ------------------------ | ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- |
|
||||
| title | **必填** 应用程序的名称。 | // @title Swagger Example API |
|
||||
| version | **必填** 提供应用程序API的版本。 | // @version 1.0 |
|
||||
| description.markdown | 应用程序的简短描述。 从`api.md`文件中解析。 这是`@description`的替代用法。 | // @description.markdown No value needed, this parses the description from api.md |
|
||||
| tag.name | 标签的名称。 | // @tag.name This is the name of the tag |
|
||||
| tag.description.markdown | 标签说明,这是`tag.description`的替代用法。 该描述将从名为`tagname.md的`文件中读取。 | // @tag.description.markdown |
|
||||
|
||||
## API操作
|
||||
|
||||
Example [celler/controller](https://github.com/swaggo/swag/tree/master/example/celler/controller)
|
||||
|
||||
| 注释 | 描述 |
|
||||
| -------------------- | ------------------------------------------------------------------------------------------------------- |
|
||||
| description | 操作行为的详细说明。 |
|
||||
| description.markdown | 应用程序的简短描述。该描述将从名为`endpointname.md`的文件中读取。 |
|
||||
| id | 用于标识操作的唯一字符串。在所有API操作中必须唯一。 |
|
||||
| tags | 每个API操作的标签列表,以逗号分隔。 |
|
||||
| summary | 该操作的简短摘要。 |
|
||||
| accept | API 可以使用的 MIME 类型列表。 请注意,Accept 仅影响具有请求正文的操作,例如 POST、PUT 和 PATCH。 值必须如“[Mime类型](#mime-types)”中所述。 |
|
||||
| produce | API可以生成的MIME类型的列表。值必须如“[Mime类型](#mime-types)”中所述。 |
|
||||
| param | 用空格分隔的参数。`param name`,`param type`,`data type`,`is mandatory?`,`comment` `attribute(optional)` |
|
||||
| security | 每个API操作的[安全性](#安全性)。 |
|
||||
| success | 以空格分隔的成功响应。`return code`,`{param type}`,`data type`,`comment` |
|
||||
| failure | 以空格分隔的故障响应。`return code`,`{param type}`,`data type`,`comment` |
|
||||
| response | 与success、failure作用相同 |
|
||||
| header | 以空格分隔的头字段。 `return code`,`{param type}`,`data type`,`comment` |
|
||||
| router | 以空格分隔的路径定义。 `path`,`[httpMethod]` |
|
||||
| x-name | 扩展字段必须以`x-`开头,并且只能使用json值。 |
|
||||
|
||||
## Mime类型
|
||||
|
||||
`swag` 接受所有格式正确的MIME类型, 即使匹配 `*/*`。除此之外,`swag`还接受某些MIME类型的别名,如下所示:
|
||||
|
||||
| Alias | MIME Type |
|
||||
| --------------------- | --------------------------------- |
|
||||
| json | application/json |
|
||||
| xml | text/xml |
|
||||
| plain | text/plain |
|
||||
| html | text/html |
|
||||
| mpfd | multipart/form-data |
|
||||
| x-www-form-urlencoded | application/x-www-form-urlencoded |
|
||||
| json-api | application/vnd.api+json |
|
||||
| json-stream | application/x-json-stream |
|
||||
| octet-stream | application/octet-stream |
|
||||
| png | image/png |
|
||||
| jpeg | image/jpeg |
|
||||
| gif | image/gif |
|
||||
|
||||
## 参数类型
|
||||
|
||||
- query
|
||||
- path
|
||||
- header
|
||||
- body
|
||||
- formData
|
||||
|
||||
## 数据类型
|
||||
|
||||
- string (string)
|
||||
- integer (int, uint, uint32, uint64)
|
||||
- number (float32)
|
||||
- boolean (bool)
|
||||
- user defined struct
|
||||
|
||||
## 安全性
|
||||
|
||||
| 注释 | 描述 | 参数 | 示例 |
|
||||
| -------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------ |
|
||||
| securitydefinitions.basic | [Basic](https://swagger.io/docs/specification/2-0/authentication/basic-authentication/) auth. | | // @securityDefinitions.basic BasicAuth |
|
||||
| securitydefinitions.apikey | [API key](https://swagger.io/docs/specification/2-0/authentication/api-keys/) auth. | in, name | // @securityDefinitions.apikey ApiKeyAuth |
|
||||
| securitydefinitions.oauth2.application | [OAuth2 application](https://swagger.io/docs/specification/authentication/oauth2/) auth. | tokenUrl, scope | // @securitydefinitions.oauth2.application OAuth2Application |
|
||||
| securitydefinitions.oauth2.implicit | [OAuth2 implicit](https://swagger.io/docs/specification/authentication/oauth2/) auth. | authorizationUrl, scope | // @securitydefinitions.oauth2.implicit OAuth2Implicit |
|
||||
| securitydefinitions.oauth2.password | [OAuth2 password](https://swagger.io/docs/specification/authentication/oauth2/) auth. | tokenUrl, scope | // @securitydefinitions.oauth2.password OAuth2Password |
|
||||
| securitydefinitions.oauth2.accessCode | [OAuth2 access code](https://swagger.io/docs/specification/authentication/oauth2/) auth. | tokenUrl, authorizationUrl, scope | // @securitydefinitions.oauth2.accessCode OAuth2AccessCode |
|
||||
|
||||
| 参数注释 | 示例 |
|
||||
| ---------------- | -------------------------------------------------------- |
|
||||
| in | // @in header |
|
||||
| name | // @name Authorization |
|
||||
| tokenUrl | // @tokenUrl https://example.com/oauth/token |
|
||||
| authorizationurl | // @authorizationurl https://example.com/oauth/authorize |
|
||||
| scope.hoge | // @scope.write Grants write access |
|
||||
|
||||
## 属性
|
||||
|
||||
```go
|
||||
// @Param enumstring query string false "string enums" Enums(A, B, C)
|
||||
// @Param enumint query int false "int enums" Enums(1, 2, 3)
|
||||
// @Param enumnumber query number false "int enums" Enums(1.1, 1.2, 1.3)
|
||||
// @Param string query string false "string valid" minlength(5) maxlength(10)
|
||||
// @Param int query int false "int valid" minimum(1) maximum(10)
|
||||
// @Param default query string false "string default" default(A)
|
||||
// @Param collection query []string false "string collection" collectionFormat(multi)
|
||||
```
|
||||
|
||||
也适用于结构体字段:
|
||||
|
||||
```go
|
||||
type Foo struct {
|
||||
Bar string `minLength:"4" maxLength:"16"`
|
||||
Baz int `minimum:"10" maximum:"20" default:"15"`
|
||||
Qux []string `enums:"foo,bar,baz"`
|
||||
}
|
||||
```
|
||||
|
||||
### 当前可用的
|
||||
|
||||
| 字段名 | 类型 | 描述 |
|
||||
| ---------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| default | * | 声明如果未提供任何参数,则服务器将使用的默认参数值,例如,如果请求中的客户端未提供该参数,则用于控制每页结果数的“计数”可能默认为100。 (注意:“default”对于必需的参数没有意义)。参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2。 与JSON模式不同,此值务必符合此参数的定义[类型](#parameterType)。 |
|
||||
| maximum | `number` | 参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2. |
|
||||
| minimum | `number` | 参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3. |
|
||||
| maxLength | `integer` | 参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1. |
|
||||
| minLength | `integer` | 参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2. |
|
||||
| enums | [\*] | 参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1. |
|
||||
| format | `string` | 上面提到的[类型](#parameterType)的扩展格式。有关更多详细信息,请参见[数据类型格式](https://swagger.io/specification/v2/#dataTypeFormat)。 |
|
||||
| collectionFormat | `string` | 指定query数组参数的格式。 可能的值为: <ul><li>`csv` - 逗号分隔值 `foo,bar`. <li>`ssv` - 空格分隔值 `foo bar`. <li>`tsv` - 制表符分隔值 `foo\tbar`. <li>`pipes` - 管道符分隔值 <code>foo|bar</code>. <li>`multi` - 对应于多个参数实例,而不是单个实例 `foo=bar&foo=baz` 的多个值。这仅对“`query`”或“`formData`”中的参数有效。 </ul> 默认值是 `csv`。 |
|
||||
|
||||
### 进一步的
|
||||
|
||||
| 字段名 | 类型 | 描述 |
|
||||
| ----------- | :-------: | ---------------------------------------------------------------------------------- |
|
||||
| multipleOf | `number` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1. |
|
||||
| pattern | `string` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3. |
|
||||
| maxItems | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.2. |
|
||||
| minItems | `integer` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.3. |
|
||||
| uniqueItems | `boolean` | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4. |
|
||||
|
||||
## 样例
|
||||
|
||||
### 多行的描述
|
||||
|
||||
可以在常规api描述或路由定义中添加跨越多行的描述,如下所示:
|
||||
|
||||
```go
|
||||
// @description This is the first line
|
||||
// @description This is the second line
|
||||
// @description And so forth.
|
||||
```
|
||||
|
||||
### 用户自定义的具有数组类型的结构
|
||||
|
||||
```go
|
||||
// @Success 200 {array} model.Account <-- This is a user defined struct.
|
||||
```
|
||||
|
||||
```go
|
||||
package model
|
||||
|
||||
type Account struct {
|
||||
ID int `json:"id" example:"1"`
|
||||
Name string `json:"name" example:"account name"`
|
||||
}
|
||||
```
|
||||
|
||||
### 响应对象中的模型组合
|
||||
|
||||
```go
|
||||
// JSONResult的data字段类型将被proto.Order类型替换
|
||||
@success 200 {object} jsonresult.JSONResult{data=proto.Order} "desc"
|
||||
```
|
||||
|
||||
```go
|
||||
type JSONResult struct {
|
||||
Code int `json:"code" `
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type Order struct { //in `proto` package
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
- 还支持对象数组和原始类型作为嵌套响应
|
||||
|
||||
```go
|
||||
@success 200 {object} jsonresult.JSONResult{data=[]proto.Order} "desc"
|
||||
@success 200 {object} jsonresult.JSONResult{data=string} "desc"
|
||||
@success 200 {object} jsonresult.JSONResult{data=[]string} "desc"
|
||||
```
|
||||
|
||||
- 替换多个字段的类型。如果某字段不存在,将添加该字段。
|
||||
|
||||
```go
|
||||
@success 200 {object} jsonresult.JSONResult{data1=string,data2=[]string,data3=proto.Order,data4=[]proto.Order} "desc"
|
||||
```
|
||||
|
||||
### 在响应中增加头字段
|
||||
|
||||
```go
|
||||
// @Success 200 {string} string "ok"
|
||||
// @failure 400 {string} string "error"
|
||||
// @response default {string} string "other error"
|
||||
// @Header 200 {string} Location "/entity/1"
|
||||
// @Header 200,400,default {string} Token "token"
|
||||
// @Header all {string} Token2 "token2"
|
||||
```
|
||||
|
||||
### 使用多路径参数
|
||||
|
||||
```go
|
||||
/// ...
|
||||
// @Param group_id path int true "Group ID"
|
||||
// @Param account_id path int true "Account ID"
|
||||
// ...
|
||||
// @Router /examples/groups/{group_id}/accounts/{account_id} [get]
|
||||
```
|
||||
|
||||
### 结构体的示例值
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
ID int `json:"id" example:"1"`
|
||||
Name string `json:"name" example:"account name"`
|
||||
PhotoUrls []string `json:"photo_urls" example:"http://test/image/1.jpg,http://test/image/2.jpg"`
|
||||
}
|
||||
```
|
||||
|
||||
### 结构体描述
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
// ID this is userid
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"` // This is Name
|
||||
}
|
||||
```
|
||||
|
||||
### 使用`swaggertype`标签更改字段类型
|
||||
|
||||
[#201](https://github.com/swaggo/swag/issues/201#issuecomment-475479409)
|
||||
|
||||
```go
|
||||
type TimestampTime struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
///实现encoding.JSON.Marshaler接口
|
||||
func (t *TimestampTime) MarshalJSON() ([]byte, error) {
|
||||
bin := make([]byte, 16)
|
||||
bin = strconv.AppendInt(bin[:0], t.Time.Unix(), 10)
|
||||
return bin, nil
|
||||
}
|
||||
|
||||
///实现encoding.JSON.Unmarshaler接口
|
||||
func (t *TimestampTime) UnmarshalJSON(bin []byte) error {
|
||||
v, err := strconv.ParseInt(string(bin), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.Time = time.Unix(v, 0)
|
||||
return nil
|
||||
}
|
||||
///
|
||||
|
||||
type Account struct {
|
||||
// 使用`swaggertype`标签将别名类型更改为内置类型integer
|
||||
ID sql.NullInt64 `json:"id" swaggertype:"integer"`
|
||||
|
||||
// 使用`swaggertype`标签更改struct类型为内置类型integer
|
||||
RegisterTime TimestampTime `json:"register_time" swaggertype:"primitive,integer"`
|
||||
|
||||
// Array types can be overridden using "array,<prim_type>" format
|
||||
Coeffs []big.Float `json:"coeffs" swaggertype:"array,number"`
|
||||
}
|
||||
```
|
||||
|
||||
[#379](https://github.com/swaggo/swag/issues/379)
|
||||
|
||||
```go
|
||||
type CerticateKeyPair struct {
|
||||
Crt []byte `json:"crt" swaggertype:"string" format:"base64" example:"U3dhZ2dlciByb2Nrcw=="`
|
||||
Key []byte `json:"key" swaggertype:"string" format:"base64" example:"U3dhZ2dlciByb2Nrcw=="`
|
||||
}
|
||||
```
|
||||
|
||||
生成的swagger文档如下:
|
||||
|
||||
```go
|
||||
"api.MyBinding": {
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"crt":{
|
||||
"type":"string",
|
||||
"format":"base64",
|
||||
"example":"U3dhZ2dlciByb2Nrcw=="
|
||||
},
|
||||
"key":{
|
||||
"type":"string",
|
||||
"format":"base64",
|
||||
"example":"U3dhZ2dlciByb2Nrcw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 使用`swaggerignore`标签排除字段
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Ignored int `swaggerignore:"true"`
|
||||
}
|
||||
```
|
||||
|
||||
### 将扩展信息添加到结构字段
|
||||
|
||||
```go
|
||||
type Account struct {
|
||||
ID string `json:"id" extensions:"x-nullable,x-abc=def,!x-omitempty"` // 扩展字段必须以"x-"开头
|
||||
}
|
||||
```
|
||||
|
||||
生成swagger文档,如下所示:
|
||||
|
||||
```go
|
||||
"Account": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"x-nullable": true,
|
||||
"x-abc": "def",
|
||||
"x-omitempty": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 对展示的模型重命名
|
||||
|
||||
```go
|
||||
type Resp struct {
|
||||
Code int
|
||||
}//@name Response
|
||||
```
|
||||
|
||||
### 如何使用安全性注释
|
||||
|
||||
通用API信息。
|
||||
|
||||
```go
|
||||
// @securityDefinitions.basic BasicAuth
|
||||
|
||||
// @securitydefinitions.oauth2.application OAuth2Application
|
||||
// @tokenUrl https://example.com/oauth/token
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
```
|
||||
|
||||
每个API操作。
|
||||
|
||||
```go
|
||||
// @Security ApiKeyAuth
|
||||
```
|
||||
|
||||
使用AND条件。
|
||||
|
||||
```go
|
||||
// @Security ApiKeyAuth
|
||||
// @Security OAuth2Application[write, admin]
|
||||
```
|
||||
|
||||
## 项目相关
|
||||
|
||||
This project was inspired by [yvasiyarov/swagger](https://github.com/yvasiyarov/swagger) but we simplified the usage and added support a variety of [web frameworks](#supported-web-frameworks). Gopher image source is [tenntenn/gopher-stickers](https://github.com/tenntenn/gopher-stickers). It has licenses [creative commons licensing](http://creativecommons.org/licenses/by/3.0/deed.en).
|
||||
|
||||
## 贡献者
|
||||
|
||||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||
<a href="https://github.com/swaggo/swag/graphs/contributors"><img src="https://opencollective.com/swag/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
## 支持者
|
||||
|
||||
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/swag#backer)]
|
||||
|
||||
<a href="https://opencollective.com/swag#backers" target="_blank"><img src="https://opencollective.com/swag/backers.svg?width=890"></a>
|
||||
|
||||
## 赞助商
|
||||
|
||||
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/swag#sponsor)]
|
||||
|
||||
<a href="https://opencollective.com/swag/sponsor/0/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/1/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/2/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/3/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/4/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/5/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/6/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/7/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/8/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/swag/sponsor/9/website" target="_blank"><img src="https://opencollective.com/swag/sponsor/9/avatar.svg"></a>
|
||||
|
||||
## License
|
||||
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fswaggo%2Fswag?ref=badge_large)
|
5
vendor/github.com/swaggo/swag/doc.go
generated
vendored
Normal file
5
vendor/github.com/swaggo/swag/doc.go
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/*
|
||||
Package swag converts Go annotations to Swagger Documentation 2.0.
|
||||
See https://github.com/swaggo/swag for more information about swag.
|
||||
*/
|
||||
package swag // import "github.com/swaggo/swag"
|
14
vendor/github.com/swaggo/swag/go.mod
generated
vendored
Normal file
14
vendor/github.com/swaggo/swag/go.mod
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
module github.com/swaggo/swag
|
||||
|
||||
require (
|
||||
github.com/KyleBanks/depth v1.2.1
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/go-openapi/spec v0.20.3
|
||||
github.com/gofrs/uuid v4.0.0+incompatible
|
||||
github.com/shopspring/decimal v1.2.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
golang.org/x/tools v0.1.0
|
||||
)
|
||||
|
||||
go 1.13
|
100
vendor/github.com/swaggo/swag/go.sum
generated
vendored
Normal file
100
vendor/github.com/swaggo/swag/go.sum
generated
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM=
|
||||
github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg=
|
||||
github.com/go-openapi/spec v0.20.3 h1:uH9RQ6vdyPSs2pSy9fL8QPspDF2AMIMPtmK5coSSjtQ=
|
||||
github.com/go-openapi/spec v0.20.3/go.mod h1:gG4F8wdEDN+YPBMVnzE85Rbhf+Th2DTvA9nFPQ5AYEg=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
|
||||
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
||||
github.com/gofrs/uuid v1.2.0 h1:coDhrjgyJaglxSjxuJdqQSSdUpG3w6p1OwN2od6frBU=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
21
vendor/github.com/swaggo/swag/license
generated
vendored
Normal file
21
vendor/github.com/swaggo/swag/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Eason Lin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
1043
vendor/github.com/swaggo/swag/operation.go
generated
vendored
Normal file
1043
vendor/github.com/swaggo/swag/operation.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
341
vendor/github.com/swaggo/swag/packages.go
generated
vendored
Normal file
341
vendor/github.com/swaggo/swag/packages.go
generated
vendored
Normal file
@ -0,0 +1,341 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
goparser "go/parser"
|
||||
"go/token"
|
||||
"golang.org/x/tools/go/loader"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PackagesDefinitions map[package import path]*PackageDefinitions.
|
||||
type PackagesDefinitions struct {
|
||||
files map[*ast.File]*AstFileInfo
|
||||
packages map[string]*PackageDefinitions
|
||||
uniqueDefinitions map[string]*TypeSpecDef
|
||||
}
|
||||
|
||||
// NewPackagesDefinitions create object PackagesDefinitions.
|
||||
func NewPackagesDefinitions() *PackagesDefinitions {
|
||||
return &PackagesDefinitions{
|
||||
files: make(map[*ast.File]*AstFileInfo),
|
||||
packages: make(map[string]*PackageDefinitions),
|
||||
uniqueDefinitions: make(map[string]*TypeSpecDef),
|
||||
}
|
||||
}
|
||||
|
||||
// CollectAstFile collect ast.file.
|
||||
func (pkgs *PackagesDefinitions) CollectAstFile(packageDir, path string, astFile *ast.File) error {
|
||||
if pkgs.files == nil {
|
||||
pkgs.files = make(map[*ast.File]*AstFileInfo)
|
||||
}
|
||||
|
||||
if pkgs.packages == nil {
|
||||
pkgs.packages = make(map[string]*PackageDefinitions)
|
||||
}
|
||||
|
||||
// return without storing the file if we lack a packageDir
|
||||
if len(packageDir) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pd, ok := pkgs.packages[packageDir]
|
||||
if ok {
|
||||
// return without storing the file if it already exists
|
||||
_, exists := pd.Files[path]
|
||||
if exists {
|
||||
return nil
|
||||
}
|
||||
pd.Files[path] = astFile
|
||||
} else {
|
||||
pkgs.packages[packageDir] = &PackageDefinitions{
|
||||
Name: astFile.Name.Name,
|
||||
Files: map[string]*ast.File{path: astFile},
|
||||
TypeDefinitions: make(map[string]*TypeSpecDef),
|
||||
}
|
||||
}
|
||||
|
||||
pkgs.files[astFile] = &AstFileInfo{
|
||||
File: astFile,
|
||||
Path: path,
|
||||
PackagePath: packageDir,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RangeFiles for range the collection of ast.File in alphabetic order.
|
||||
func (pkgs *PackagesDefinitions) RangeFiles(handle func(filename string, file *ast.File) error) error {
|
||||
sortedFiles := make([]*AstFileInfo, 0, len(pkgs.files))
|
||||
for _, info := range pkgs.files {
|
||||
sortedFiles = append(sortedFiles, info)
|
||||
}
|
||||
|
||||
sort.Slice(sortedFiles, func(i, j int) bool {
|
||||
return strings.Compare(sortedFiles[i].Path, sortedFiles[j].Path) < 0
|
||||
})
|
||||
|
||||
for _, info := range sortedFiles {
|
||||
err := handle(info.Path, info.File)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseTypes parse types
|
||||
// @Return parsed definitions.
|
||||
func (pkgs *PackagesDefinitions) ParseTypes() (map[*TypeSpecDef]*Schema, error) {
|
||||
parsedSchemas := make(map[*TypeSpecDef]*Schema)
|
||||
for astFile, info := range pkgs.files {
|
||||
pkgs.parseTypesFromFile(astFile, info.PackagePath, parsedSchemas)
|
||||
}
|
||||
return parsedSchemas, nil
|
||||
}
|
||||
|
||||
func (pkgs *PackagesDefinitions) parseTypesFromFile(astFile *ast.File, packagePath string, parsedSchemas map[*TypeSpecDef]*Schema) {
|
||||
for _, astDeclaration := range astFile.Decls {
|
||||
if generalDeclaration, ok := astDeclaration.(*ast.GenDecl); ok && generalDeclaration.Tok == token.TYPE {
|
||||
for _, astSpec := range generalDeclaration.Specs {
|
||||
if typeSpec, ok := astSpec.(*ast.TypeSpec); ok {
|
||||
typeSpecDef := &TypeSpecDef{
|
||||
PkgPath: packagePath,
|
||||
File: astFile,
|
||||
TypeSpec: typeSpec,
|
||||
}
|
||||
|
||||
if idt, ok := typeSpec.Type.(*ast.Ident); ok && IsGolangPrimitiveType(idt.Name) && parsedSchemas != nil {
|
||||
parsedSchemas[typeSpecDef] = &Schema{
|
||||
PkgPath: typeSpecDef.PkgPath,
|
||||
Name: astFile.Name.Name,
|
||||
Schema: PrimitiveSchema(TransToValidSchemeType(idt.Name)),
|
||||
}
|
||||
}
|
||||
|
||||
if pkgs.uniqueDefinitions == nil {
|
||||
pkgs.uniqueDefinitions = make(map[string]*TypeSpecDef)
|
||||
}
|
||||
|
||||
fullName := typeSpecDef.FullName()
|
||||
anotherTypeDef, ok := pkgs.uniqueDefinitions[fullName]
|
||||
if ok {
|
||||
if typeSpecDef.PkgPath == anotherTypeDef.PkgPath {
|
||||
continue
|
||||
} else {
|
||||
delete(pkgs.uniqueDefinitions, fullName)
|
||||
}
|
||||
} else {
|
||||
pkgs.uniqueDefinitions[fullName] = typeSpecDef
|
||||
}
|
||||
|
||||
if pkgs.packages[typeSpecDef.PkgPath] == nil {
|
||||
pkgs.packages[typeSpecDef.PkgPath] = &PackageDefinitions{
|
||||
Name: astFile.Name.Name,
|
||||
TypeDefinitions: map[string]*TypeSpecDef{typeSpecDef.Name(): typeSpecDef},
|
||||
}
|
||||
} else if _, ok = pkgs.packages[typeSpecDef.PkgPath].TypeDefinitions[typeSpecDef.Name()]; !ok {
|
||||
pkgs.packages[typeSpecDef.PkgPath].TypeDefinitions[typeSpecDef.Name()] = typeSpecDef
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (pkgs *PackagesDefinitions) findTypeSpec(pkgPath string, typeName string) *TypeSpecDef {
|
||||
if pkgs.packages == nil {
|
||||
return nil
|
||||
}
|
||||
pd, found := pkgs.packages[pkgPath]
|
||||
if found {
|
||||
typeSpec, ok := pd.TypeDefinitions[typeName]
|
||||
if ok {
|
||||
return typeSpec
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pkgs *PackagesDefinitions) loadExternalPackage(importPath string) error {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
conf := loader.Config{
|
||||
ParserMode: goparser.ParseComments,
|
||||
Cwd: cwd,
|
||||
}
|
||||
|
||||
conf.Import(importPath)
|
||||
|
||||
lprog, err := conf.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, info := range lprog.AllPackages {
|
||||
pkgPath := info.Pkg.Path()
|
||||
if strings.HasPrefix(pkgPath, "vendor/") {
|
||||
pkgPath = pkgPath[7:]
|
||||
}
|
||||
for _, astFile := range info.Files {
|
||||
pkgs.parseTypesFromFile(astFile, pkgPath, nil)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// findPackagePathFromImports finds out the package path of a package via ranging imports of a ast.File
|
||||
// @pkg the name of the target package
|
||||
// @file current ast.File in which to search imports
|
||||
// @fuzzy search for the package path that the last part matches the @pkg if true
|
||||
// @return the package path of a package of @pkg.
|
||||
func (pkgs *PackagesDefinitions) findPackagePathFromImports(pkg string, file *ast.File, fuzzy bool) string {
|
||||
if file == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if strings.ContainsRune(pkg, '.') {
|
||||
pkg = strings.Split(pkg, ".")[0]
|
||||
}
|
||||
|
||||
hasAnonymousPkg := false
|
||||
|
||||
matchLastPathPart := func(pkgPath string) bool {
|
||||
paths := strings.Split(pkgPath, "/")
|
||||
if paths[len(paths)-1] == pkg {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// prior to match named package
|
||||
for _, imp := range file.Imports {
|
||||
if imp.Name != nil {
|
||||
if imp.Name.Name == pkg {
|
||||
return strings.Trim(imp.Path.Value, `"`)
|
||||
}
|
||||
if imp.Name.Name == "_" {
|
||||
hasAnonymousPkg = true
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
if pkgs.packages != nil {
|
||||
path := strings.Trim(imp.Path.Value, `"`)
|
||||
if fuzzy {
|
||||
if matchLastPathPart(path) {
|
||||
return path
|
||||
}
|
||||
} else if pd, ok := pkgs.packages[path]; ok && pd.Name == pkg {
|
||||
return path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// match unnamed package
|
||||
if hasAnonymousPkg && pkgs.packages != nil {
|
||||
for _, imp := range file.Imports {
|
||||
if imp.Name == nil {
|
||||
continue
|
||||
}
|
||||
if imp.Name.Name == "_" {
|
||||
path := strings.Trim(imp.Path.Value, `"`)
|
||||
if fuzzy {
|
||||
if matchLastPathPart(path) {
|
||||
return path
|
||||
}
|
||||
} else if pd, ok := pkgs.packages[path]; ok && pd.Name == pkg {
|
||||
return path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// FindTypeSpec finds out TypeSpecDef of a type by typeName
|
||||
// @typeName the name of the target type, if it starts with a package name, find its own package path from imports on top of @file
|
||||
// @file the ast.file in which @typeName is used
|
||||
// @pkgPath the package path of @file.
|
||||
func (pkgs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File, parseDependency bool) *TypeSpecDef {
|
||||
if IsGolangPrimitiveType(typeName) {
|
||||
return nil
|
||||
}
|
||||
if file == nil { // for test
|
||||
return pkgs.uniqueDefinitions[typeName]
|
||||
}
|
||||
|
||||
parts := strings.Split(typeName, ".")
|
||||
if len(parts) > 1 {
|
||||
isAliasPkgName := func(file *ast.File, pkgName string) bool {
|
||||
if file != nil && file.Imports != nil {
|
||||
for _, pkg := range file.Imports {
|
||||
if pkg.Name != nil && pkg.Name.Name == pkgName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if !isAliasPkgName(file, parts[0]) {
|
||||
typeDef, ok := pkgs.uniqueDefinitions[typeName]
|
||||
if ok {
|
||||
return typeDef
|
||||
}
|
||||
}
|
||||
pkgPath := pkgs.findPackagePathFromImports(parts[0], file, false)
|
||||
if len(pkgPath) == 0 {
|
||||
//check if the current package
|
||||
if parts[0] == file.Name.Name {
|
||||
pkgPath = pkgs.files[file].PackagePath
|
||||
} else if parseDependency {
|
||||
//take it as an external package, needs to be loaded
|
||||
if pkgPath = pkgs.findPackagePathFromImports(parts[0], file, true); len(pkgPath) > 0 {
|
||||
if err := pkgs.loadExternalPackage(pkgPath); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pkgs.findTypeSpec(pkgPath, parts[1])
|
||||
}
|
||||
|
||||
typeDef, ok := pkgs.uniqueDefinitions[fullTypeName(file.Name.Name, typeName)]
|
||||
if ok {
|
||||
return typeDef
|
||||
}
|
||||
|
||||
typeDef = pkgs.findTypeSpec(pkgs.files[file].PackagePath, typeName)
|
||||
if typeDef != nil {
|
||||
return typeDef
|
||||
}
|
||||
|
||||
for _, imp := range file.Imports {
|
||||
if imp.Name != nil && imp.Name.Name == "." {
|
||||
typeDef := pkgs.findTypeSpec(strings.Trim(imp.Path.Value, `"`), typeName)
|
||||
if typeDef != nil {
|
||||
return typeDef
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
1689
vendor/github.com/swaggo/swag/parser.go
generated
vendored
Normal file
1689
vendor/github.com/swaggo/swag/parser.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
197
vendor/github.com/swaggo/swag/schema.go
generated
vendored
Normal file
197
vendor/github.com/swaggo/swag/schema.go
generated
vendored
Normal file
@ -0,0 +1,197 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/spec"
|
||||
)
|
||||
|
||||
const (
|
||||
// ARRAY array.
|
||||
ARRAY = "array"
|
||||
// OBJECT object.
|
||||
OBJECT = "object"
|
||||
// PRIMITIVE primitive.
|
||||
PRIMITIVE = "primitive"
|
||||
// BOOLEAN boolean.
|
||||
BOOLEAN = "boolean"
|
||||
// INTEGER integer.
|
||||
INTEGER = "integer"
|
||||
// NUMBER number.
|
||||
NUMBER = "number"
|
||||
// STRING string.
|
||||
STRING = "string"
|
||||
// FUNC func.
|
||||
FUNC = "func"
|
||||
// ANY any
|
||||
ANY = "any"
|
||||
// NIL nil
|
||||
NIL = "nil"
|
||||
)
|
||||
|
||||
// CheckSchemaType checks if typeName is not a name of primitive type.
|
||||
func CheckSchemaType(typeName string) error {
|
||||
if !IsPrimitiveType(typeName) {
|
||||
return fmt.Errorf("%s is not basic types", typeName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsSimplePrimitiveType determine whether the type name is a simple primitive type.
|
||||
func IsSimplePrimitiveType(typeName string) bool {
|
||||
switch typeName {
|
||||
case STRING, NUMBER, INTEGER, BOOLEAN:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsPrimitiveType determine whether the type name is a primitive type.
|
||||
func IsPrimitiveType(typeName string) bool {
|
||||
switch typeName {
|
||||
case STRING, NUMBER, INTEGER, BOOLEAN, ARRAY, OBJECT, FUNC:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsNumericType determines whether the swagger type name is a numeric type.
|
||||
func IsNumericType(typeName string) bool {
|
||||
return typeName == INTEGER || typeName == NUMBER
|
||||
}
|
||||
|
||||
// TransToValidSchemeType indicates type will transfer golang basic type to swagger supported type.
|
||||
func TransToValidSchemeType(typeName string) string {
|
||||
switch typeName {
|
||||
case "uint", "int", "uint8", "int8", "uint16", "int16", "byte":
|
||||
return INTEGER
|
||||
case "uint32", "int32", "rune":
|
||||
return INTEGER
|
||||
case "uint64", "int64":
|
||||
return INTEGER
|
||||
case "float32", "float64":
|
||||
return NUMBER
|
||||
case "bool":
|
||||
return BOOLEAN
|
||||
case "string":
|
||||
return STRING
|
||||
}
|
||||
|
||||
return typeName
|
||||
}
|
||||
|
||||
// IsGolangPrimitiveType determine whether the type name is a golang primitive type.
|
||||
func IsGolangPrimitiveType(typeName string) bool {
|
||||
switch typeName {
|
||||
case "uint",
|
||||
"int",
|
||||
"uint8",
|
||||
"int8",
|
||||
"uint16",
|
||||
"int16",
|
||||
"byte",
|
||||
"uint32",
|
||||
"int32",
|
||||
"rune",
|
||||
"uint64",
|
||||
"int64",
|
||||
"float32",
|
||||
"float64",
|
||||
"bool",
|
||||
"string":
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// TransToValidCollectionFormat determine valid collection format.
|
||||
func TransToValidCollectionFormat(format string) string {
|
||||
switch format {
|
||||
case "csv", "multi", "pipes", "tsv", "ssv":
|
||||
return format
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// TypeDocName get alias from comment '// @name ', otherwise the original type name to display in doc.
|
||||
func TypeDocName(pkgName string, spec *ast.TypeSpec) string {
|
||||
if spec != nil {
|
||||
if spec.Comment != nil {
|
||||
for _, comment := range spec.Comment.List {
|
||||
text := strings.TrimSpace(comment.Text)
|
||||
text = strings.TrimLeft(text, "//")
|
||||
text = strings.TrimSpace(text)
|
||||
texts := strings.Split(text, " ")
|
||||
if len(texts) > 1 && strings.ToLower(texts[0]) == "@name" {
|
||||
return texts[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
if spec.Name != nil {
|
||||
return fullTypeName(strings.Split(pkgName, ".")[0], spec.Name.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return pkgName
|
||||
}
|
||||
|
||||
// RefSchema build a reference schema.
|
||||
func RefSchema(refType string) *spec.Schema {
|
||||
return spec.RefSchema("#/definitions/" + refType)
|
||||
}
|
||||
|
||||
// PrimitiveSchema build a primitive schema.
|
||||
func PrimitiveSchema(refType string) *spec.Schema {
|
||||
return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{refType}}}
|
||||
}
|
||||
|
||||
// BuildCustomSchema build custom schema specified by tag swaggertype.
|
||||
func BuildCustomSchema(types []string) (*spec.Schema, error) {
|
||||
if len(types) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch types[0] {
|
||||
case PRIMITIVE:
|
||||
if len(types) == 1 {
|
||||
return nil, errors.New("need primitive type after primitive")
|
||||
}
|
||||
|
||||
return BuildCustomSchema(types[1:])
|
||||
case ARRAY:
|
||||
if len(types) == 1 {
|
||||
return nil, errors.New("need array item type after array")
|
||||
}
|
||||
schema, err := BuildCustomSchema(types[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return spec.ArrayProperty(schema), nil
|
||||
case OBJECT:
|
||||
if len(types) == 1 {
|
||||
return PrimitiveSchema(types[0]), nil
|
||||
}
|
||||
schema, err := BuildCustomSchema(types[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return spec.MapProperty(schema), nil
|
||||
default:
|
||||
err := CheckSchemaType(types[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return PrimitiveSchema(types[0]), nil
|
||||
}
|
||||
}
|
61
vendor/github.com/swaggo/swag/swagger.go
generated
vendored
Normal file
61
vendor/github.com/swaggo/swag/swagger.go
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Name is a unique name be used to register swag instance.
|
||||
const Name = "swagger"
|
||||
|
||||
var (
|
||||
swaggerMu sync.RWMutex
|
||||
swags map[string]Swagger
|
||||
)
|
||||
|
||||
// Swagger is a interface to read swagger document.
|
||||
type Swagger interface {
|
||||
ReadDoc() string
|
||||
}
|
||||
|
||||
// Register registers swagger for given name.
|
||||
func Register(name string, swagger Swagger) {
|
||||
swaggerMu.Lock()
|
||||
defer swaggerMu.Unlock()
|
||||
if swagger == nil {
|
||||
panic("swagger is nil")
|
||||
}
|
||||
|
||||
if swags == nil {
|
||||
swags = make(map[string]Swagger)
|
||||
}
|
||||
|
||||
if _, ok := swags[name]; ok {
|
||||
panic("Register called twice for swag: " + name)
|
||||
}
|
||||
swags[name] = swagger
|
||||
}
|
||||
|
||||
// ReadDoc reads swagger document. An optional name parameter can be passed to read a specific document.
|
||||
// The default name is "swagger".
|
||||
func ReadDoc(optionalName ...string) (string, error) {
|
||||
swaggerMu.RLock()
|
||||
defer swaggerMu.RUnlock()
|
||||
|
||||
if swags == nil {
|
||||
return "", errors.New("no swag has yet been registered")
|
||||
}
|
||||
|
||||
name := Name
|
||||
if len(optionalName) != 0 && optionalName[0] != "" {
|
||||
name = optionalName[0]
|
||||
}
|
||||
|
||||
swag, ok := swags[name]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("no swag named \"%s\" was registered", name)
|
||||
}
|
||||
|
||||
return swag.ReadDoc(), nil
|
||||
}
|
60
vendor/github.com/swaggo/swag/types.go
generated
vendored
Normal file
60
vendor/github.com/swaggo/swag/types.go
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
|
||||
"github.com/go-openapi/spec"
|
||||
)
|
||||
|
||||
// Schema parsed schema.
|
||||
type Schema struct {
|
||||
PkgPath string // package import path used to rename Name of a definition int case of conflict
|
||||
Name string // Name in definitions
|
||||
*spec.Schema //
|
||||
}
|
||||
|
||||
// TypeSpecDef the whole information of a typeSpec.
|
||||
type TypeSpecDef struct {
|
||||
// path of package starting from under ${GOPATH}/src or from module path in go.mod
|
||||
PkgPath string
|
||||
|
||||
// ast file where TypeSpec is
|
||||
File *ast.File
|
||||
|
||||
// the TypeSpec of this type definition
|
||||
TypeSpec *ast.TypeSpec
|
||||
}
|
||||
|
||||
// Name the name of the typeSpec.
|
||||
func (t *TypeSpecDef) Name() string {
|
||||
return t.TypeSpec.Name.Name
|
||||
}
|
||||
|
||||
// FullName full name of the typeSpec.
|
||||
func (t *TypeSpecDef) FullName() string {
|
||||
return fullTypeName(t.File.Name.Name, t.TypeSpec.Name.Name)
|
||||
}
|
||||
|
||||
// AstFileInfo information of an ast.File.
|
||||
type AstFileInfo struct {
|
||||
// File ast.File
|
||||
File *ast.File
|
||||
|
||||
// Path the path of the ast.File
|
||||
Path string
|
||||
|
||||
// PackagePath package import path of the ast.File
|
||||
PackagePath string
|
||||
}
|
||||
|
||||
// PackageDefinitions files and definition in a package.
|
||||
type PackageDefinitions struct {
|
||||
// package name
|
||||
Name string
|
||||
|
||||
// files in this package, map key is file's relative path starting package path
|
||||
Files map[string]*ast.File
|
||||
|
||||
// definitions in this package, map key is typeName
|
||||
TypeDefinitions map[string]*TypeSpecDef
|
||||
}
|
4
vendor/github.com/swaggo/swag/version.go
generated
vendored
Normal file
4
vendor/github.com/swaggo/swag/version.go
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
package swag
|
||||
|
||||
// Version of swag.
|
||||
const Version = "v1.7.4"
|
Reference in New Issue
Block a user