瀏覽代碼

generator: Un-special-case the range plugin

The "range" plugin has a name that conflicts with a reserved keyword.
Use "pl_<pluginname>" as import name for all plugins, which will not
conflict with any reserved keywords for go 1, removing the special case

Signed-off-by: Anatole Denis <anatole@unverle.fr>
Anatole Denis 5 年之前
父節點
當前提交
b00e56f059
共有 2 個文件被更改,包括 11 次插入8 次删除
  1. 10 7
      cmds/coredhcp-generator/coredhcp.go.template
  2. 1 1
      cmds/coredhcp-generator/main.go

+ 10 - 7
cmds/coredhcp-generator/coredhcp.go.template

@@ -10,13 +10,16 @@ import (
 	"io/ioutil"
 	"time"
 
-	"github.com/coredhcp/coredhcp"
 	"github.com/coredhcp/coredhcp/config"
 	"github.com/coredhcp/coredhcp/logger"
+	"github.com/coredhcp/coredhcp/server"
+
 	"github.com/coredhcp/coredhcp/plugins"
-{{range $plugin := .}}
-	{{if eq $plugin "github.com/coredhcp/coredhcp/plugins/range"}}rangepl "{{$plugin}}"{{else}}"{{$plugin}}"{{end}}
-{{end}}
+{{- range $plugin := .}}
+	{{- /* We import all plugins as pl_<pluginname> to avoid conflicts with reserved keywords */}}
+	{{importname $plugin}} "{{$plugin}}"
+{{- end}}
+
 	"github.com/sirupsen/logrus"
 )
 
@@ -44,9 +47,9 @@ func getLogLevels() []string {
 }
 
 var desiredPlugins = []*plugins.Plugin{
-{{range $plugin := .}}
-{{$import := importname $plugin}}&{{if eq $import "range"}}rangepl{{else}}{{$import}}{{end}}.Plugin,
-{{end}}
+{{- range $plugin := .}}
+	&{{importname $plugin}}.Plugin,
+{{- end}}
 }
 
 func main() {

+ 1 - 1
cmds/coredhcp-generator/main.go

@@ -33,7 +33,7 @@ var funcMap = template.FuncMap{
 		if len(parts) < 1 {
 			return "", fmt.Errorf("no components found in import path '%s'", importPath)
 		}
-		return parts[len(parts)-1], nil
+		return "pl_" + parts[len(parts)-1], nil
 	},
 }