Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
2 contributors

Users who have contributed to this file

@easonlin404 @pei0804
41 lines (34 sloc) 726 Bytes
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")
}
You can’t perform that action at this time.