Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
1) added custom optional custom http port
Browse files Browse the repository at this point in the history
2) filling README.md started
  • Loading branch information
tyranron committed Jan 25, 2015
1 parent 941769f commit 9a02170
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
Golang sizeof tips
------------------

**Web tool for interactive playing with Golang struct sizes.**

## Install
To install correct versions of dependencies
[Goop dependency manager](https://github.com/nitrous-io/goop) should be used.
```bash
go get github.com/gophergala/golang-sizeof.tips
cd github.com/gophergala/golang-sizeof.tips
goop install
goop go build -o ./server
```
You may also install via simple `go get` by your own risk.


## Starting, stoping, restarting
```bash
./server -http=:7777 start
./server stop
./server restart
```
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/gophergala/golang-sizeof.tips/internal/log"

var appLog log.Logger

var HttpPort = ":7777"
const DefaultHttpPort = ":7777"

// Represents simple zero-cost message that can be used
// as signal between goroutines.
Expand Down
15 changes: 12 additions & 3 deletions app/daemon.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"flag"
"fmt"
"io/ioutil"
"os"
Expand All @@ -16,6 +17,11 @@ func init() {
daemon.AppName = "golang-sizeof.tips HTTP server"
daemon.PidFile = "logs/sizeof.pid"

httpPort := ""
flag.StringVar(
&httpPort, "http", DefaultHttpPort, "port to listen http reauests on",
)

// Overwriting default daemonigo "start" action.
daemon.SetAction("start", func() {
switch isRunning, _, err := daemon.Status(); {
Expand All @@ -26,7 +32,7 @@ func init() {
"%s is already started and running now\n", daemon.AppName,
)
default:
daemonStart()
daemonStart(httpPort)
}
})

Expand All @@ -46,12 +52,12 @@ func init() {
fmt.Println("OK")
}
}
daemonStart()
daemonStart(httpPort)
})
}

// Helper function for custom daemon starting.
func daemonStart() {
func daemonStart(port string) {
fmt.Printf("Starting %s...", daemon.AppName)
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGUSR1)
Expand All @@ -60,6 +66,9 @@ func daemonStart() {
printFailed(err)
return
}
if port != "" {
cmd.Env = append(cmd.Env, "_GO_HTTP="+port)
}
stdErr, err := cmd.StderrPipe()
if err != nil {
printFailed(err)
Expand Down
9 changes: 7 additions & 2 deletions app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ func Run() (exitCode int) {
return 1
}

httpPort := os.Getenv("_GO_HTTP")
if httpPort == "" {
httpPort = DefaultHttpPort
}

bindHttpHandlers()
canExit, httpErr := make(chan sig, 1), make(chan error, 1)
go func() {
defer close(canExit)
if err := http.ListenAndServe(HttpPort, nil); err != nil {
if err := http.ListenAndServe(httpPort, nil); err != nil {
httpErr <- fmt.Errorf(
"creating HTTP server on port '%s' FAILED, reason -> %s",
HttpPort, err.Error(),
httpPort, err.Error(),
)
}
}()
Expand Down

0 comments on commit 9a02170

Please sign in to comment.