forked from swaggo/swag
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswagger.go
More file actions
41 lines (34 loc) · 726 Bytes
/
swagger.go
File metadata and controls
41 lines (34 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package swag
import (
"errors"
"sync"
)
// Name is a unique name be used to register swag instance.
const Name = "swagger"
var (
swaggerMu sync.RWMutex
swag 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 swag != nil {
panic("Register called twice for swag: " + name)
}
swag = swagger
}
// ReadDoc reads swagger document.
func ReadDoc() (string, error) {
if swag != nil {
return swag.ReadDoc(), nil
}
return "", errors.New("not yet registered swag")
}