mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	Don't number the plugins (#1146)
* Don't number the plugins The number is not needed, because the ordering is already specified. It's also annoying when you move plugins, because you need to renumber them. Remove this. 'go gen' shows no changes in the generated files, meaning this just works. * better naming
This commit is contained in:
		| @@ -8,17 +8,17 @@ import ( | |||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
| 	"log" | 	"log" | ||||||
| 	"os" | 	"os" | ||||||
| 	"sort" |  | ||||||
| 	"strconv" |  | ||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func main() { | func main() { | ||||||
| 	mi := make(map[string]string, 0) | 	mi := make(map[string]string, 0) | ||||||
| 	md := make(map[int]string, 0) | 	md := []string{} | ||||||
|  |  | ||||||
| 	file, err := os.Open(pluginFile) | 	file, err := os.Open(pluginFile) | ||||||
| 	fatalIfErr(err) | 	if err != nil { | ||||||
|  | 		log.Fatalf("Failed to open %s: %q", pluginFile, err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	defer file.Close() | 	defer file.Close() | ||||||
|  |  | ||||||
| @@ -30,21 +30,21 @@ func main() { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		items := strings.Split(line, ":") | 		items := strings.Split(line, ":") | ||||||
| 		if len(items) != 3 { | 		if len(items) != 2 { | ||||||
| 			// ignore | 			// ignore empty lines | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		priority, err := strconv.Atoi(items[0]) | 		name, repo := items[0], items[1] | ||||||
| 		fatalIfErr(err) |  | ||||||
|  |  | ||||||
| 		if v, ok := md[priority]; ok { | 		if _, ok := mi[name]; ok { | ||||||
| 			log.Fatalf("Duplicate priority '%d', slot already taken by %q", priority, v) | 			log.Fatalf("Duplicate entry %q", name) | ||||||
| 		} | 		} | ||||||
| 		md[priority] = items[1] |  | ||||||
| 		mi[items[1]] = pluginPath + items[2] // Default, unless overridden by 3rd arg |  | ||||||
|  |  | ||||||
| 		if _, err := os.Stat(pluginFSPath + items[2]); err != nil { // External package has been given | 		md = append(md, name) | ||||||
| 			mi[items[1]] = items[2] | 		mi[name] = pluginPath + repo // Default, unless overridden by 3rd arg | ||||||
|  |  | ||||||
|  | 		if _, err := os.Stat(pluginFSPath + repo); err != nil { // External package has been given | ||||||
|  | 			mi[name] = repo | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -65,14 +65,12 @@ func genImports(file, pack string, mi map[string]string) { | |||||||
| 	} | 	} | ||||||
| 	outs += ")\n" | 	outs += ")\n" | ||||||
|  |  | ||||||
| 	res, err := format.Source([]byte(outs)) | 	if err := formatAndWrite(file, outs); err != nil { | ||||||
| 	fatalIfErr(err) | 		log.Fatalf("Failed to format and write: %q", err) | ||||||
|  | 	} | ||||||
| 	err = ioutil.WriteFile(file, res, 0644) |  | ||||||
| 	fatalIfErr(err) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func genDirectives(file, pack string, md map[int]string) { | func genDirectives(file, pack string, md []string) { | ||||||
|  |  | ||||||
| 	outs := header + "package " + pack + "\n\n" | 	outs := header + "package " + pack + "\n\n" | ||||||
| 	outs += ` | 	outs += ` | ||||||
| @@ -87,29 +85,27 @@ func genDirectives(file, pack string, md map[int]string) { | |||||||
| var directives = []string{ | var directives = []string{ | ||||||
| ` | ` | ||||||
|  |  | ||||||
| 	var orders []int | 	for i := range md { | ||||||
| 	for k := range md { | 		outs += `"` + md[i] + `",` + "\n" | ||||||
| 		orders = append(orders, k) |  | ||||||
| 	} |  | ||||||
| 	sort.Ints(orders) |  | ||||||
|  |  | ||||||
| 	for _, k := range orders { |  | ||||||
| 		outs += `"` + md[k] + `",` + "\n" |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	outs += "}\n" | 	outs += "}\n" | ||||||
|  |  | ||||||
| 	res, err := format.Source([]byte(outs)) | 	if err := formatAndWrite(file, outs); err != nil { | ||||||
| 	fatalIfErr(err) | 		log.Fatalf("Failed to format and write: %q", err) | ||||||
|  | 	} | ||||||
| 	err = ioutil.WriteFile(file, res, 0644) |  | ||||||
| 	fatalIfErr(err) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func fatalIfErr(err error) { | func formatAndWrite(file string, data string) error { | ||||||
|  | 	res, err := format.Source([]byte(data)) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatal(err) | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if err = ioutil.WriteFile(file, res, 0644); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
|   | |||||||
							
								
								
									
										68
									
								
								plugin.cfg
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								plugin.cfg
									
									
									
									
									
								
							| @@ -10,42 +10,42 @@ | |||||||
| # Modify the list below and run `go gen && go build` | # Modify the list below and run `go gen && go build` | ||||||
|  |  | ||||||
| # The parser takes the input format of | # The parser takes the input format of | ||||||
| #     <order>:<plugin-name>:<package-name> | #     <plugin-name>:<package-name> | ||||||
| # Or | # Or | ||||||
| #     <order>:<plugin-name>:<fully-qualified-package-name> | #     <plugin-name>:<fully-qualified-package-name> | ||||||
| # | # | ||||||
| # External plugin example: | # External plugin example: | ||||||
| # 80:log:github.com/coredns/coredns/plugin/log | # log:github.com/coredns/coredns/plugin/log | ||||||
| # Local plugin example: | # Local plugin example: | ||||||
| # 80:log:log | # log:log | ||||||
|  |  | ||||||
| 1:tls:tls | tls:tls | ||||||
| 10:root:root | root:root | ||||||
| 20:bind:bind | bind:bind | ||||||
| 30:debug:debug | debug:debug | ||||||
| 40:trace:trace | trace:trace | ||||||
| 50:health:health | health:health | ||||||
| 60:pprof:pprof | pprof:pprof | ||||||
| 70:prometheus:metrics | prometheus:metrics | ||||||
| 80:errors:errors | errors:errors | ||||||
| 90:log:log | log:log | ||||||
| 100:autopath:autopath | autopath:autopath | ||||||
| 110:dnstap:dnstap | dnstap:dnstap | ||||||
| 120:chaos:chaos | chaos:chaos | ||||||
| 130:cache:cache | cache:cache | ||||||
| 140:rewrite:rewrite | rewrite:rewrite | ||||||
| 150:loadbalance:loadbalance | loadbalance:loadbalance | ||||||
| 160:dnssec:dnssec | dnssec:dnssec | ||||||
| 170:reverse:reverse | reverse:reverse | ||||||
| 180:hosts:hosts | hosts:hosts | ||||||
| 190:federation:federation | federation:federation | ||||||
| 200:kubernetes:kubernetes | kubernetes:kubernetes | ||||||
| 210:file:file | file:file | ||||||
| 220:auto:auto | auto:auto | ||||||
| 230:secondary:secondary | secondary:secondary | ||||||
| 240:etcd:etcd | etcd:etcd | ||||||
| 250:proxy:proxy | proxy:proxy | ||||||
| 260:erratic:erratic | erratic:erratic | ||||||
| 270:whoami:whoami | whoami:whoami | ||||||
| 500:startup:github.com/mholt/caddy/startupshutdown | startup:github.com/mholt/caddy/startupshutdown | ||||||
| 510:shutdown:github.com/mholt/caddy/startupshutdown | shutdown:github.com/mholt/caddy/startupshutdown | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user