Skip to content

Commit

Permalink
Gitignore accidentally ignored new cli main, updated main doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbornm committed Sep 11, 2015
1 parent 0d8b74e commit d4c6979
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gowsdl
./gowsdl
myservice
135 changes: 135 additions & 0 deletions cmd/gowsdl/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
/*
Gowsdl generates Go code from a WSDL file.
This project is originally intended to generate Go clients for WS-* services.
Usage: gowsdl [options] myservice.wsdl
-o string
File where the generated code will be saved (default "myservice.go")
-p string
Package under which code will be generated (default "myservice")
-v Shows gowsdl version
Features
Supports only Document/Literal wrapped services, which are WS-I (http://ws-i.org/) compliant.
Attempts to generate idiomatic Go code as much as possible.
Supports WSDL 1.1, XML Schema 1.0, SOAP 1.1.
Resolves external XML Schemas
Supports providing WSDL HTTP URL as well as a local WSDL file.
Not supported
UDDI.
TODO
Add support for filters to allow the user to change the generated code.
If WSDL file is local, resolve external XML schemas locally too instead of failing due to not having a URL to download them from.
Resolve XSD element references.
Support for generating namespaces.
Make code generation agnostic so generating code to other programming languages is feasible through plugins.
*/

package main

import (
"bytes"
"flag"
"go/format"
"log"
"os"
"fmt"

gen "github.com/hooklift/gowsdl"
)

const version = "v0.0.1"

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")


func init() {
log.SetFlags(0)
log.SetOutput(os.Stdout)
log.SetPrefix("🍀 ")
}

func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] myservice.wsdl\n", os.Args[0])
flag.PrintDefaults()
}

flag.Parse()

// Show app version
if *vers {
log.Println(version)
os.Exit(0)
}

if len(os.Args) < 2 {
flag.Usage()
os.Exit(0)
}

wsdlPath := os.Args[len(os.Args)-1]

if *outFile == wsdlPath {
log.Fatalln("Output file cannot be the same WSDL file")
}

// load wsdl
gowsdl, err := gen.NewGoWsdl(wsdlPath, *pkg, false)
if err != nil {
log.Fatalln(err)
}

// generate code
gocode, err := gowsdl.Start()
if err != nil {
log.Fatalln(err)
}

pkg := "./" + *pkg
err = os.Mkdir(pkg, 0744)

fd, err := os.Create(pkg + "/" + *outFile)
if err != nil {
log.Fatalln(err)
}
defer fd.Close()

data := new(bytes.Buffer)
data.Write(gocode["header"])
data.Write(gocode["types"])
data.Write(gocode["operations"])
data.Write(gocode["soap"])

// go fmt the generated code
source, err := format.Source(data.Bytes())
if err != nil {
fd.Write(data.Bytes())
log.Fatalln(err)
}

fd.Write(source)

log.Println("Done 💩")
}

0 comments on commit d4c6979

Please sign in to comment.