From 8c732a91bb721ca614e59ef7ed1c9e47d8b8b22d Mon Sep 17 00:00:00 2001 From: Jhonata Menezes Date: Wed, 3 May 2017 15:18:56 -0300 Subject: [PATCH] renomeando package e bind --- cache.go | 4 ++-- cmd/cmd.go | 19 +++++++++++++++++++ controller.go | 9 ++++++--- json_build.go | 2 +- main/kartola.go | 17 ++++++++++++----- request.go | 2 +- routes.go | 2 +- 7 files changed, 42 insertions(+), 13 deletions(-) mode change 100644 => 100755 cache.go create mode 100755 cmd/cmd.go mode change 100644 => 100755 controller.go mode change 100644 => 100755 json_build.go mode change 100644 => 100755 main/kartola.go mode change 100644 => 100755 request.go mode change 100644 => 100755 routes.go diff --git a/cache.go b/cache.go old mode 100644 new mode 100755 index b1c2ed6..182121a --- a/cache.go +++ b/cache.go @@ -1,7 +1,7 @@ -package kartola +package kartolafc import ( - "github.com/jhonata-menezes/kartola/api" + "github.com/jhonata-menezes/kartolafc-backend/api" "time" ) diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100755 index 0000000..37ec524 --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/spf13/cobra" + "os" +) + +var ServerBind string + +func init() { + cmd := cobra.Command{} + cmd.Flags().StringVarP(&ServerBind, "bind", "b", "0.0.0.0:5015", "bind de interface ip:porta") + //"Kartola FC é um wrapper da API do cartolafc" + + if err := cmd.Execute(); err != nil { + os.Exit(1) + } +} + diff --git a/controller.go b/controller.go old mode 100644 new mode 100755 index 874e978..bac637a --- a/controller.go +++ b/controller.go @@ -1,16 +1,19 @@ -package kartola +package kartolafc import ( - "github.com/jhonata-menezes/kartola/api" + "github.com/jhonata-menezes/kartolafc-backend/api" "net/http" "github.com/pressly/chi" "strconv" "github.com/pressly/chi/render" + "encoding/json" ) func GetHome(response http.ResponseWriter, request *http.Request) { responseDefault(response) - render.JSON(response, request, []byte("{ \"status\":\"Birll\"}")) + var out map[string]string + json.Unmarshal([]byte("{ \"status\":\"Birll\"}"), &out) + render.JSON(response, request, out) } func GetStatus(response http.ResponseWriter, request *http.Request) { diff --git a/json_build.go b/json_build.go old mode 100644 new mode 100755 index 9ca7aea..8627600 --- a/json_build.go +++ b/json_build.go @@ -1,4 +1,4 @@ -package kartola +package kartolafc import ( "encoding/json" diff --git a/main/kartola.go b/main/kartola.go old mode 100644 new mode 100755 index 4732120..9f36b75 --- a/main/kartola.go +++ b/main/kartola.go @@ -2,15 +2,18 @@ package main import ( "github.com/pressly/chi" - "github.com/jhonata-menezes/kartola" + kartolafc "github.com/jhonata-menezes/kartolafc-backend" "net/http" "fmt" "github.com/pressly/chi/middleware" "github.com/pressly/chi/render" + "github.com/jhonata-menezes/kartolafc-backend/cmd" + "log" ) -func main(){ - go kartola.UpdateCache() +func main() { + + go kartolafc.UpdateCache() router := chi.NewRouter() router.Use(middleware.DefaultCompress) @@ -20,7 +23,11 @@ func main(){ router.Use(middleware.RealIP) router.Use(middleware.RequestID) - kartola.BuildRoutes(router) + kartolafc.BuildRoutes(router) fmt.Println("Bora Cumpade.") - http.ListenAndServe("0.0.0.0:5015", router) + log.Println("listen", cmd.ServerBind) + err := http.ListenAndServe(cmd.ServerBind, router) + if err != nil { + panic(err) + } } diff --git a/request.go b/request.go old mode 100644 new mode 100755 index 6bbfd21..c514b89 --- a/request.go +++ b/request.go @@ -1,4 +1,4 @@ -package kartola +package kartolafc import ( "github.com/valyala/fasthttp" diff --git a/routes.go b/routes.go old mode 100644 new mode 100755 index 782fe93..56f2bc1 --- a/routes.go +++ b/routes.go @@ -1,4 +1,4 @@ -package kartola +package kartolafc import "github.com/pressly/chi"