1
0
mirror of https://github.com/rancher/types.git synced 2025-04-28 02:30:07 +00:00
types/main.go

57 lines
1.2 KiB
Go
Raw Normal View History

2017-11-11 04:58:42 +00:00
//go:generate go run main.go
2017-11-10 20:23:15 +00:00
package main
import (
2017-11-11 04:58:42 +00:00
"path"
"strings"
2017-11-10 20:23:15 +00:00
2017-11-11 04:58:42 +00:00
"github.com/rancher/norman/generator"
"github.com/rancher/norman/types"
clusterSchema "github.com/rancher/types/io.cattle.cluster/v1/schema"
2017-11-10 20:23:15 +00:00
)
2017-11-11 04:58:42 +00:00
var (
basePackage = "github.com/rancher/types"
baseCattle = "client"
)
2017-11-10 20:23:15 +00:00
func main() {
2017-11-11 04:58:42 +00:00
generate(clusterSchema.Schemas)
}
func generate(schemas *types.Schemas) {
version := getVersion(schemas)
groupParts := strings.Split(version.Group, ".")
cattleOutputPackage := path.Join(basePackage, baseCattle, groupParts[len(groupParts)-1], version.Version)
k8sOutputPackage := path.Join(basePackage, version.Group, version.Version)
if err := generator.Generate(schemas, cattleOutputPackage, k8sOutputPackage); err != nil {
panic(err)
}
}
func getVersion(schemas *types.Schemas) *types.APIVersion {
var version types.APIVersion
for _, schema := range schemas.Schemas() {
if version.Group == "" {
version = schema.Version
continue
}
if version.Group != schema.Version.Group ||
version.Version != schema.Version.Version {
panic("schema set contains two APIVersions")
}
}
return &version
}
func must(err error) {
if err != nil {
panic(err)
}
2017-11-10 20:23:15 +00:00
}