Skip to content

Commit

Permalink
Merge pull request #89 from jirenius/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jirenius authored May 6, 2019
2 parents 3877f9f + a1a67e9 commit 8b98e31
Show file tree
Hide file tree
Showing 37 changed files with 1,513 additions and 1,052 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ go:
- 1.12.x
install:
- go get github.com/mattn/goveralls
- go get honnef.co/go/tools/cmd/megacheck
- go get honnef.co/go/tools/cmd/staticcheck
- go get github.com/client9/misspell/cmd/misspell
before_script:
- PACKAGES=$(go list ./...)
- go get -d ./...
- go build
- $(exit $(go fmt $PACKAGES | wc -l))
- misspell -error -locale US .
- megacheck $PACKAGES
- staticcheck $PACKAGES
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.12\. ]] && [ "$TRAVIS_TAG" != "" ]; then ./scripts/cross_compile.sh $TRAVIS_TAG; fi
script:
- go test -i $PACKAGES
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
<a href="https://coveralls.io/github/jirenius/resgate?branch=master"><img src="https://coveralls.io/repos/github/jirenius/resgate/badge.svg?branch=master" alt="Coverage"></a>
</p>

<p align="center">Visit <a href="https://resgate.io">Resgate.io</a> for <a href="https://resgate.io/docs/get-started/introduction/">guides</a>, <a href="https://resgate.io/demo/">live demos</a>, and <a href="https://resgate.io/docs/get-started/resources/">resources</a>.</p>

---

