1
0
mirror of https://github.com/rancher/norman.git synced 2025-04-28 11:24:47 +00:00
norman/example/main.go
Steffan Tucker 1e41884a06
Fix golangci-lint issues
As part of updating dapper files, golangci-lint was set to be used. This
caused a lot of lint issues to crop up, which this fixes.
2022-07-26 10:40:30 -06:00

67 lines
1.3 KiB
Go

package main
import (
"context"
"fmt"
"net/http"
"os"
"github.com/rancher/norman/api"
"github.com/rancher/norman/store/crd"
"github.com/rancher/norman/store/proxy"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/factory"
"k8s.io/client-go/tools/clientcmd"
)
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: "example.core.cattle.io",
Path: "/example/v1",
}
Schemas = factory.Schemas(&version)
)
func main() {
kubeConfig, err := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG"))
if err != nil {
panic(err)
}
client, err := proxy.NewClientGetterFromConfig(*kubeConfig)
if err != nil {
panic(err)
}
crdFactory := crd.Factory{
ClientGetter: client,
}
Schemas.MustImportAndCustomize(&version, Foo{}, func(schema *types.Schema) {
if err := crdFactory.AssignStores(context.Background(), types.DefaultStorageContext, nil, schema); err != nil {
panic(err)
}
})
server := api.NewAPIServer()
if err := server.AddSchemas(Schemas); err != nil {
panic(err)
}
fmt.Println("Listening on 0.0.0.0:1234")
panic(http.ListenAndServe("0.0.0.0:1234", server))
}