2017-11-10 21:44:02 -07:00
|
|
|
Norman
|
2017-10-11 22:48:07 -07:00
|
|
|
========
|
|
|
|
|
2017-11-10 21:44:02 -07:00
|
|
|
An API framework for Building [Rancher Style APIs](https://github.com/rancher/api-spec/) backed by K8s CustomResources.
|
2017-10-11 22:48:07 -07:00
|
|
|
|
|
|
|
## Building
|
|
|
|
|
|
|
|
`make`
|
|
|
|
|
2017-11-10 21:44:02 -07:00
|
|
|
## Example
|
2017-10-11 22:48:07 -07:00
|
|
|
|
2017-11-10 21:44:02 -07:00
|
|
|
Refer to `examples/`
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2017-11-10 21:50:42 -07:00
|
|
|
"net/http"
|
2017-11-10 21:44:02 -07:00
|
|
|
"os"
|
|
|
|
|
2017-11-10 21:50:42 -07:00
|
|
|
"github.com/rancher/norman/generator"
|
|
|
|
"github.com/rancher/norman/server"
|
|
|
|
"github.com/rancher/norman/types"
|
2017-11-10 21:44:02 -07:00
|
|
|
)
|
|
|
|
|
2017-11-10 21:50:42 -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"`
|
|
|
|
}
|
|
|
|
|
2017-11-10 21:44:02 -07:00
|
|
|
var (
|
2017-11-10 21:50:42 -07:00
|
|
|
version = types.APIVersion{
|
2017-11-10 21:44:02 -07:00
|
|
|
Version: "v1",
|
|
|
|
Group: "io.cattle.core.example",
|
|
|
|
Path: "/example/v1",
|
|
|
|
}
|
|
|
|
|
2017-11-10 21:50:42 -07:00
|
|
|
Schemas = types.NewSchemas()
|
2017-11-10 21:44:02 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-11-10 21:50:42 -07:00
|
|
|
if _, err := Schemas.Import(&version, Foo{}); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
server, err := server.NewAPIServer(context.Background(), os.Getenv("KUBECONFIG"), Schemas)
|
2017-11-10 21:44:02 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Listening on 0.0.0.0:1234")
|
|
|
|
http.ListenAndServe("0.0.0.0:1234", server)
|
|
|
|
}
|
|
|
|
```
|
2017-10-11 22:48:07 -07:00
|
|
|
|
|
|
|
|
|
|
|
## License
|
2017-11-10 21:44:02 -07:00
|
|
|
Copyright (c) 2014-2017 [Rancher Labs, Inc.](http://rancher.com)
|
2017-10-11 22:48:07 -07:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|