Skip to content

Commit

Permalink
add web
Browse files Browse the repository at this point in the history
  • Loading branch information
fifsky committed Mar 18, 2020
1 parent aefecbe commit 21354a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/goapt/dotenv"
"github.com/ilibs/gosql/v2"
"github.com/rs/cors"

"github.com/fifsky/genstruct/generator"
)
Expand Down Expand Up @@ -38,7 +39,11 @@ func main() {
db := gosql.Use("default")
gen := generator.NewGenerator(db)

http.HandleFunc("/api/struct/gen", func(w http.ResponseWriter, r *http.Request) {
c := cors.New(cors.Options{
AllowedOrigins: []string{"http://api.fifsky.com","https://api.fifsky.com"},
})

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
w.Write([]byte(fmt.Sprintf("request body read error \n%s", err)))
Expand Down Expand Up @@ -90,7 +95,9 @@ func main() {
w.Write(st)
})

err = http.ListenAndServe(":8989", nil)
http.Handle("/api/struct/gen", c.Handler(handler))

err = http.ListenAndServe(":8989",nil)

if err != nil {
log.Fatal("ListenAndServe", err)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ require (
github.com/ilibs/gosql/v2 v2.0.2
github.com/mattn/go-runewidth v0.0.8 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/rs/cors v1.7.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down

0 comments on commit 21354a5

Please sign in to comment.