1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-05 17:20:20 +00:00
Files
norman/example/main.go

59 lines
1.1 KiB
Go
Raw Normal View History

2017-11-10 21:44:02 -07:00
package main
import (
"fmt"
"net/http"
"os"
2017-11-28 14:28:25 -07:00
"github.com/rancher/norman/api"
"github.com/rancher/norman/store/crd"
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)
}
2017-11-28 14:28:25 -07:00
store, err := crd.NewCRDStoreFromConfig(*kubeConfig)
2017-11-10 21:44:02 -07:00
if err != nil {
panic(err)
}
2017-11-28 14:28:25 -07:00
Schemas.MustImportAndCustomize(&version, Foo{}, func(schema *types.Schema) {
schema.Store = store
})
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")
http.ListenAndServe("0.0.0.0:1234", server)
}