| 1 |
/* |
| 2 |
Copyright 2015 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package generator |
| 18 |
|
| 19 |
import ( |
| 20 |
"io" |
| 21 |
|
| 22 |
"k8s.io/gengo/namer" |
| 23 |
"k8s.io/gengo/types" |
| 24 |
) |
| 25 |
|
| 26 |
const ( |
| 27 |
GolangFileType = "golang" |
| 28 |
) |
| 29 |
|
| 30 |
// DefaultGen implements a do-nothing Generator. |
| 31 |
// |
| 32 |
// It can be used to implement static content files. |
| 33 |
type DefaultGen struct { |
| 34 |
// OptionalName, if present, will be used for the generator's name, and |
| 35 |
// the filename (with ".go" appended). |
| 36 |
OptionalName string |
| 37 |
|
| 38 |
// OptionalBody, if present, will be used as the return from the "Init" |
| 39 |
// method. This causes it to be static content for the entire file if |
| 40 |
// no other generator touches the file. |
| 41 |
OptionalBody []byte |
| 42 |
} |
| 43 |
|
| 44 |
func (d DefaultGen) Name() string { return d.OptionalName } |
| 45 |
func (d DefaultGen) Filter(*Context, *types.Type) bool { return true } |
| 46 |
func (d DefaultGen) Namers(*Context) namer.NameSystems { return nil } |
| 47 |
func (d DefaultGen) Imports(*Context) []string { return []string{} } |
| 48 |
func (d DefaultGen) PackageVars(*Context) []string { return []string{} } |
| 49 |
func (d DefaultGen) PackageConsts(*Context) []string { return []string{} } |
| 50 |
func (d DefaultGen) GenerateType(*Context, *types.Type, io.Writer) error { return nil } |
| 51 |
func (d DefaultGen) Filename() string { return d.OptionalName + ".go" } |
| 52 |
func (d DefaultGen) FileType() string { return GolangFileType } |
| 53 |
func (d DefaultGen) Finalize(*Context, io.Writer) error { return nil } |
| 54 |
|
| 55 |
func (d DefaultGen) Init(c *Context, w io.Writer) error { |
| 56 |
_, err := w.Write(d.OptionalBody) |
| 57 |
return err |
| 58 |
} |
| 59 |
|
| 60 |
var ( |
| 61 |
_ = Generator(DefaultGen{}) |
| 62 |
) |