print server address on start

This commit is contained in:
alessio 2016-10-17 11:58:22 +02:00
parent 6fe4d62a80
commit 2fd91f3464
3 changed files with 28 additions and 21 deletions

View File

@ -17,6 +17,7 @@ const (
Limit = 10000
Config = "r.config.yaml"
Output = "r.output.log"
Host = "Web server listening on localhost:5000"
)
var r realize
@ -25,22 +26,22 @@ var R Realizer
// Realizer interface for wrap the cli, app and server functions
type Realizer interface {
Wdir() string
Before() error
Red(string) string
Blue(string) string
BlueS(string) string
Handle(error) error
Serve(*cli.Context)
Before(*cli.Context) error
Fast(*cli.Context) error
Run(p *cli.Context) error
Add(p *cli.Context) error
Remove(p *cli.Context) error
List(p *cli.Context) error
Run(*cli.Context) error
Add(*cli.Context) error
Remove(*cli.Context) error
List(*cli.Context) error
}
// Realize struct contains the general app informations
type realize struct {
Name, Description, Author, Email string
Name, Description, Author, Email, Host string
Version string
Limit uint64
Blueprint c.Blueprint
@ -55,6 +56,7 @@ func init() {
Name: Name,
Version: Version,
Description: Description,
Host: Host,
Limit: Limit,
Files: map[string]string{
"config": Config,
@ -133,9 +135,14 @@ func (r *realize) List(p *cli.Context) error {
return r.Blueprint.List()
}
func (r *realize) Before() error {
func (r *realize) Before(p *cli.Context) error {
fmt.Println(r.Blue(r.Name) + " - " + r.Blue(r.Version))
if !p.Bool("no-server") {
fmt.Println(r.BlueS(r.Description))
fmt.Println(r.Red(r.Host) + "\n")
} else {
fmt.Println(r.BlueS(r.Description) + "\n")
}
gopath := os.Getenv("GOPATH")
if gopath == "" {
log.Fatal(r.Red("$GOPATH isn't set up properly"))

View File

@ -36,7 +36,7 @@ func main() {
return app.Handle(app.Run(p))
},
Before: func(c *cli.Context) error {
return app.Before()
return app.Before(c)
},
},
{
@ -57,7 +57,7 @@ func main() {
return app.Handle(app.Fast(p))
},
Before: func(c *cli.Context) error {
return app.Before()
return app.Before(c)
},
},
{
@ -78,7 +78,7 @@ func main() {
return app.Handle(app.Add(p))
},
Before: func(c *cli.Context) error {
return app.Before()
return app.Before(c)
},
},
{
@ -93,7 +93,7 @@ func main() {
return app.Handle(app.Remove(p))
},
Before: func(c *cli.Context) error {
return app.Before()
return app.Before(c)
},
},
{
@ -105,7 +105,7 @@ func main() {
return app.Handle(app.List(p))
},
Before: func(c *cli.Context) error {
return app.Before()
return app.Before(c)
},
},
},

View File

@ -83,7 +83,7 @@ func (s *Server) Start() {
//e.GET("/ws", standard.WrapHandler(s.projects()))
e.GET("/ws", standard.WrapHandler(s.projects()))
go e.Run(standard.New(":5000"))
if(s.Open) {
if s.Open {
Open("http://localhost:5000")
}
}