mirror of
https://github.com/rancher/norman.git
synced 2025-09-05 01:00:36 +00:00
Update example
This commit is contained in:
48
README.md
48
README.md
@@ -16,46 +16,42 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"fmt"
|
||||
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/rancher/go-rancher/v3"
|
||||
"github.com/rancher/norman/api/crd"
|
||||
"github.com/rancher/norman/generator"
|
||||
"github.com/rancher/norman/server"
|
||||
"github.com/rancher/norman/types"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
types.Resource
|
||||
Name string `json:"name"`
|
||||
Foo string `json:"foo"`
|
||||
SubThing Baz `json:"subThing"`
|
||||
}
|
||||
|
||||
type Baz struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
var (
|
||||
version = client.APIVersion{
|
||||
version = types.APIVersion{
|
||||
Version: "v1",
|
||||
Group: "io.cattle.core.example",
|
||||
Path: "/example/v1",
|
||||
}
|
||||
|
||||
Foo = client.Schema{
|
||||
ID: "foo",
|
||||
Version: version,
|
||||
ResourceFields: map[string]*client.Field{
|
||||
"foo": {
|
||||
Type: "string",
|
||||
Create: true,
|
||||
Update: true,
|
||||
},
|
||||
"name": {
|
||||
Type: "string",
|
||||
Create: true,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Schemas = client.NewSchemas().
|
||||
AddSchema(&Foo)
|
||||
Schemas = types.NewSchemas()
|
||||
)
|
||||
|
||||
func main() {
|
||||
server, err := crd.NewAPIServer(context.Background(), os.Getenv("KUBECONFIG"), Schemas)
|
||||
if _, err := Schemas.Import(&version, Foo{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
server, err := server.NewAPIServer(context.Background(), os.Getenv("KUBECONFIG"), Schemas)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/rancher/norman/generator"
|
||||
"github.com/rancher/norman/server"
|
||||
"github.com/rancher/norman/types"
|
||||
)
|
||||
@@ -37,10 +36,6 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := generator.Generate("example_gen", Schemas); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
server, err := server.NewAPIServer(context.Background(), os.Getenv("KUBECONFIG"), Schemas)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Reference in New Issue
Block a user