Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-brito committed Feb 14, 2019
1 parent d48635b commit 5c92ab1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/sirupsen/logrus v1.3.0
github.com/src-d/gcfg v1.3.0 // indirect
github.com/stretchr/testify v1.2.2
github.com/urfave/cli v1.20.0 // indirect
github.com/xanzy/ssh-agent v0.2.0 // indirect
go.opencensus.io v0.17.0 // indirect
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/src-d/gcfg v1.3.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jW
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/xanzy/ssh-agent v0.2.0 h1:Adglfbi5p9Z0BmK2oKU9nTG+zKfniSfnaMYB+ULd+Ro=
github.com/xanzy/ssh-agent v0.2.0/go.mod h1:0NyE30eGUDliuLEHJgYte/zncp2zdTStcOnWhgSqHD8=
go.opencensus.io v0.17.0 h1:2Cu88MYg+1LU+WVD+NWwYhyP0kKgRlN9QjWGaX0jKTE=
Expand Down
42 changes: 33 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package main

import (
"context"
"fmt"
"net/http"
"os"

log "github.com/sirupsen/logrus"

"github.com/go-chi/chi"
"github.com/rodrigo-brito/gocity/handle"
"github.com/rodrigo-brito/gocity/handle/middlewares"
"github.com/rodrigo-brito/gocity/lib"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

const EnvKeyGCS = "GOOGLE_APPLICATION_CREDENTIALS"
Expand All @@ -20,7 +21,7 @@ func main() {
router := chi.NewRouter()
cache := lib.NewCache()

// Use Google Cloud Storage for cache, if available
// Use Google Cloud Storage for cache, if credentials available
if credentials := os.Getenv(EnvKeyGCS); len(credentials) > 0 {
var err error
storage, err = lib.NewGCS(context.Background())
Expand All @@ -31,17 +32,40 @@ func main() {

corsMiddleware := middlewares.GetCors("*")
router.Use(corsMiddleware.Handler)

analyzer := handle.AnalyzerHandle{
Cache: cache,
Storage: storage,
}

router.Get("/api", analyzer.Handler)
router.Get("/health", handle.HealthCheck)
app := cli.NewApp()
app.Version = "1.0.0"
app.Description = "Code City metaphor for visualizing Go source code in 3D"
app.Author = "Rodrigo Brito"

app.Commands = []cli.Command{
{
Name: "server",
Description: "Start a local server to analyze projects",
Action: func(c *cli.Context) error {
router.Get("/api", analyzer.Handler)
router.Get("/health", handle.HealthCheck)

log.Println("Server started at http://localhost:4000")

return http.ListenAndServe(":4000", router)
},
},
{
Name: "open",
Description: "Open a given project in local server",
Action: func(c *cli.Context) error {
fmt.Println(c.Args().First())
return nil
},
},
}

log.Println("Server started at http://localhost:4000")
if err := http.ListenAndServe(":4000", router); err != nil {
log.Error(err)
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}

0 comments on commit 5c92ab1

Please sign in to comment.