1 // Copyright (c) 2020 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
21 GenerateFile func(*Generator, *File) *GenFile
24 var Plugins = map[string]*Plugin{}
27 func RegisterPlugin(name string, genfn func(*Generator, *File) *GenFile) {
29 panic("plugin name empty")
31 for _, p := range plugins {
33 panic("duplicate plugin name: " + name)
40 plugins = append(plugins, plugin)
41 Plugins[name] = plugin
44 func RunPlugin(name string, gen *Generator, file *File) error {
45 p, ok := Plugins[name]
47 return fmt.Errorf("plugin not found: %q", name)
49 p.GenerateFile(gen, file)