Пример #1
0
func printserver(dir string, apiset *parser.APISet, apipkg string, impl string) {
	if impl == "" {
		die(errors.New("must use -impl=your.package/full/path to give implementation package"))
	}

	apiset.ServerImports = []string{
		"time",
		"io",
		"strings",
		"compress/gzip",
		"encoding/json",
		"encoding/base64",
		apipkg,
		impl,
		"net/http",
		"log",
	}
	apiset.ImplPkg = impl

	tpl := codeTemplate()

	p := filepath.Join(dir, apiset.Name+"httpimpl", "gen.go")
	os.Mkdir(filepath.Dir(p), 0755)
	f, err := os.Create(p)
	if err != nil {
		panic(err)
	}
	err = tpl.ExecuteTemplate(f, "httpserver", apiset)
	if err != nil {
		panic(err)
	}
}
Пример #2
0
func printgolang(dir string, apiset *parser.APISet, apipkg string) {
	apiset.ServerImports = []string{
		"bytes",
		"encoding/json",
		apipkg,
		"net/http",
		"compress/gzip",
		"github.com/theplant/govalidations",
		"io",
		"errors",
		"log",
		"net/http",
		"runtime/debug",
	}

	tpl := codeTemplate()

	p := filepath.Join(dir, "client", "client.go")
	os.Mkdir(filepath.Dir(p), 0755)
	f, err := os.Create(p)
	dieIf(err)

	err = tpl.ExecuteTemplate(f, "golang/interface", apiset)
	dieIf(err)
}
Пример #3
0
func printgolang(dir string, apiset *parser.APISet, apipkg string) {
	apiset.ServerImports = []string{
		"bytes",
		"time",
		"errors",
		"encoding/json",
		apipkg,
		"net/http",
	}

	tpl := codeTemplate()

	p := filepath.Join(dir, "client", "client.go")
	os.Mkdir(filepath.Dir(p), 0755)
	f, err := os.Create(p)
	dieIf(err)

	err = tpl.ExecuteTemplate(f, "golang/interface", apiset)
	dieIf(err)
}