mirror of
https://github.com/rancher/norman.git
synced 2025-09-11 12:13:19 +00:00
More initial dev
This commit is contained in:
51
example/main.go
Normal file
51
example/main.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"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 = types.APIVersion{
|
||||
Version: "v1",
|
||||
Group: "io.cattle.core.example",
|
||||
Path: "/example/v1",
|
||||
}
|
||||
|
||||
Schemas = types.NewSchemas()
|
||||
)
|
||||
|
||||
func main() {
|
||||
if _, err := Schemas.Import(&version, Foo{}); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
fmt.Println("Listening on 0.0.0.0:1234")
|
||||
http.ListenAndServe("0.0.0.0:1234", server)
|
||||
}
|
Reference in New Issue
Block a user