2 Copyright 2015 The Kubernetes Authors.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
23 // DefaultPackage contains a default implementation of Package.
24 type DefaultPackage struct {
25 // Short name of package, used in the "package xxxx" line.
27 // Import path of the package, and the location on disk of the package.
30 // Emitted at the top of every file.
33 // Emitted only for a "doc.go" file; appended to the HeaderText for
35 PackageDocumentation []byte
37 // If non-nil, will be called on "Generators"; otherwise, the static
38 // list will be used. So you should set only one of these two fields.
39 GeneratorFunc func(*Context) []Generator
40 GeneratorList []Generator
42 // Optional; filters the types exposed to the generators.
43 FilterFunc func(*Context, *types.Type) bool
46 func (d *DefaultPackage) Name() string { return d.PackageName }
47 func (d *DefaultPackage) Path() string { return d.PackagePath }
49 func (d *DefaultPackage) Filter(c *Context, t *types.Type) bool {
50 if d.FilterFunc != nil {
51 return d.FilterFunc(c, t)
56 func (d *DefaultPackage) Generators(c *Context) []Generator {
57 if d.GeneratorFunc != nil {
58 return d.GeneratorFunc(c)
60 return d.GeneratorList
63 func (d *DefaultPackage) Header(filename string) []byte {
64 if filename == "doc.go" {
65 return append(d.HeaderText, d.PackageDocumentation...)
71 _ = Package(&DefaultPackage{})