1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-31 06:35:09 +00:00
Files
norman/example/main.go

67 lines
1.3 KiB
Go
Raw Normal View History

2017-11-10 21:44:02 -07:00
package main
import (
2018-02-09 13:31:12 -07:00
"context"
2017-11-10 21:44:02 -07:00
"fmt"
"net/http"
"os"
2017-11-28 14:28:25 -07:00
"github.com/rancher/norman/api"
"github.com/rancher/norman/store/crd"
2018-02-09 13:31:12 -07:00
"github.com/rancher/norman/store/proxy"
2017-11-10 21:44:02 -07:00
"github.com/rancher/norman/types"
2017-11-29 14:27:02 -07:00
"github.com/rancher/norman/types/factory"
2017-11-28 14:28:25 -07:00
"k8s.io/client-go/tools/clientcmd"
2017-11-10 21:44:02 -07:00
)
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 = types.APIVersion{
Version: "v1",
2017-12-19 21:39:57 -07:00
Group: "example.core.cattle.io",
2017-11-10 21:44:02 -07:00
Path: "/example/v1",
}
2017-11-29 14:27:02 -07:00
Schemas = factory.Schemas(&version)
2017-11-10 21:44:02 -07:00
)
func main() {
2017-11-28 14:28:25 -07:00
kubeConfig, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG"))
if err != nil {
2017-11-10 21:44:02 -07:00
panic(err)
}
2018-02-09 13:31:12 -07:00
client, err := proxy.NewClientGetterFromConfig(*kubeConfig)
2017-11-10 21:44:02 -07:00
if err != nil {
panic(err)
}
2018-02-09 13:31:12 -07:00
crdFactory := crd.Factory{
ClientGetter: client,
}
2017-11-28 14:28:25 -07:00
Schemas.MustImportAndCustomize(&version, Foo{}, func(schema *types.Schema) {
2021-09-21 14:02:30 -07:00
if err := crdFactory.AssignStores(context.Background(), types.DefaultStorageContext, nil, schema); err != nil {
2018-02-09 13:31:12 -07:00
panic(err)
}
2017-11-28 14:28:25 -07:00
})
server := api.NewAPIServer()
if err := server.AddSchemas(Schemas); err != nil {
panic(err)
}
2017-11-10 21:44:02 -07:00
fmt.Println("Listening on 0.0.0.0:1234")
panic(http.ListenAndServe("0.0.0.0:1234", server))
2017-11-10 21:44:02 -07:00
}