[Resgate](https://resgate.io) is a [Go](http://golang.org) project implementing a realtime API gateway for the [RES protocol](docs/res-protocol.md) with [NATS server](https://nats.io/about/) as messaging system.
Resgate is a [Go](http://golang.org) project implementing a realtime API gateway for the [RES protocol](docs/res-protocol.md) with [NATS server](https://nats.io/about/) as messaging system.

It is a simple server that lets you create REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.

Used for building **new REST APIs** with real-time functionality, or when creating **single page applications** using reactive frameworks such as React, Vue.js, or Modapp.

![Book Collection Animation](docs/img/book-collection-anim.gif)
*Screen capture from the [Book Collection Example](examples/book-collection/)*.
*Screen capture from the [Book Collection Example](examples/book-collection/). Try out the [Live demo](https://resgate.io/demo/#book-collection-demo) version yourself.*

## How it works

Expand Down Expand Up @@ -86,6 +88,7 @@ resgate [options]
| Option | Description |
|---|---|
| `-n, --nats <url>` | NATS Server URL |
| `-i, --addr <host>` | Bind to HOST address |
| `-p, --port <port>` | Use port for clients |
| `-w, --wspath <path>` | Path to WebSocket |
| `-a, --apipath <path>` | Path to web resources |
Expand All @@ -94,6 +97,7 @@ resgate [options]
| ` --tls` | Enable TLS |
| ` --tlscert <file>` | Server certificate file |
| ` --tlskey <file>` | Private key for server certificate |
| ` --apiencoding <type>` | Encoding for web resources: json, jsonflat |
| `-c, --config <file>` | Configuration file |
| `-h, --help` | Show usage message |

Expand All @@ -109,13 +113,22 @@ Configuration is a JSON encoded file. If no config file is found at the given pa
"natsUrl": "nats://127.0.0.1:4222",
// Timeout in milliseconds for NATS requests
"requestTimeout": 3000,
// Bind to HOST IPv4 or IPv6 address
// Empty string ("") means all IPv4 and IPv6 addresses.
// Invalid or missing IP address defaults to 0.0.0.0.
"addr": "0.0.0.0",
// Port for the http server to listen on.
// If the port value is missing or 0, standard http(s) port is used.
"port": 8080,
// Path for accessing the RES API WebSocket
"wsPath": "/",
// Path for accessing web resources
"apiPath": "/api",
// Encoding for web resources.
// Available encodings are:
// * json - JSON encoding with resource reference meta data
// * jsonflat - JSON encoding without resource reference meta data
"apiEncoding": "json",
// Header authentication resource method for web resources.
// Prior to accessing the resource, this resource method will be
// called, allowing an auth service to set a token using
Expand Down
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Usage: resgate [options]
Server Options:
-n, --nats <url> NATS Server URL (default: nats://127.0.0.1:4222)
-i --addr <host> Bind to HOST address (default: 0.0.0.0)
-p, --port <port> HTTP port for client connections (default: 8080)
-w, --wspath <path> WebSocket path for clients (default: /)
-a, --apipath <path> Web resource path for clients (default: /api/)
Expand All @@ -30,6 +31,7 @@ Server Options:
--tls Enable TLS for HTTP (default: false)
--tlscert <file> HTTP server certificate file
--tlskey <file> Private key for HTTP server certificate
--apiencoding <type> Encoding for web resources: json, jsonflat (default: json)
-c, --config <file> Configuration file
Common Options:
Expand Down Expand Up @@ -63,6 +65,7 @@ func (c *Config) Init(fs *flag.FlagSet, args []string) error {
configFile string
port uint
headauth string
addr string
)

fs.BoolVar(&showHelp, "h", false, "Show this message.")
Expand All @@ -71,6 +74,8 @@ func (c *Config) Init(fs *flag.FlagSet, args []string) error {
fs.StringVar(&configFile, "config", "", "Configuration file.")
fs.StringVar(&c.NatsURL, "n", "", "NATS Server URL.")
fs.StringVar(&c.NatsURL, "nats", "", "NATS Server URL.")
fs.StringVar(&addr, "i", "", "Bind to HOST address.")
fs.StringVar(&addr, "addr", "", "Bind to HOST address.")
fs.UintVar(&port, "p", 0, "HTTP port for client connections.")
fs.UintVar(&port, "port", 0, "HTTP port for client connections.")
fs.StringVar(&c.WSPath, "w", "", "WebSocket path for clients.")
Expand All @@ -82,6 +87,7 @@ func (c *Config) Init(fs *flag.FlagSet, args []string) error {
fs.BoolVar(&c.TLS, "tls", false, "Enable TLS for HTTP.")
fs.StringVar(&c.TLSCert, "tlscert", "", "HTTP server certificate file.")
fs.StringVar(&c.TLSKey, "tlskey", "", "Private key for HTTP server certificate.")
fs.StringVar(&c.APIEncoding, "apiencoding", "", "Encoding for web resources.")
fs.IntVar(&c.RequestTimeout, "r", 0, "Timeout in milliseconds for NATS requests.")
fs.IntVar(&c.RequestTimeout, "reqtimeout", 0, "Timeout in milliseconds for NATS requests.")

Expand Down Expand Up @@ -137,6 +143,10 @@ func (c *Config) Init(fs *flag.FlagSet, args []string) error {
} else {
c.HeaderAuth = &headauth
}
case "i":
fallthrough
case "addr":
c.Addr = &addr
}
})

Expand Down Expand Up @@ -177,11 +187,14 @@ func main() {
l.Logf("[DEPRECATED] ", "Request timeout should be in milliseconds.\nChange your requestTimeout from %d to %d, and you won't be bothered anymore.", cfg.RequestTimeout, cfg.RequestTimeout*1000)
cfg.RequestTimeout *= 1000
}
serv := server.NewService(&nats.Client{
serv, err := server.NewService(&nats.Client{
URL: cfg.NatsURL,
RequestTimeout: time.Duration(cfg.RequestTimeout) * time.Millisecond,
Logger: l,
}, cfg.Config)
if err != nil {
printAndDie(err.Error(), false)
}
serv.SetLogger(l)

if err := serv.Start(); err != nil {
Expand Down
Loading

0 comments on commit 8b98e31

Please sign in to comment.