-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.go
50 lines (41 loc) · 1.32 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"flag"
"fmt"
"github.com/weibreeze/breeze-generator"
"github.com/weibreeze/breeze-generator/core"
breezeHttp "github.com/weibreeze/breeze-generator/http"
"net/http"
"os"
"strconv"
)
var (
srcDir = ""
goPkgPath = ""
)
func main() {
//testGenerateCode() // generate by local breeze file
startGenerateServer(8899, "/generate_code") // start as generate server
}
func testGenerateCode() {
os.RemoveAll("autoGenerate")
defaultPath := "./main/demo.breeze"
flag.StringVar(&srcDir, "src", defaultPath, "breeze schema files path")
flag.StringVar(&goPkgPath, "gopkg", "", "project package path in $GOPATH")
flag.Parse()
//parsers.UniformPackage = "motan" // set UniformPackage if you want all class in same package.
path := srcDir
config := &generator.Config{WritePath: "./autoGenerate", CodeTemplates: "all", Options: make(map[string]string)}
config.Options[core.WithPackageDir] = "true"
config.Options[core.GoPackagePrefix] = goPkgPath
// for test
//config.Options["with_motan_config"] = "true"
//config.Options["motan_config_type"] = "yaml"
result, err := generator.GeneratePath(path, config)
fmt.Printf("%v, %v\n", result, err)
}
func startGenerateServer(port int, path string) {
http.Handle(path, &breezeHttp.GenerateCodeHandler{})
http.ListenAndServe(":"+strconv.Itoa(port), nil)
select {}
}