begin move to go-restful
This commit is contained in:
50
pkg/apiutils/apiutils.go
Normal file
50
pkg/apiutils/apiutils.go
Normal file
@ -0,0 +1,50 @@
|
||||
package apiutils
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
restfulspec "github.com/emicklei/go-restful-openapi"
|
||||
)
|
||||
|
||||
// Prepare does the default API preparation.
|
||||
func Prepare() {
|
||||
restful.DefaultRequestContentType(restful.MIME_JSON)
|
||||
restful.DefaultResponseContentType(restful.MIME_JSON)
|
||||
restful.DefaultContainer.Router(restful.CurlyRouter{})
|
||||
}
|
||||
|
||||
// Setup does the default API setup
|
||||
func Setup(addWebServices func()) {
|
||||
Prepare()
|
||||
|
||||
addWebServices()
|
||||
|
||||
SetupHealth()
|
||||
SetupOpenAPI()
|
||||
SetupCORSWildcard()
|
||||
}
|
||||
|
||||
func SetupHealth() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// SetupOpenAPI creates the standard API documentation endpoint at the default location.
|
||||
func SetupOpenAPI() {
|
||||
SetupOpenAPIAt("/swagger.json")
|
||||
}
|
||||
|
||||
// SetupOpenAPI creates the standard API documentation endpoint at the defined location.
|
||||
func SetupOpenAPIAt(apiPath string) {
|
||||
config := restfulspec.Config{
|
||||
WebServices: restful.RegisteredWebServices(),
|
||||
APIPath: apiPath,
|
||||
}
|
||||
restful.Add(restfulspec.NewOpenAPIService(config))
|
||||
}
|
||||
|
||||
func SetupCORSWildcard() {
|
||||
restful.Filter(restful.CrossOriginResourceSharing{
|
||||
CookiesAllowed: true,
|
||||
Container: restful.DefaultContainer,
|
||||
}.Filter)
|
||||
restful.Filter(restful.OPTIONSFilter())
|
||||
}
|
Reference in New Issue
Block a user