Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
5318e108
"...Irrlicht/svn:/svn.code.sf.net/p/irrlicht/code/trunk@1632" did not exist on "67b315786d2452bb18fdc2afeb640c882ff68cb3"
Commit
5318e108
authored
Aug 22, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:miekg/coredns
parents
82ac70f1
08ca048a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
50 deletions
+17
-50
plugin_generate.go
plugin_generate.go
+17
-50
No files found.
plugin_generate.go
View file @
5318e108
...
...
@@ -4,54 +4,15 @@ package main
import
(
"bytes"
"errors"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"io/ioutil"
"log"
"strconv"
)
func
AddImportToFile
(
file
,
imprt
string
)
([]
byte
,
error
)
{
fset
:=
token
.
NewFileSet
()
f
,
err
:=
parser
.
ParseFile
(
fset
,
file
,
nil
,
parser
.
ParseComments
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
s
:=
range
f
.
Imports
{
iSpec
:=
&
ast
.
ImportSpec
{
Path
:
&
ast
.
BasicLit
{
Value
:
s
.
Path
.
Value
}}
if
iSpec
.
Path
.
Value
==
strconv
.
Quote
(
imprt
)
{
return
nil
,
errors
.
New
(
"coredns import already found"
)
}
}
for
i
:=
0
;
i
<
len
(
f
.
Decls
);
i
++
{
d
:=
f
.
Decls
[
i
]
switch
d
.
(
type
)
{
case
*
ast
.
FuncDecl
:
// No action
case
*
ast
.
GenDecl
:
dd
:=
d
.
(
*
ast
.
GenDecl
)
// IMPORT Declarations
if
dd
.
Tok
==
token
.
IMPORT
{
// Add the new import
iSpec
:=
&
ast
.
ImportSpec
{
Name
:
&
ast
.
Ident
{
Name
:
"_"
},
Path
:
&
ast
.
BasicLit
{
Value
:
strconv
.
Quote
(
imprt
)}}
dd
.
Specs
=
append
(
dd
.
Specs
,
iSpec
)
break
}
}
}
ast
.
SortImports
(
fset
,
f
)
out
,
err
:=
GenerateFile
(
fset
,
f
)
return
out
,
err
}
"golang.org/x/tools/go/ast/astutil"
)
func
GenerateFile
(
fset
*
token
.
FileSet
,
file
*
ast
.
File
)
([]
byte
,
error
)
{
var
output
[]
byte
...
...
@@ -63,19 +24,25 @@ func GenerateFile(fset *token.FileSet, file *ast.File) ([]byte, error) {
return
buffer
.
Bytes
(),
nil
}
const
(
coredns
=
"github.com/miekg/coredns/core"
// If everything is OK and we are sitting in CoreDNS' dir, this is where run.go should be.
caddyrun
=
"../../mholt/caddy/caddy/caddymain/run.go"
)
func
main
()
{
out
,
err
:=
AddImportToFile
(
caddyrun
,
coredns
)
fset
:=
token
.
NewFileSet
()
f
,
err
:=
parser
.
ParseFile
(
fset
,
caddyrun
,
nil
,
parser
.
ParseComments
)
if
err
!=
nil
{
log
.
Printf
(
"failed to add import: %s"
,
err
)
return
log
.
Fatalf
(
"failed to parse %s: %s"
,
caddyrun
,
err
)
}
astutil
.
AddNamedImport
(
fset
,
f
,
"_"
,
coredns
)
astutil
.
DeleteNamedImport
(
fset
,
f
,
"_"
,
caddy
)
out
,
err
:=
GenerateFile
(
fset
,
f
)
if
err
:=
ioutil
.
WriteFile
(
caddyrun
,
out
,
0644
);
err
!=
nil
{
log
.
Fatalf
(
"failed to write go file: %s"
,
err
)
}
}
const
(
coredns
=
"github.com/miekg/coredns/core"
caddy
=
"github.com/mholt/caddy/caddyhttp"
// If everything is OK and we are sitting in CoreDNS' dir, this is where run.go should be.
caddyrun
=
"../../mholt/caddy/caddy/caddymain/run.go"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment