1
0
mirror of https://github.com/rancher/norman.git synced 2025-05-31 03:05:07 +00:00
norman/example/main.go

59 lines
1.1 KiB
Go
Raw Normal View History

2017-11-11 04:44:02 +00:00
package main
import (
"fmt"
"net/http"
"os"
2017-11-28 21:28:25 +00:00
"github.com/rancher/norman/api"
"github.com/rancher/norman/store/crd"
2017-11-11 04:44:02 +00:00
"github.com/rancher/norman/types"
2017-11-29 21:27:02 +00:00
"github.com/rancher/norman/types/factory"
2017-11-28 21:28:25 +00:00
"k8s.io/client-go/tools/clientcmd"
2017-11-11 04:44:02 +00: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",
Group: "io.cattle.core.example",
Path: "/example/v1",
}
2017-11-29 21:27:02 +00:00
Schemas = factory.Schemas(&version)
2017-11-11 04:44:02 +00:00
)
func main() {
2017-11-28 21:28:25 +00:00
kubeConfig, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG"))
if err != nil {
2017-11-11 04:44:02 +00:00
panic(err)
}
2017-11-28 21:28:25 +00:00
store, err := crd.NewCRDStoreFromConfig(*kubeConfig)
2017-11-11 04:44:02 +00:00
if err != nil {
panic(err)
}
2017-11-28 21:28:25 +00: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-11 04:44:02 +00:00
fmt.Println("Listening on 0.0.0.0:1234")
http.ListenAndServe("0.0.0.0:1234", server)
}