Skip to content

Commit

Permalink
Merge branch 'release/v1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Mar 20, 2020
2 parents d44d51e + 236f972 commit 2d5c9ca
Show file tree
Hide file tree
Showing 37 changed files with 1,086 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*.out

# Editor specifics
.vscode/*
.vscode
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
language: go
go:
- 1.12.x
- 1.13.4
- 1.13.x
- 1.14.1
install:
- go get github.com/mattn/goveralls
- go get honnef.co/go/tools/cmd/staticcheck
- go get github.com/client9/misspell/cmd/misspell
- go get -t ./...
- ./scripts/install-checks.sh
before_script:
- PACKAGES=$(go list ./...)
- go get -d ./...
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]]; then ./scripts/check.sh; fi
- go build
- $(exit $(go fmt $PACKAGES | wc -l))
- go vet $PACKAGES
- misspell -error -locale US .
- staticcheck $PACKAGES
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.13\. ]] && [ "$TRAVIS_TAG" != "" ]; then ./scripts/cross_compile.sh $TRAVIS_TAG; fi
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]] && [ "$TRAVIS_TAG" != "" ]; then ./scripts/cross_compile.sh $TRAVIS_TAG; fi
script:
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.13\. ]]; then ./scripts/cover.sh TRAVIS; else go test -v -race $PACKAGES; fi
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]]; then ./scripts/cover.sh TRAVIS; else go test -v -race $PACKAGES; fi
after_success:
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.13\. ]] && [ "$TRAVIS_TAG" != "" ]; then ghr --owner resgateio --token $GITHUB_TOKEN --draft --replace $TRAVIS_TAG pkg/; fi
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]] && [ "$TRAVIS_TAG" != "" ]; then ghr --owner resgateio --token $GITHUB_TOKEN --draft --replace $TRAVIS_TAG pkg/; fi
174 changes: 97 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Whenever there is a change to the data, the responsible micro-service sends an e

## Quickstart

### Docker

If you <a href="https://docs.docker.com/install/" target="_blank">install Docker</a>, it is easy to run both *NATS server* and *Resgate* as containers:

```text
Expand All @@ -44,37 +42,16 @@ docker run -d --name nats -p 4222:4222 --net res nats
docker run --name resgate -p 8080:8080 --net res resgateio/resgate --nats nats://nats:4222
```

Both images are small, less than 10 MB each.

### Download

Another way to install *Resgate* and *NATS Server* is to download one of the pre-built binaries:

* [Download](https://nats.io/download/nats-io/nats-server/) and run NATS Server
* [Download](https://resgate.io/download/) and run Resgate
Both images are small, about 10 MB each.

### Building

If you wish to build your own binaries, first make sure you have:
* [installed Go](https://golang.org/doc/install) and [set your `$GOPATH`](https://golang.org/cmd/go/#hdr-GOPATH_environment_variable)
* added `$GOPATH/bin` (where your binaries are stored) to your `PATH`
* [installed node.js](https://nodejs.org/en/download/) (for the test app)

Install and run [NATS server](https://nats-io.github.io/docs/nats_server/installation.html) and Resgate:
```bash
go get github.com/nats-io/nats-server
nats-server
```
```bash
go get github.com/resgateio/resgate
resgate
```
See [Resgate.io - Installation](https://resgate.io/docs/get-started/installation/) for other ways of installation.

## Examples

While Resgate may be used with any language, the examples in this repository are written in Javascript for Node.js.
While Resgate may be used with any language, the examples in this repository are written in Javascript for Node.js, without using any additional library.

For examples in other languages, visit [Resgate.io - Examples](https://resgate.io/docs/get-started/examples/).
* For Go (golang) examples, see [go-res package](https://github.com/jirenius/go-res)
* For C# (NETCore) examples, see [RES Service for .NET](https://github.com/jirenius/csharp-res)

| Example | Description
| --- | ---
Expand All @@ -101,22 +78,43 @@ For more in depth information on the protocol:
```
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 |
| `-r, --reqtimeout <milliseconds>` | Timeout duration for NATS requests |
| `-u, --headauth <method>` | Resource method for header authentication |
| ` --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 |
| `-v, --version` | Show version |

### Server options

| Option | Description | Default value
| --- | --- | ---
| `-n`, `--nats <url>` | NATS Server URL | `nats://127.0.0.1:4222`
| `-i`, `--addr <host>` | Bind to HOST address | `0.0.0.0`
| `-p`, `--port <port>` | HTTP port for client connections | `8080`
| `-w`, `--wspath <path>` | WebSocket path for clients | `/`
| `-a`, `--apipath <path>` | Web resource path for clients | `/api/`
| `-r`, `--reqtimeout <seconds>` | Timeout duration for NATS requests | `3000`
| `-u`, `--headauth <method>` | Resource method for header authentication |
| ` --tls` | Enable TLS for HTTP | `false`
| ` --tlscert <file>` | HTTP server certificate file |
| ` --tlskey <file>` | Private key for HTTP server certificate |
| ` --apiencoding <type>` | Encoding for web resources: json, jsonflat | `json`
| ` --creds <file>` | NATS User Credentials file |
| ` --alloworigin <origin>` | Allowed origin(s): *, or \<scheme\>://\<hostname\>\[:\<port\>\] | `*`
| ` --putmethod <methodName>` | Call method name mapped to HTTP PUT requests |
| ` --deletemethod <methodName>` | Call method name mapped to HTTP DELETE requests |
| ` --patchmethod <methodName>` | Call method name mapped to HTTP PATCH requests |
| `-c`, `--config <file>` | Configuration file in JSON format |

### Logging options

| Option | Description
| --- | ---
| `-D`, `--debug` | Enable debugging output
| `-V`, `--trace` | Enable trace logging
| `-DV` | Debug and trace

### Common options

| Option | Description
| --- | ---
| `-h`, `--help` | Show usage message
| `-v`, `--version` | Show version


## Configuration
Expand All @@ -126,39 +124,61 @@ Configuration is a JSON encoded file. If no config file is found at the given pa

```javascript
{
// URL to the NATS server
"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
// information such as the request headers.
// Missing value or null will disable header authentication.
// Eg. "authService.headerLogin"
"headerAuth": null,
// Flag telling if tls encryption is enabled
"tls": false,
// Certificate file path for tls encryption
"tlsCert": "",
// Key file path for tls encryption
"tlsKey": ""
// URL to the NATS server.
"natsUrl": "nats://127.0.0.1:4222",
// NATS User Credentials file path.
// Eg. "ngs.creds"
"natsCreds": null,
// 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 prefix 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",
// Flag enabling WebSocket per message compression (RFC 7692).
"wsCompression": false,
// Call method name to map HTTP PUT method requests to.
// Eg. "put"
"putMethod": null,
// Call method name to map HTTP DELETE method requests to.
// Eg. "delete"
"deleteMethod": null,
// Call method name to map HTTP PATCH method requests to.
// Eg. "patch"
"patchMethod": null,
// 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
// information such as the request headers.
// Missing value or null will disable header authentication.
// Eg. "authService.headerLogin"
"headerAuth": null,
// Flag enabling tls encryption.
"tls": false,
// Certificate file path for tls encryption.
"tlsCert": "",
// Key file path for tls encryption.
"tlsKey": "",
// Allowed origin for CORS requests, or * to allow all origins.
// Multiple origins are separated by semicolon.
// Eg. "https://example.com;https://api.example.com"
"allowOrigin": "*",
// Flag enabling debug logging.
"debug": false,
// Flag enabling trace logging.
"trace": false
}
```

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13.4-alpine3.10 as builder
FROM golang:1.14.1-alpine3.11 as builder

LABEL maintainer="Samuel Jirenius <samuel@jirenius.com>"

Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13.4-alpine3.10 as builder
FROM golang:1.14.1-alpine3.11 as builder

LABEL maintainer="Samuel Jirenius <samuel@jirenius.com>"

Expand All @@ -15,7 +15,7 @@ COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags "-s -w" -o /resgate

FROM alpine:3.10
FROM alpine:3.11
COPY --from=builder /resgate /bin/resgate

EXPOSE 8080
Expand Down
5 changes: 4 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ All changes to the RES Protocol will be documented in this file.
* #136 Added RES client *version* request.
* #135 Resource response on call and auth requests.

See [v1.2 update page](res-protocol-v1.2-update.md) for more info.

## v1.1.1 - [Resgate v1.3.0](compare/v1.2.2...v1.3.0) - 2019-10-02

* #110 Allow query on non-query requests.
* #111 Added *Invalid Query* error.
* #113 Added [RES Protocol Semantic Versioning](blob/v1.3.0/docs/res-protocol-semver.md).

## v1.1.0 - [Resgate v1.2.1](compare/v1.2.0...v1.2.1) - 2019-08-05
See [v1.1 update page](docs/res-protocol-v1.1-update.md) for more info.

* #68 Props field on change event.

See [v1.1 update page](res-protocol-v1.1-update.md) for more info.

## v1.0.0 - [Resgate v1.0.0](tree/v1.0.0) - 2018-09-22

* Initial release.
2 changes: 1 addition & 1 deletion docs/res-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ If a gateway loses the connection to a client, it will make no attempt at recove

A client is the application that accesses the API by connecting to a gateway's WebSocket. While it may be possible to access the API resources through HTTP requests, any reference in these documentations to *client* implies a client using the WebSocket.

A client uses the [RES-service protocol](res-service-protocol.md) for communication.
A client uses the [RES-client protocol](res-client-protocol.md) for communication.

## Connection IDs

Expand Down
4 changes: 3 additions & 1 deletion docs/res-service-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ A delete action is a JSON object used when a property has been deleted from a mo
`event.<resourceName>.add`

Add events are sent when a value is added to a [collection](res-protocol.md#collections).
Any previous value at the same index or higher will implicitly be shifted one step to a higher index.
MUST NOT be sent on [models](res-protocol.md#models).
The event payload has the following parameters:

Expand All @@ -410,7 +411,7 @@ The event payload has the following parameters:

**idx**
Zero-based index number of where the value is inserted.
MUST be a number that is zero or greater and less than the length of the collection.
MUST be a number that is zero or greater and less than or equal to the length of the collection.

**Example payload**
```json
Expand All @@ -426,6 +427,7 @@ MUST be a number that is zero or greater and less than the length of the collect
`event.<resourceName>.remove`

Remove events are sent when a value is removed from a [collection](res-protocol.md#collections).
Any previous value at a higher index will implicitly be shifted one step to a lower index.
MUST NOT be sent on [models](res-protocol.md#models).
The event payload has the following parameter:

Expand Down
6 changes: 3 additions & 3 deletions examples/edit-text/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/hello-world/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ module github.com/resgateio/resgate
go 1.13

require (
github.com/gorilla/websocket v1.4.1
github.com/gorilla/websocket v1.4.2
github.com/jirenius/timerqueue v1.0.0
github.com/nats-io/nats-server/v2 v2.1.0 // indirect
github.com/nats-io/nats.go v1.8.1
github.com/posener/wstest v0.0.0-20180217133618-28272a7ea048
github.com/nats-io/nats-server/v2 v2.1.4 // indirect
github.com/nats-io/nats.go v1.9.1
github.com/posener/wstest v1.2.0
github.com/rs/xid v1.2.1
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc // indirect
golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6 // indirect
)
Loading

0 comments on commit 2d5c9ca

Please sign in to comment.