-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (45 loc) · 1009 Bytes
/
main.go
File metadata and controls
58 lines (45 loc) · 1009 Bytes
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
51
52
53
54
55
56
57
58
package main
import (
"fmt"
. "github.com/dravinbox/json2GoStruct/controller"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
flag "github.com/spf13/pflag"
"io/ioutil"
)
var (
web bool
name string
file string
)
func main() {
flag.BoolVarP(&web, "web", "w", false, "start web interface")
flag.StringVarP(&name, "name", "n", "Hello", "Go struct name")
flag.StringVarP(&file, "file", "f", "./file.json", "path to the json file")
flag.Parse()
if web {
startWeb()
}else{
cmdLine()
}
}
func startWeb() {
app := iris.New()
app.RegisterView(iris.HTML("view", ".html"))
app.Get("/", func(context context.Context) {
//context.JSON(Address{"guangdong","guangdong"})
context.View("index.html")
})
app.Post("/convert_form_action", ConvertAction)
app.Run(iris.Addr(":8080"))
}
func cmdLine(){
bytes, e := ioutil.ReadFile(file)
if e!=nil{
fmt.Println(e)
return
}
json := string(bytes)
structString := Json2StructString(json, name)
fmt.Println(structString)
}