Skip to content

Commit

Permalink
Make export of structs optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch000001 committed Jun 5, 2016
1 parent 19a52ac commit b817f5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/gowsdl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var vers = flag.Bool("v", false, "Shows gowsdl version")
var pkg = flag.String("p", "myservice", "Package under which code will be generated")
var outFile = flag.String("o", "myservice.go", "File where the generated code will be saved")
var insecure = flag.Bool("i", false, "Skips TLS Verification")
var makePublic = flag.Bool("make-public", true, "Make the generated types public/exported")

func init() {
log.SetFlags(0)
Expand Down Expand Up @@ -100,7 +101,7 @@ func main() {
}

// load wsdl
gowsdl, err := gen.NewGoWSDL(wsdlPath, *pkg, *insecure)
gowsdl, err := gen.NewGoWSDL(wsdlPath, *pkg, *insecure, *makePublic)
if err != nil {
log.Fatalln(err)
}
Expand Down
20 changes: 13 additions & 7 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const maxRecursion uint8 = 20
type GoWSDL struct {
file, pkg string
ignoreTLS bool
makePublicFn func(string) string
wsdl *WSDL
resolvedXSDExternals map[string]bool
currentRecursionLevel uint8
Expand Down Expand Up @@ -75,7 +76,7 @@ func downloadFile(url string, ignoreTLS bool) ([]byte, error) {
}

// NewGoWSDL initializes WSDL generator.
func NewGoWSDL(file, pkg string, ignoreTLS bool) (*GoWSDL, error) {
func NewGoWSDL(file, pkg string, ignoreTLS bool, exportAllTypes bool) (*GoWSDL, error) {
file = strings.TrimSpace(file)
if file == "" {
return nil, errors.New("WSDL file is required to generate Go proxy")
Expand All @@ -85,11 +86,16 @@ func NewGoWSDL(file, pkg string, ignoreTLS bool) (*GoWSDL, error) {
if pkg == "" {
pkg = "myservice"
}
makePublicFn := func(id string) string { return id }
if exportAllTypes {
makePublicFn = makePublic
}

return &GoWSDL{
file: file,
pkg: pkg,
ignoreTLS: ignoreTLS,
file: file,
pkg: pkg,
ignoreTLS: ignoreTLS,
makePublicFn: makePublicFn,
}, nil
}

Expand Down Expand Up @@ -233,7 +239,7 @@ func (g *GoWSDL) genTypes() ([]byte, error) {
"toGoType": toGoType,
"stripns": stripns,
"replaceReservedWords": replaceReservedWords,
"makePublic": makePublic,
"makePublic": g.makePublicFn,
"comment": comment,
"removeNS": removeNS,
}
Expand All @@ -256,7 +262,7 @@ func (g *GoWSDL) genOperations() ([]byte, error) {
"toGoType": toGoType,
"stripns": stripns,
"replaceReservedWords": replaceReservedWords,
"makePublic": makePublic,
"makePublic": g.makePublicFn,
"findType": g.findType,
"findSOAPAction": g.findSOAPAction,
"findServiceAddress": g.findServiceAddress,
Expand All @@ -277,7 +283,7 @@ func (g *GoWSDL) genHeader() ([]byte, error) {
"toGoType": toGoType,
"stripns": stripns,
"replaceReservedWords": replaceReservedWords,
"makePublic": makePublic,
"makePublic": g.makePublicFn,
"findType": g.findType,
"comment": comment,
}
Expand Down
10 changes: 6 additions & 4 deletions gowsdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (

func TestElementGenerationDoesntCommentOutStructProperty(t *testing.T) {
g := GoWSDL{
file: "fixtures/test.wsdl",
pkg: "myservice",
file: "fixtures/test.wsdl",
pkg: "myservice",
makePublicFn: makePublic,
}

resp, err := g.Start()
Expand All @@ -37,8 +38,9 @@ func TestVboxGeneratesWithoutSyntaxErrors(t *testing.T) {

for _, file := range files {
g := GoWSDL{
file: file,
pkg: "myservice",
file: file,
pkg: "myservice",
makePublicFn: makePublic,
}

resp, err := g.Start()
Expand Down

0 comments on commit b817f5c

Please sign in to comment.