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

Commit

Permalink
Update readme, allow setting of staticPath
Browse files Browse the repository at this point in the history
  • Loading branch information
fourcube committed May 15, 2018
1 parent 149d183 commit c8165f5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,29 @@ You can read more about it at https://openiban.com.

Implements a basic REST Web-service for validating IBAN account numbers in GO. Uses the logic from http://github.com/fourcube/goiban. Deployed at http://openiban.com .

Running the service
Running the service (Embedded Data)
-------

Via `go get`:

```bash
> go get -u github.com/fourcube/goiban-service
# Launch the service listening on port 8080 and serve static content
> $GOPATH/bin/goiban-service -p 8080 -w
```

Download a binary package:

```bash
$ curl -o goiban-service.tar.gz "https://github.com/fourcube/goiban-service/releases/latest-<ARCH>.tar.gz"
$ tar -xzf goiban-service.tar.gz
$ cd goiban-service
# Launch the service listening on port 8080, using the bank data from ./data and serving
# the web interface from ./static
$ ./goiban-service -dataPath ./data -p 8080 -w
```

Running the service (MySQL)
-------

You have to install go >= 1.8, setup your GOPATH and install a MySQL server.
Expand Down
33 changes: 26 additions & 7 deletions goiban_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -41,19 +43,22 @@ var (
inmemMetrics = m.NewInmemMetricsRegister()
repo data.BankDataRepository
// Flags
dataPath string
mysqlURL string
port string
help bool
web bool
dataPath string
staticPath string
mysqlURL string
port string
help bool
web bool
)

func init() {
flag.StringVar(&dataPath, "dataPath", "", "Base path of the bank data")
flag.StringVar(&staticPath, "staticPath", "", "Base path of the static web content")
flag.StringVar(&mysqlURL, "dbUrl", "", "Database connection string")

flag.StringVar(&port, "port", "8080", "HTTP Port or interface to listen on")
flag.BoolVar(&help, "h", false, "Show usage")
flag.BoolVar(&web, "w", false, "Serve ./static folder")
flag.BoolVar(&web, "w", false, "Serve staticPath folder")
}

func main() {
Expand All @@ -64,6 +69,19 @@ func main() {
return
}

if web && staticPath == "" {
// Try to serve from the package src directory
path := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "fourcube", "goiban-service", "static")
f, err := os.Open(path)
defer f.Close()

if err != nil {
log.Fatalf("Cannot serve static content from %s: %v. Please set a correct folder with the -staticPath option.", path, err)
}

staticPath = path
}

listen()
}

Expand Down Expand Up @@ -101,7 +119,8 @@ func listen() {

//Only host the static template when the ENV is 'Live' or 'Test'
if web {
router.NotFound = http.FileServer(http.Dir("static"))
log.Printf("Serving static content from folder %s.", staticPath)
router.NotFound = http.FileServer(http.Dir(staticPath))
}

listeningInfo := "Listening on %s"
Expand Down

0 comments on commit c8165f5

Please sign in to comment.