Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #66 from vania-pooh/master
Browse files Browse the repository at this point in the history
Added automatic -version command (fixes #62)
  • Loading branch information
aandryashin authored May 13, 2017
2 parents fa2a02d + 4ea8d82 commit 40f6096
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ services:

script:
- go test -race -coverprofile=coverage.txt -covermode=atomic -coverpkg .
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build
- gox -os "linux darwin" -arch "amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git rev-parse HEAD`"
- gox -os "linux darwin" -arch "amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git rev-parse HEAD`"

before_install:
- go get -u github.com/kardianos/govendor
Expand Down
30 changes: 30 additions & 0 deletions docs/cli-flags.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
== Ggr CLI Flags

The following flags are supported by ```ggr``` command:
```
-listen string
host and port to listen to (default ":4444")
-quotaDir string
quota directory (default "quota")
-timeout duration
session creation timeout in time.Duration format, e.g. 300s or 500ms (default 5m0s)
-users string
htpasswd auth file path (default ".htpasswd")
-version
show version and exit
```
For example:
```
$ ./ggr -quotaDir /my/custom/quota/dir
```
When using Ggr inside Docker container these flags are passed like the following:


[source,bash,subs="attributes+"]
----
# docker run -d --name \
ggr -v /etc/grid-router/:/etc/grid-router:ro \
--net host aerokube/ggr:1.1.1
-quotaDir /my/custom/quota/dir
----

1 change: 1 addition & 0 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ include::quota-files.adoc[leveloffset=+1]
include::quota-reload.adoc[leveloffset=+1]
include::how-it-works.adoc[leveloffset=+1]
include::log-files.adoc[leveloffset=+1]
include::cli-flags.adoc[leveloffset=+1]

include::contributing.adoc[]
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var (

startTime = time.Now()
lastReloadTime = time.Now()

version bool
gitRevision string = "HEAD"
buildStamp string = "unknown"
)

func loadQuotaFiles(quotaDir string) error {
Expand Down Expand Up @@ -61,12 +65,22 @@ func updateQuota(quotaName string, browsers Browsers) {
lastReloadTime = time.Now()
}

func showVersion() {
fmt.Printf("Git Revision: %s\n", gitRevision)
fmt.Printf("UTC Build Time: %s\n", buildStamp)
}

func init() {
flag.StringVar(&listen, "listen", ":4444", "host and port to listen to")
flag.StringVar(&quotaDir, "quotaDir", "quota", "quota directory")
flag.StringVar(&users, "users", ".htpasswd", "htpasswd auth file path")
flag.DurationVar(&timeout, "timeout", 300*time.Second, "session creation timeout in time.Duration format, e.g. 300s or 500ms")
flag.BoolVar(&version, "version", false, "show version and exit")
flag.Parse()
if version {
showVersion()
os.Exit(0)
}
log.Printf("Users file is [%s]\n", users)
if err := loadQuotaFiles(quotaDir); err != nil {
log.Fatalf("%v\n", err)
Expand Down

0 comments on commit 40f6096

Please sign in to comment.