mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-07 16:10:10 +00:00
Make / and /v1 work
This commit is contained in:
29
vendor/github.com/rancher/norman/pkg/api/builtin/schema.go
generated
vendored
29
vendor/github.com/rancher/norman/pkg/api/builtin/schema.go
generated
vendored
@@ -1,6 +1,8 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/rancher/norman/pkg/store/schema"
|
||||
"github.com/rancher/norman/pkg/types"
|
||||
)
|
||||
@@ -52,30 +54,12 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
APIRoot = types.Schema{
|
||||
ID: "apiRoot",
|
||||
CollectionMethods: []string{"GET"},
|
||||
ResourceMethods: []string{"GET"},
|
||||
ResourceFields: map[string]types.Field{
|
||||
"apiVersion": {Type: "map[json]"},
|
||||
"path": {Type: "string"},
|
||||
},
|
||||
Formatter: APIRootFormatter,
|
||||
Store: NewAPIRootStore(nil, nil),
|
||||
}
|
||||
|
||||
Schemas = types.EmptySchemas().
|
||||
MustAddSchema(Schema).
|
||||
MustAddSchema(Error).
|
||||
MustAddSchema(Collection).
|
||||
MustAddSchema(APIRoot)
|
||||
MustAddSchema(Collection)
|
||||
)
|
||||
|
||||
func apiVersionFromMap(schemas *types.Schemas, apiVersion map[string]interface{}) string {
|
||||
version, _ := apiVersion["version"].(string)
|
||||
return version
|
||||
}
|
||||
|
||||
func SchemaFormatter(apiOp *types.APIRequest, resource *types.RawResource) {
|
||||
schema := apiOp.Schemas.Schema(resource.ID)
|
||||
if schema == nil {
|
||||
@@ -88,6 +72,13 @@ func SchemaFormatter(apiOp *types.APIRequest, resource *types.RawResource) {
|
||||
}
|
||||
}
|
||||
|
||||
func getSchemaCollectionLink(apiOp *types.APIRequest, schema *types.Schema) string {
|
||||
if schema != nil && contains(schema.CollectionMethods, http.MethodGet) {
|
||||
return apiOp.URLBuilder.Collection(schema)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func contains(list []string, needle string) bool {
|
||||
for _, v := range list {
|
||||
if v == needle {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package builtin
|
||||
package apiroot
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -7,6 +7,20 @@ import (
|
||||
"github.com/rancher/norman/pkg/types"
|
||||
)
|
||||
|
||||
func Register(schemas *types.Schemas, versions, roots []string) {
|
||||
schemas.MustAddSchema(types.Schema{
|
||||
ID: "apiRoot",
|
||||
CollectionMethods: []string{"GET"},
|
||||
ResourceMethods: []string{"GET"},
|
||||
ResourceFields: map[string]types.Field{
|
||||
"apiVersion": {Type: "map[json]"},
|
||||
"path": {Type: "string"},
|
||||
},
|
||||
Formatter: APIRootFormatter,
|
||||
Store: NewAPIRootStore(versions, roots),
|
||||
})
|
||||
}
|
||||
|
||||
func APIRootFormatter(apiOp *types.APIRequest, resource *types.RawResource) {
|
||||
path, _ := resource.Values["path"].(string)
|
||||
if path == "" {
|
||||
@@ -86,6 +100,7 @@ func (a *APIRootStore) List(apiOp *types.APIRequest, schema *types.Schema, opt *
|
||||
|
||||
func apiVersionToAPIRootMap(version string) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": version,
|
||||
"type": "apiRoot",
|
||||
"apiVersion": map[string]interface{}{
|
||||
"version": version,
|
||||
@@ -93,3 +108,17 @@ func apiVersionToAPIRootMap(version string) map[string]interface{} {
|
||||
"path": "/" + version,
|
||||
}
|
||||
}
|
||||
|
||||
func apiVersionFromMap(schemas *types.Schemas, apiVersion map[string]interface{}) string {
|
||||
version, _ := apiVersion["version"].(string)
|
||||
return version
|
||||
}
|
||||
|
||||
func contains(list []string, needle string) bool {
|
||||
for _, v := range list {
|
||||
if v == needle {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
3
vendor/github.com/rancher/norman/pkg/urlbuilder/url.go
generated
vendored
3
vendor/github.com/rancher/norman/pkg/urlbuilder/url.go
generated
vendored
@@ -99,6 +99,9 @@ func (u *DefaultURLBuilder) Current() string {
|
||||
}
|
||||
|
||||
func (u *DefaultURLBuilder) RelativeToRoot(path string) string {
|
||||
if len(path) > 0 && path[0] != '/' {
|
||||
return u.responseURLBase + "/" + path
|
||||
}
|
||||
return u.responseURLBase + path
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user