提交 8b22902c 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

new features for 1.1

上级 3e16775b
......@@ -12,8 +12,12 @@ zendata是一款通用的数据生成工具,您可以使用yaml文件来定义
-t --table 输出格式为sql时,需通过该参数指定要插入数据的表名。
-H --human 输出可读格式,打印字段名,并使用tab键进行分割。
-p --port 在指定端口上运行HTTP服务。可通过http://ip/接口获得JSON格式的数据。服务模式下只支持数据生成。
-W --width 生成的字符串宽度,默认左侧补空格。
-L --leftPad 宽度不足时,左侧补充的字符,默认为空格。此参数为非空时,RightPad设置无效。
-R --rightPad 宽度不足时,右侧补充的字符,仅在LeftPad为空时有效。
-b --bind 监听的ip地址,默认监听所有的ip地址。
-p --port 在指定端口上运行HTTP服务。可通过http://ip/接口获得JSON格式的数据。服务模式下只支持数据生成。
-r --root 运行HTTP服务时根目录。客户端可调用该根目录下面的配置文件。如果不指定,取zd可执行文件所在目录。
-i --input 指定一个schema文件,输出每个表的yaml配置文件。需通过-o参数指定一个输出的目录。
......
......@@ -11,6 +11,10 @@ zendata是一款通用的数据生成工具,您可以使用yaml文件来定义
-t --table 输出格式为sql时,需通过该参数指定要插入数据的表名。
-H --human 输出可读格式,打印字段名,并使用tab键进行分割。
-W --width 生成的字符串宽度,默认左侧补空格。
-P --leftPad 宽度不足时,左侧补充的字符,默认为空格。此参数为非空时,RightPad设置无效。
-R --rightPad 宽度不足时,右侧补充的字符,仅在LeftPad为空时有效。
-p --port 在指定端口上运行HTTP服务。可通过http://ip/接口获得JSON格式的数据。服务模式下只支持数据生成。
-b --bind 监听的ip地址,默认监听所有的ip地址。
-r --root 运行HTTP服务时根目录。客户端可调用该根目录下面的配置文件。如果不指定,取zd可执行文件所在目录。
......
......@@ -86,8 +86,8 @@
"translation": "Generate %d yaml files in %s, spend %d secs."
},
{
"id": "press_to_exist",
"translation": "Press ctrl+c to exist."
"id": "start_server",
"translation": "Success yo start zendata http service, press CTRL+C to exist. \n You may use http://%s:%dto retrieve the data,for example: \n curl http://%s:%d/?default=/demo/default.yaml&config=/demo/test.yaml&n=100."
}
]
}
\ No newline at end of file
......@@ -77,8 +77,8 @@
"translation": "生成%d个yaml文件于目录%s中, 耗时%d秒。"
},
{
"id": "press_to_exist",
"translation": "按ctrl+c键推出。"
"id": "start_server",
"translation": "zendata http服务已经成功运行,按CTRL+C键推出。\n 您可以通过http://%s:%d地址来调用,比如:\n curl http://%s:%d/?default=/demo/default.yaml&config=/demo/test.yaml&n=100."
}
]
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/easysoft/zendata/src/gen"
"github.com/easysoft/zendata/src/model"
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
......@@ -46,11 +47,21 @@ func Generate(deflt string, yml string, total int, fieldsToExportStr string, out
WriteToFile(out, content)
}
if vari.HttpService {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("press_to_exist"), color.FgCyan)
if vari.Ip != "" || vari.Port != 0 || vari.Root != ""{
if vari.Ip == "" {
vari.Ip = commonUtils.GetIp()
}
if vari.Port == 0 {
vari.Port = constant.DefaultPort
}
if vari.Root == "" {
vari.Root = constant.DefaultRoot
}
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server"), color.FgCyan)
http.HandleFunc("/", DataHandler)
http.ListenAndServe(":58848", nil)
http.ListenAndServe(fmt.Sprintf("%s:%d", vari.Ip, vari.Port), nil)
}
//entTime := time.Now().Unix()
......
......@@ -5,6 +5,7 @@ import (
"github.com/easysoft/zendata/src/utils/const"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"github.com/emirpasic/gods/maps"
"net"
"os"
"path"
"path/filepath"
......@@ -115,3 +116,79 @@ func LinkedMapToMap(mp maps.Map) map[string]string {
return ret
}
func GetIp() string {
ifaces, err := net.Interfaces()
if err != nil {
return ""
}
ipMap := map[string]string{}
for _, iface := range ifaces {
if iface.Flags&net.FlagUp == 0 {
continue // interface down
}
if iface.Flags&net.FlagLoopback != 0 {
continue // loopback interface
}
addrs, err := iface.Addrs()
if err != nil {
return ""
}
for _, addr := range addrs {
ip := getIpFromAddr(addr)
if ip == nil {
continue
}
ipType := GetIpType(ip)
ipMap[ipType] = ip.String()
}
}
if ipMap["public"] != "" {
return ipMap["public"]
} else if ipMap["private"] != "" {
return ipMap["private"]
} else {
return ""
}
}
func getIpFromAddr(addr net.Addr) net.IP {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
if ip == nil || ip.IsLoopback() {
return nil
}
ip = ip.To4()
if ip == nil {
return nil // not an ipv4 address
}
return ip
}
func GetIpType(IP net.IP) string {
if IP.IsLoopback() || IP.IsLinkLocalMulticast() || IP.IsLinkLocalUnicast() {
return ""
}
if ip4 := IP.To4(); ip4 != nil {
switch true {
case ip4[0] == 10:
return "private"
case ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31:
return "private"
case ip4[0] == 192 && ip4[1] == 168:
return "private"
default:
return "public"
}
}
return ""
}
\ No newline at end of file
......@@ -40,6 +40,9 @@ var (
LeftChar rune = '('
RightChar rune = ')'
DefaultPort = 8848
DefaultRoot = "./"
ResDir = "data/"
ResPath = ResDir + "system/buildin.yaml"
......
......@@ -29,6 +29,8 @@ var (
LeftPad string
RightPad string
HttpService bool
JsonResp string = "[]"
Ip string
Port int
Root string
)
......@@ -75,11 +75,19 @@ func main() {
flagSet.StringVar(&vari.HeadSep, "H", "\t", "")
flagSet.StringVar(&vari.HeadSep, "human", "\t", "")
flagSet.IntVar(&vari.Length, "length", 0, "")
flagSet.IntVar(&vari.Length, "W", 0, "")
flagSet.IntVar(&vari.Length, "width", 0, "")
flagSet.StringVar(&vari.LeftPad, "L", "", "")
flagSet.StringVar(&vari.LeftPad, "leftPad", "", "")
flagSet.StringVar(&vari.RightPad, "R", "", "")
flagSet.StringVar(&vari.RightPad, "rightPad", "", "")
flagSet.BoolVar(&vari.HttpService, "s", false, "")
flagSet.StringVar(&vari.Ip, "b", "", "")
flagSet.StringVar(&vari.Ip, "bind", "", "")
flagSet.IntVar(&vari.Port, "p", 0, "")
flagSet.IntVar(&vari.Port, "port", 0, "")
flagSet.StringVar(&vari.Root, "r", "", "")
flagSet.StringVar(&vari.Root, "root", "", "")
flagSet.BoolVar(&example, "e", false, "")
flagSet.BoolVar(&example, "example", false, "")
......
cd build
cp zd-x86.exe zd.exe
zip -r zd-win-x86-1.1.zip zd.exe data demo
rm zd.exe
cp zd-amd64.exe zd.exe
zip -r zd-win-amd64-1.1.zip zd.exe data demo
rm zd.exe
cp zd-linux zd
tar -zcvf zd-linux-1.1.tar.gz zd data demo
rm zd
cp zd-mac zd
zip -r zd-mac-1.1.zip zd data demo
rm zd
cd ..
\ No newline at end of file
rm -rf build
mkdir build
mkdir build/log
cp -r data build/
cp -r demo build/
go-bindata -o=res/res.go -pkg=res res/ res/doc
CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -o build/zd-x86.exe src/zd.go
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o build/zd-amd64.exe src/zd.go
GO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o build/zd-linux src/zd.go
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o build/zd-mac src/zd.go
cd build
cp zd-x86.exe zd.exe
zip -r zd-win-x86-1.0.zip zd.exe data demo
rm zd.exe
cp zd-amd64.exe zd.exe
zip -r zd-win-amd64-1.0.zip zd.exe data demo
rm zd.exe
cp zd-linux zd
tar -zcvf zd-linux-1.0.tar.gz zd data demo
rm zd
cp zd-mac zd
zip -r zd-mac-1.0.zip zd data demo
rm zd
cd ..
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册