Compare commits
53 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
574e832152 | ||
|
|
2a84799832 | ||
|
|
8adf3c8261 | ||
|
|
b3245aba9b | ||
|
|
dac2149fbd | ||
|
|
e501f6d125 | ||
|
|
341f26f197 | ||
|
|
5e28643a76 | ||
|
|
b35132451c | ||
|
|
6b0aeae504 | ||
|
|
950c77886a | ||
|
|
51221d37d0 | ||
|
|
d02baa4e8d | ||
|
|
41b3db0457 | ||
|
|
b6c488b7d4 | ||
|
|
c4b09b7a14 | ||
|
|
e201779341 | ||
|
|
321d19c5c2 | ||
|
|
56c417fd0e | ||
|
|
d3576031bb | ||
|
|
f6c3b38976 | ||
|
|
cc8fa9d611 | ||
|
|
49be089a23 | ||
|
|
157736a99d | ||
|
|
86f3f0c8e3 | ||
|
|
c991503e33 | ||
|
|
55ae241d92 | ||
|
|
ab346bcf90 | ||
|
|
4c6df96051 | ||
|
|
2a56dd24e4 | ||
|
|
65d9429a12 | ||
|
|
5fb5ce5f12 | ||
|
|
3f783fabf8 | ||
|
|
4f428d6bda | ||
|
|
eb737b6527 | ||
|
|
1840fae1aa | ||
|
|
934c629a41 | ||
|
|
3798783154 | ||
|
|
6ab917d35a | ||
|
|
c459fb22aa | ||
|
|
64ae21da53 | ||
|
|
67ba53fff4 | ||
|
|
4a72d24cdd | ||
|
|
92daf9191b | ||
|
|
fd49891632 | ||
|
|
e74b0518e9 | ||
|
|
0b324458f0 | ||
|
|
8b0b4f64f1 | ||
|
|
47e73a4eff | ||
|
|
d02de285d9 | ||
|
|
9236d6fa86 | ||
|
|
acdaa019cb | ||
|
|
01ce2da533 |
63
.github/workflows/docker-build.yml
vendored
Normal file
63
.github/workflows/docker-build.yml
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
name: build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "**"
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
inverter_gui_pipeline:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: "Setup"
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: '1.16'
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||||
|
|
||||||
|
- name: Upload code coverage
|
||||||
|
uses: codecov/codecov-action@v1
|
||||||
|
|
||||||
|
- name: Generate docker image labels and tags
|
||||||
|
id: docker_meta
|
||||||
|
uses: crazy-max/ghaction-docker-meta@v2
|
||||||
|
with:
|
||||||
|
images: ghcr.io/diebietse/invertergui
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.CR_PAT }}
|
||||||
|
|
||||||
|
- name: Build and push to GitHub Container Registry
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||||
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@@ -10,5 +10,13 @@
|
|||||||
"[go]": {
|
"[go]": {
|
||||||
"editor.insertSpaces": false,
|
"editor.insertSpaces": false,
|
||||||
"editor.tabSize": 4
|
"editor.tabSize": 4
|
||||||
}
|
},
|
||||||
|
"cSpell.words": [
|
||||||
|
"diebietse",
|
||||||
|
"ghaction",
|
||||||
|
"ghcr",
|
||||||
|
"golangci",
|
||||||
|
"invertergui",
|
||||||
|
"semver"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
22
Dockerfile
22
Dockerfile
@@ -1,14 +1,14 @@
|
|||||||
FROM golang:alpine as builder
|
FROM golang:1.16-alpine as builder
|
||||||
RUN apk add git
|
|
||||||
RUN mkdir /build
|
RUN mkdir /build
|
||||||
COPY . /build/
|
COPY . /build/
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
RUN go build -o invertergui ./cmd/invertergui
|
RUN CGO_ENABLED=0 go build -o invertergui ./cmd/invertergui
|
||||||
FROM alpine
|
|
||||||
RUN adduser -S -D -H -h /app inverteruser
|
FROM scratch
|
||||||
RUN addgroup inverteruser dialout
|
|
||||||
USER inverteruser
|
# Group ID 20 is dialout, needed for tty read/write access
|
||||||
COPY --from=builder /build/invertergui /app/
|
USER 3000:20
|
||||||
WORKDIR /app
|
COPY --from=builder /build/invertergui /bin/
|
||||||
ENTRYPOINT [ "./invertergui" ]
|
ENTRYPOINT [ "/bin/invertergui" ]
|
||||||
CMD []
|
EXPOSE 8080
|
||||||
|
|||||||
29
Makefile
29
Makefile
@@ -26,40 +26,33 @@
|
|||||||
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
.PHONY: test test-race vet install gofmt docker statik lint clean guimock invertergui invertercli build
|
.PHONY: test test-race vet install gofmt docker statik lint clean invertergui vendor
|
||||||
|
|
||||||
.DEFAULT_GOAL = build
|
.DEFAULT_GOAL = invertergui
|
||||||
|
|
||||||
guimock:
|
|
||||||
go build ./cmd/guimock/
|
|
||||||
|
|
||||||
invertergui:
|
invertergui:
|
||||||
go build ./cmd/invertergui/
|
go build ./cmd/invertergui/
|
||||||
|
|
||||||
invertercli:
|
|
||||||
go build ./cmd/invertercli/
|
|
||||||
|
|
||||||
build: guimock invertergui invertercli
|
|
||||||
|
|
||||||
all: build gofmt test
|
all: build gofmt test
|
||||||
|
|
||||||
gofmt:
|
gofmt:
|
||||||
gofmt -l -s -w .
|
gofmt -l -s -w .
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v ./...
|
|
||||||
|
|
||||||
test-race:
|
|
||||||
go test -v -race ./...
|
go test -v -race ./...
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
docker build --tag invertergui .
|
docker build --tag invertergui .
|
||||||
|
|
||||||
statik:
|
|
||||||
statik -f -p=frontend -src=./frontend/root
|
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run
|
docker run --rm -it \
|
||||||
|
-w /src -v $(shell pwd):/src \
|
||||||
|
golangci/golangci-lint:v1.39 golangci-lint run \
|
||||||
|
-v -c .golangci.yml
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm ./guimock ./invertercli ./invertergui
|
rm ./invertergui
|
||||||
|
|
||||||
|
vendor:
|
||||||
|
go mod tidy
|
||||||
|
go mod vendor
|
||||||
|
|||||||
68
README.md
68
README.md
@@ -1,8 +1,13 @@
|
|||||||
# Inverter GUI
|
# Inverter GUI
|
||||||
|
|
||||||
|
[![release][release-badge]][release-link]
|
||||||
|
[![publish-docker-image][publish-docker-badge]][publish-docker-link]
|
||||||
|
![license][license-link]
|
||||||
|
[![codecov][codecov-badge]][codecov-link]
|
||||||
|
|
||||||
The invertergui allows the monitoring of a [Victron Multiplus](https://www.victronenergy.com/inverters-chargers/multiplus-12v-24v-48v-800va-3kva) via the [MK3/MK2 USB](https://www.victronenergy.com/accessories/interface-mk3-usb) or the MK2 RS232.
|
The invertergui allows the monitoring of a [Victron Multiplus](https://www.victronenergy.com/inverters-chargers/multiplus-12v-24v-48v-800va-3kva) via the [MK3/MK2 USB](https://www.victronenergy.com/accessories/interface-mk3-usb) or the MK2 RS232.
|
||||||
|
|
||||||
The [`diebietse/invertergui`](https://hub.docker.com/r/diebietse/invertergui) docker image is a build of this repository.
|
The [`ghcr.io/diebietse/invertergui`](https://github.com/orgs/diebietse/packages/container/package/invertergui) docker image is a build of this repository.
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
@@ -11,25 +16,35 @@ The [`diebietse/invertergui`](https://hub.docker.com/r/diebietse/invertergui) do
|
|||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
```console
|
```console
|
||||||
docker run --name invertergui --device /dev/ttyUSB0:/dev/ttyUSB0 -p 8080:8080 diebietse/invertergui
|
docker run --name invertergui --device /dev/ttyUSB0:/dev/ttyUSB0 -p 8080:8080 ghcr.io/diebietse/invertergui
|
||||||
```
|
```
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
This project makes use of [Go Modules](https://github.com/golang/go/wiki/Modules). The minimum version for Go is 1.11.x.
|
This project makes use of [Go Modules](https://github.com/golang/go/wiki/Modules). The minimum version for Go is 1.16
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Usage of ./invertergui:
|
Usage:
|
||||||
-addr string
|
invertergui [OPTIONS]
|
||||||
TCP address to listen on. (default ":8080")
|
|
||||||
-dev string
|
Application Options:
|
||||||
TTY device to use. (default "/dev/ttyUSB0")
|
--address= The IP/DNS and port of the machine that the application is running on. (default: :8080) [$ADDRESS]
|
||||||
-ip string
|
--data.source= Set the source of data for the inverter gui. "serial", "tcp" or "mock" (default: serial) [$DATA_SOURCE]
|
||||||
IP to connect when using tcp connection. (default "localhost:8139")
|
--data.host= Host to connect when source is set to tcp. (default: localhost:8139) [$DATA_HOST]
|
||||||
-tcp
|
--data.device= TTY device to use when source is set to serial. (default: /dev/ttyUSB0) [$DATA_DEVICE]
|
||||||
Use TCP instead of TTY
|
--cli.enabled Enable CLI output. [$CLI_ENABLED]
|
||||||
|
--mqtt.enabled Enable MQTT publishing. [$MQTT_ENABLED]
|
||||||
|
--mqtt.broker= Set the host port and scheme of the MQTT broker. (default: tcp://localhost:1883) [$MQTT_BROKER]
|
||||||
|
--mqtt.client_id= Set the client ID for the MQTT connection. (default: interter-gui) [$MQTT_CLIENT_ID]
|
||||||
|
--mqtt.topic= Set the MQTT topic updates published to. (default: invertergui/updates) [$MQTT_TOPIC]
|
||||||
|
--mqtt.username= Set the MQTT username [$MQTT_USERNAME]
|
||||||
|
--mqtt.password= Set the MQTT password [$MQTT_PASSWORD]
|
||||||
|
--loglevel= The log level to generate logs at. ("panic", "fatal", "error", "warn", "info", "debug", "trace") (default: info) [$LOGLEVEL]
|
||||||
|
|
||||||
|
Help Options:
|
||||||
|
-h, --help Show this help message
|
||||||
```
|
```
|
||||||
|
|
||||||
## Port 8080
|
## Port 8080
|
||||||
@@ -257,6 +272,25 @@ process_start_time_seconds 1.54506833485e+09
|
|||||||
process_virtual_memory_bytes 1.15101696e+08
|
process_virtual_memory_bytes 1.15101696e+08
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### MQTT
|
||||||
|
|
||||||
|
The MQTT client will publish updates to the given broker at the set topic.
|
||||||
|
|
||||||
|
#### MQTT Configuration Options
|
||||||
|
|
||||||
|
```bash
|
||||||
|
--mqtt.enabled Enable MQTT publishing. [$MQTT_ENABLED]
|
||||||
|
--mqtt.broker= Set the host port and scheme of the MQTT broker. (default: tcp://localhost:1883) [$MQTT_BROKER]
|
||||||
|
--mqtt.client_id= Set the client ID for the MQTT connection. (default: interter-gui) [$MQTT_CLIENT_ID]
|
||||||
|
--mqtt.topic= Set the MQTT topic updates published to. (default: invertergui/updates) [$MQTT_TOPIC]
|
||||||
|
--mqtt.username= Set the MQTT username [$MQTT_USERNAME]
|
||||||
|
--mqtt.password= Set the MQTT password [$MQTT_PASSWORD]
|
||||||
|
```
|
||||||
|
|
||||||
|
The MQTT client can be enabled by setting the environment variable `MQTT_ENABLED=true` or flag `--mqtt.enabled`.
|
||||||
|
All MQTT configuration can be done via flags or as environment variables.
|
||||||
|
The URI for the broker can be configured format should be `scheme://host:port`, where "scheme" is one of "tcp", "ssl", or "ws".
|
||||||
|
|
||||||
## TTY Device
|
## TTY Device
|
||||||
|
|
||||||
The intertergui application makes use of a serial tty device to monitor the Multiplus.
|
The intertergui application makes use of a serial tty device to monitor the Multiplus.
|
||||||
@@ -318,4 +352,12 @@ The last four lines are optional, but is useful when debugging and logging conne
|
|||||||
|
|
||||||
This repos includes a [Grafana](https://grafana.com/) dashboard in the [grafana folder](./grafana/prometheus-dashboard.json) that you can import. This is useful if you are using prometheus to log your data and want to display it in a nice way.
|
This repos includes a [Grafana](https://grafana.com/) dashboard in the [grafana folder](./grafana/prometheus-dashboard.json) that you can import. This is useful if you are using prometheus to log your data and want to display it in a nice way.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
[publish-docker-badge]: https://github.com/diebietse/invertergui/actions/workflows/docker-build.yml/badge.svg
|
||||||
|
[publish-docker-link]: https://github.com/diebietse/invertergui/actions/workflows/docker-build.yml
|
||||||
|
[license-link]: https://img.shields.io/github/license/diebietse/invertergui.svg
|
||||||
|
[release-badge]: https://img.shields.io/github/v/release/diebietse/invertergui
|
||||||
|
[release-link]: https://github.com/diebietse/invertergui/releases
|
||||||
|
[codecov-badge]: https://codecov.io/gh/diebietse/invertergui/branch/master/graph/badge.svg?token=xTLfEzoqYF
|
||||||
|
[codecov-link]: https://codecov.io/gh/diebietse/invertergui
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/frontend"
|
|
||||||
"github.com/diebietse/invertergui/mk2if"
|
|
||||||
"github.com/diebietse/invertergui/webgui"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
addr := flag.String("addr", ":8080", "TCP address to listen on.")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
mk2 := mk2if.NewMk2Mock()
|
|
||||||
gui := webgui.NewWebGui(mk2)
|
|
||||||
|
|
||||||
http.Handle("/", frontend.NewStatic())
|
|
||||||
http.Handle("/ws", http.HandlerFunc(gui.ServeHub))
|
|
||||||
|
|
||||||
http.Handle("/munin", http.HandlerFunc(gui.ServeMuninHTTP))
|
|
||||||
http.Handle("/muninconfig", http.HandlerFunc(gui.ServeMuninConfigHTTP))
|
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
|
||||||
log.Fatal(http.ListenAndServe(*addr, nil))
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2if"
|
|
||||||
"github.com/tarm/serial"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Basic CLI to serve as example lib usage
|
|
||||||
func main() {
|
|
||||||
//Info = log.New()
|
|
||||||
|
|
||||||
tcp := flag.Bool("tcp", false, "Use TCP instead of TTY")
|
|
||||||
ip := flag.String("ip", "localhost:8139", "IP to connect when using tcp connection.")
|
|
||||||
dev := flag.String("dev", "/dev/ttyUSB0", "TTY device to use.")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
var p io.ReadWriteCloser
|
|
||||||
var err error
|
|
||||||
var tcpAddr *net.TCPAddr
|
|
||||||
|
|
||||||
if *tcp {
|
|
||||||
tcpAddr, err = net.ResolveTCPAddr("tcp", *ip)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
p, err = net.DialTCP("tcp", nil, tcpAddr)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
serialConfig := &serial.Config{Name: *dev, Baud: 2400}
|
|
||||||
p, err = serial.OpenPort(serialConfig)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer p.Close()
|
|
||||||
mk2, err := mk2if.NewMk2Connection(p)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer mk2.Close()
|
|
||||||
|
|
||||||
c := mk2.C()
|
|
||||||
sigterm := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(sigterm, syscall.SIGTERM, os.Interrupt)
|
|
||||||
mainloop:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case tmp := <-c:
|
|
||||||
if tmp.Valid {
|
|
||||||
PrintInfo(tmp)
|
|
||||||
}
|
|
||||||
case <-sigterm:
|
|
||||||
break mainloop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Printf("Closing connection")
|
|
||||||
}
|
|
||||||
|
|
||||||
func PrintInfo(info *mk2if.Mk2Info) {
|
|
||||||
out := fmt.Sprintf("Version: %v\n", info.Version)
|
|
||||||
out += fmt.Sprintf("Bat Volt: %.2fV Bat Cur: %.2fA \n", info.BatVoltage, info.BatCurrent)
|
|
||||||
out += fmt.Sprintf("In Volt: %.2fV In Cur: %.2fA In Freq %.2fHz\n", info.InVoltage, info.InCurrent, info.InFrequency)
|
|
||||||
out += fmt.Sprintf("Out Volt: %.2fV Out Cur: %.2fA Out Freq %.2fHz\n", info.OutVoltage, info.OutCurrent, info.OutFrequency)
|
|
||||||
out += fmt.Sprintf("In Power %.2fW Out Power %.2fW\n", info.InVoltage*info.InCurrent, info.OutVoltage*info.OutCurrent)
|
|
||||||
out += fmt.Sprintf("Charge State: %.2f%%\n", info.ChargeState*100)
|
|
||||||
out += "LEDs state:"
|
|
||||||
for k, v := range info.LEDs {
|
|
||||||
out += fmt.Sprintf(" %s %s", mk2if.LedNames[k], mk2if.StateNames[v])
|
|
||||||
}
|
|
||||||
|
|
||||||
out += "\nErrors:"
|
|
||||||
for _, v := range info.Errors {
|
|
||||||
out += " " + v.Error()
|
|
||||||
}
|
|
||||||
out += "\n"
|
|
||||||
log.Printf("System Info: \n%v", out)
|
|
||||||
}
|
|
||||||
35
cmd/invertergui/config.go
Normal file
35
cmd/invertergui/config.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jessevdk/go-flags"
|
||||||
|
)
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
Address string `long:"address" env:"ADDRESS" default:":8080" description:"The IP/DNS and port of the machine that the application is running on."`
|
||||||
|
Data struct {
|
||||||
|
Source string `long:"data.source" env:"DATA_SOURCE" default:"serial" description:"Set the source of data for the inverter gui. \"serial\", \"tcp\" or \"mock\""`
|
||||||
|
Host string `long:"data.host" env:"DATA_HOST" default:"localhost:8139" description:"Host to connect when source is set to tcp."`
|
||||||
|
Device string `long:"data.device" env:"DATA_DEVICE" default:"/dev/ttyUSB0" description:"TTY device to use when source is set to serial."`
|
||||||
|
}
|
||||||
|
Cli struct {
|
||||||
|
Enabled bool `long:"cli.enabled" env:"CLI_ENABLED" description:"Enable CLI output."`
|
||||||
|
}
|
||||||
|
MQTT struct {
|
||||||
|
Enabled bool `long:"mqtt.enabled" env:"MQTT_ENABLED" description:"Enable MQTT publishing."`
|
||||||
|
Broker string `long:"mqtt.broker" env:"MQTT_BROKER" default:"tcp://localhost:1883" description:"Set the host port and scheme of the MQTT broker."`
|
||||||
|
ClientID string `long:"mqtt.client_id" env:"MQTT_CLIENT_ID" default:"interter-gui" description:"Set the client ID for the MQTT connection."`
|
||||||
|
Topic string `long:"mqtt.topic" env:"MQTT_TOPIC" default:"invertergui/updates" description:"Set the MQTT topic updates published to."`
|
||||||
|
Username string `long:"mqtt.username" env:"MQTT_USERNAME" default:"" description:"Set the MQTT username"`
|
||||||
|
Password string `long:"mqtt.password" env:"MQTT_PASSWORD" default:"" description:"Set the MQTT password"`
|
||||||
|
}
|
||||||
|
Loglevel string `long:"loglevel" env:"LOGLEVEL" default:"info" description:"The log level to generate logs at. (\"panic\", \"fatal\", \"error\", \"warn\", \"info\", \"debug\", \"trace\")"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseConfig() (*config, error) {
|
||||||
|
conf := &config{}
|
||||||
|
parser := flags.NewParser(conf, flags.Default)
|
||||||
|
if _, err := parser.Parse(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conf, nil
|
||||||
|
}
|
||||||
@@ -31,60 +31,116 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/frontend"
|
"github.com/diebietse/invertergui/mk2core"
|
||||||
"github.com/diebietse/invertergui/mk2if"
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
"github.com/diebietse/invertergui/webgui"
|
"github.com/diebietse/invertergui/plugins/cli"
|
||||||
|
"github.com/diebietse/invertergui/plugins/mqttclient"
|
||||||
|
"github.com/diebietse/invertergui/plugins/munin"
|
||||||
|
"github.com/diebietse/invertergui/plugins/prometheus"
|
||||||
|
"github.com/diebietse/invertergui/plugins/webui"
|
||||||
|
"github.com/diebietse/invertergui/plugins/webui/static"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/tarm/serial"
|
"github.com/tarm/serial"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = logrus.WithField("ctx", "inverter-gui")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := flag.String("addr", ":8080", "TCP address to listen on.")
|
conf, err := parseConfig()
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
log.Info("Starting invertergui")
|
||||||
|
logLevel, err := logrus.ParseLevel(conf.Loglevel)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not parse log level: %v", err)
|
||||||
|
}
|
||||||
|
logrus.SetLevel(logLevel)
|
||||||
|
|
||||||
tcp := flag.Bool("tcp", false, "Use TCP instead of TTY")
|
mk2, err := getMk2Device(conf.Data.Source, conf.Data.Host, conf.Data.Device)
|
||||||
ip := flag.String("ip", "localhost:8139", "IP to connect when using tcp connection.")
|
if err != nil {
|
||||||
dev := flag.String("dev", "/dev/ttyUSB0", "TTY device to use.")
|
log.Fatalf("Could not open data source: %v", err)
|
||||||
flag.Parse()
|
}
|
||||||
|
defer mk2.Close()
|
||||||
|
|
||||||
|
core := mk2core.NewCore(mk2)
|
||||||
|
|
||||||
|
if conf.Cli.Enabled {
|
||||||
|
cli.NewCli(core.NewSubscription())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Webgui
|
||||||
|
gui := webui.NewWebGui(core.NewSubscription())
|
||||||
|
http.Handle("/", static.New())
|
||||||
|
http.Handle("/ws", http.HandlerFunc(gui.ServeHub))
|
||||||
|
|
||||||
|
// Munin
|
||||||
|
mu := munin.NewMunin(core.NewSubscription())
|
||||||
|
http.Handle("/munin", http.HandlerFunc(mu.ServeMuninHTTP))
|
||||||
|
http.Handle("/muninconfig", http.HandlerFunc(mu.ServeMuninConfigHTTP))
|
||||||
|
|
||||||
|
// Prometheus
|
||||||
|
prometheus.NewPrometheus(core.NewSubscription())
|
||||||
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
|
||||||
|
// MQTT
|
||||||
|
if conf.MQTT.Enabled {
|
||||||
|
mqttConf := mqttclient.Config{
|
||||||
|
Broker: conf.MQTT.Broker,
|
||||||
|
Topic: conf.MQTT.Topic,
|
||||||
|
ClientID: conf.MQTT.ClientID,
|
||||||
|
Username: conf.MQTT.Username,
|
||||||
|
Password: conf.MQTT.Password,
|
||||||
|
}
|
||||||
|
if err := mqttclient.New(core.NewSubscription(), mqttConf); err != nil {
|
||||||
|
log.Fatalf("Could not setup MQTT client: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Infof("Invertergui web server starting on: %v", conf.Address)
|
||||||
|
|
||||||
|
if err := http.ListenAndServe(conf.Address, nil); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMk2Device(source, ip, dev string) (mk2driver.Mk2, error) {
|
||||||
var p io.ReadWriteCloser
|
var p io.ReadWriteCloser
|
||||||
var err error
|
var err error
|
||||||
var tcpAddr *net.TCPAddr
|
var tcpAddr *net.TCPAddr
|
||||||
|
|
||||||
if *tcp {
|
switch source {
|
||||||
tcpAddr, err = net.ResolveTCPAddr("tcp", *ip)
|
case "serial":
|
||||||
|
serialConfig := &serial.Config{Name: dev, Baud: 2400}
|
||||||
|
p, err = serial.OpenPort(serialConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
|
}
|
||||||
|
case "tcp":
|
||||||
|
tcpAddr, err = net.ResolveTCPAddr("tcp", ip)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
p, err = net.DialTCP("tcp", nil, tcpAddr)
|
p, err = net.DialTCP("tcp", nil, tcpAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
|
||||||
} else {
|
|
||||||
serialConfig := &serial.Config{Name: *dev, Baud: 2400}
|
|
||||||
p, err = serial.OpenPort(serialConfig)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
case "mock":
|
||||||
|
return mk2driver.NewMk2Mock(), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Invalid source selection: %v\nUse \"serial\", \"tcp\" or \"mock\"", source)
|
||||||
}
|
}
|
||||||
defer p.Close()
|
|
||||||
mk2, err := mk2if.NewMk2Connection(p)
|
mk2, err := mk2driver.NewMk2Connection(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
defer mk2.Close()
|
|
||||||
|
|
||||||
gui := webgui.NewWebGui(mk2)
|
return mk2, nil
|
||||||
|
|
||||||
http.Handle("/", frontend.NewStatic())
|
|
||||||
http.Handle("/ws", http.HandlerFunc(gui.ServeHub))
|
|
||||||
http.Handle("/munin", http.HandlerFunc(gui.ServeMuninHTTP))
|
|
||||||
http.Handle("/muninconfig", http.HandlerFunc(gui.ServeMuninConfigHTTP))
|
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
|
||||||
log.Fatal(http.ListenAndServe(*addr, nil))
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
codecov.yml
Normal file
4
codecov.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
coverage:
|
||||||
|
precision: 2
|
||||||
|
round: down
|
||||||
|
range: "65...100"
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package frontend
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/rakyll/statik/fs"
|
|
||||||
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewStatic() http.Handler {
|
|
||||||
statikFs, err := fs.New()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
return http.FileServer(statikFs)
|
|
||||||
}
|
|
||||||
12
frontend/root/css/bootstrap.min.css
vendored
12
frontend/root/css/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
@@ -1,88 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'">
|
|
||||||
<title>Page not found · GitHub Pages</title>
|
|
||||||
<style type="text/css" media="screen">
|
|
||||||
body {
|
|
||||||
background-color: #f1f1f1;
|
|
||||||
margin: 0;
|
|
||||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container { margin: 50px auto 40px auto; width: 600px; text-align: center; }
|
|
||||||
|
|
||||||
a { color: #4183c4; text-decoration: none; }
|
|
||||||
a:hover { text-decoration: underline; }
|
|
||||||
|
|
||||||
h1 { width: 800px; position:relative; left: -100px; letter-spacing: -1px; line-height: 60px; font-size: 60px; font-weight: 100; margin: 0px 0 50px 0; text-shadow: 0 1px 0 #fff; }
|
|
||||||
p { color: rgba(0, 0, 0, 0.5); margin: 20px 0; line-height: 1.6; }
|
|
||||||
|
|
||||||
ul { list-style: none; margin: 25px 0; padding: 0; }
|
|
||||||
li { display: table-cell; font-weight: bold; width: 1%; }
|
|
||||||
|
|
||||||
.logo { display: inline-block; margin-top: 35px; }
|
|
||||||
.logo-img-2x { display: none; }
|
|
||||||
@media
|
|
||||||
only screen and (-webkit-min-device-pixel-ratio: 2),
|
|
||||||
only screen and ( min--moz-device-pixel-ratio: 2),
|
|
||||||
only screen and ( -o-min-device-pixel-ratio: 2/1),
|
|
||||||
only screen and ( min-device-pixel-ratio: 2),
|
|
||||||
only screen and ( min-resolution: 192dpi),
|
|
||||||
only screen and ( min-resolution: 2dppx) {
|
|
||||||
.logo-img-1x { display: none; }
|
|
||||||
.logo-img-2x { display: inline-block; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#suggestions {
|
|
||||||
margin-top: 35px;
|
|
||||||
color: #ccc;
|
|
||||||
}
|
|
||||||
#suggestions a {
|
|
||||||
color: #666666;
|
|
||||||
font-weight: 200;
|
|
||||||
font-size: 14px;
|
|
||||||
margin: 0 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
|
|
||||||
<h1>404</h1>
|
|
||||||
<p><strong>File not found</strong></p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
The site configured at this address does not
|
|
||||||
contain the requested file.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
If this is your site, make sure that the filename case matches the URL.<br>
|
|
||||||
For root URLs (like <code>http://example.com/</code>) you must provide an
|
|
||||||
<code>index.html</code> file.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<a href="https://help.github.com/pages/">Read the full documentation</a>
|
|
||||||
for more information about using <strong>GitHub Pages</strong>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div id="suggestions">
|
|
||||||
<a href="https://githubstatus.com">GitHub Status</a> —
|
|
||||||
<a href="https://twitter.com/githubstatus">@githubstatus</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<a href="/" class="logo logo-img-1x">
|
|
||||||
<img width="32" height="32" title="" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpFMTZCRDY3REIzRjAxMUUyQUQzREIxQzRENUFFNUM5NiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpFMTZCRDY3RUIzRjAxMUUyQUQzREIxQzRENUFFNUM5NiI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkUxNkJENjdCQjNGMDExRTJBRDNEQjFDNEQ1QUU1Qzk2IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkUxNkJENjdDQjNGMDExRTJBRDNEQjFDNEQ1QUU1Qzk2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+SM9MCAAAA+5JREFUeNrEV11Ik1EY3s4+ddOp29Q5b0opCgKFsoKoi5Kg6CIhuwi6zLJLoYLopq4qsKKgi4i6CYIoU/q5iDAKs6syoS76IRWtyJ+p7cdt7sf1PGOD+e0c3dygAx/67ZzzPM95/877GYdHRg3ZjMXFxepQKNS6sLCwJxqNNuFpiMfjVs4ZjUa/pmmjeD6VlJS8NpvNT4QQ7mxwjSsJiEQim/1+/9lgMHgIr5ohuxG1WCw9Vqv1clFR0dCqBODElV6v90ogEDjGdYbVjXhpaendioqK07CIR7ZAqE49PT09BPL2PMgTByQGsYiZlQD4uMXtdr+JxWINhgINYhGT2MsKgMrm2dnZXgRXhaHAg5jEJodUAHxux4LudHJE9RdEdA+i3Juz7bGHe4mhE9FNrgwBCLirMFV9Okh5eflFh8PR5nK5nDabrR2BNJlKO0T35+Li4n4+/J+/JQCxhmu5h3uJoXNHPbmWZAHMshWB8l5/ipqammaAf0zPDDx1ONV3vurdidqwAQL+pEc8sLcAe1CCvQ3YHxIW8Pl85xSWNC1hADDIv0rIE/o4J0k3kww4xSlwIhcq3EFFOm7KN/hUGOQkt0CFa5WpNJlMvxBEz/IVQAxg/ZRZl9wiHA63yDYieM7DnLP5CiAGsC7I5sgtYKJGWe2A8seFqgFJrJjEPY1Cn3pJ8/9W1e5VWsFDTEmFrBcoDhZJEQkXuhICMyKpjhahqN21hRYATKfUOlDmkygrR4o4C0VOLGJKrOITKB4jijzdXygBKixyC5TDQdnk/Pz8qRw6oOWGlsTKGOQW6OH6FBWsyePxdOXLTgxiyebILZCjz+GLgMIKnXNzc49YMlcRdHXcSwxFVgTInQhC9G33UhNoJLuqq6t345p9y3eUy8OTk5PjAHuI9uo4b07FBaOhsu0A4Unc+T1TU1Nj3KsSSE5yJ65jqF2DDd8QqWYmAZrIM2VlZTdnZmb6AbpdV9V6ec9znf5Q7HjYumdRE0JOp3MjitO4SFa+cZz8Umqe3TCbSLvdfkR/kWDdNQl5InuTcysOcpFT35ZrbBxx4p3JAHlZVVW1D/634VRt+FvLBgK/v5LV9WS+10xMTEwtRw7XvqOL+e2Q8V3AYIOIAXQ26/heWVnZCVfcyKHg2CBgTpmPmjYM8l24GyaUHyaIh7XwfR9ErE8qHoDfn2LTNAVC0HX6MFcBIP8Bi+6F6cdW/DICkANRfx99fEYFQ7Nph5i/uQiA214gno7K+guhaiKg9gC62+M8eR7XsBsYJ4ilam60Fb7r7uAj8wFyuwM1oIOWgfmDy6RXEEQzJMPe23DXrVS7rtyD3Df8z/FPgAEAzWU5Ku59ZAUAAAAASUVORK5CYII=">
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="/" class="logo logo-img-2x">
|
|
||||||
<img width="32" height="32" title="" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpEQUM1QkUxRUI0MUMxMUUyQUQzREIxQzRENUFFNUM5NiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpEQUM1QkUxRkI0MUMxMUUyQUQzREIxQzRENUFFNUM5NiI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkUxNkJENjdGQjNGMDExRTJBRDNEQjFDNEQ1QUU1Qzk2IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkUxNkJENjgwQjNGMDExRTJBRDNEQjFDNEQ1QUU1Qzk2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+hfPRaQAAB6lJREFUeNrsW2mME2UYbodtt+2222u35QheoCCYGBQligIJgkZJNPzgigoaTEj8AdFEMfADfyABkgWiiWcieK4S+QOiHAYUj2hMNKgYlEujpNttu9vttbvdw+chU1K6M535pt3ubHCSyezR+b73eb73+t7vrfXsufOW4bz6+vom9/b23ovnNNw34b5xYGAgODg46Mbt4mesVmsWd1qSpHhdXd2fuP/Afcput5/A88xwymcdBgLqenp6FuRyuWV4zu/v759QyWBjxoz5t76+/gun09mK5xFyakoCAPSaTCazNpvNPoYVbh6O1YKGRF0u13sNDQ27QMzfpiAAKj0lnU6/gBVfAZW2WWpwwVzy0IgP3G73FpjI6REhAGA9qVRqA1b9mVoBVyIC2tDi8Xg24+dUzQiAbS/s7Ox8G2o/3mKCC+Zw0efzPQEfcVjYrARX3dbV1bUtHo8fMgt42f+Mp0yUTVQbdWsAHVsikdiHkHaPxcQXQufXgUBgMRxme9U0AAxfH4vFvjM7eF6UkbJS5qoQwEQGA57Ac5JllFyUVZZ5ckUEgMVxsK2jlSYzI+QXJsiyjzNEAJyJAzb/KQa41jJKL8pODMQiTEAymXw5n8/P0IjD3bh7Rgog59aanxiIRTVvV/oj0tnHca/WMrVwODwB3raTGxzkBg/gnZVapFV62Wy2n5AO70HM/5wbJ0QnXyQSaVPDIuNZzY0V3ntHMwxiwHA0Gj2Np7ecIBDgaDAYXKCQJM1DhrgJ3nhulcPbl8j4NmHe46X/g60fwbz3aewjkqFQaAqebWU1AOqyQwt8Id6qEHMc97zu7u7FGGsn7HAiVuosVw7P35C1nccdgSCxop1dHeZswmfHMnxBo6ZTk+jN8dl/vF7vWofDsa+MLN9oEUBMxOb3+1eoEsBVw6Zmua49r8YmhAKDiEPcMwBsxMiqQ+ixzPFxZyqRpXARG/YOr1ObFJ0gUskXBbamcR1OKmMUvDxHRAu8/LmY3jFLMUpFqz9HxG65smYJdyKyECOxDiEAe/p1gjF2oonivZAsxVgl2daa4EQWCW6J55qFAFFZiJWYLxNQy2qOSUzGRsyXCUDIeliwAHEO4WSlWQBRFoZakXcKmCXmyXAKs0Ve9vl8q42WoIYpJU4hV3hKcNs8m9gl7p/xQ73eF5kB4j5mNrWmTJRNwAzqiV1CxjVTZCIkEq+Z1bZFZSN2CenmVAFVy4Plz8xKAGWjjAKFk6lCBMDR/MJjLLMSQNm43xAiQKTaA+9/wewhDjL+JVI1kkTSSOTcKbMTwPqESAot6dn6Fr1gHwVJju6IRuyiByPuUUBAg5DGkAgBmxlvdgIEK9gDkohdY/BJo4CAG0R8miRSsGABkgVQs4KXu098IgUXSSRsFAoKZiVAVDY2WUiiPTjYRi41KwGisrGsLtlsth8Fiwnz2fBkQvWfRtlE3iF2yW63/yCacXZ1dW02GwGyTFaRd4idJnCKHRaCxYRHoG5LTKT6SyiToP1fJHbmAYPYRR0UnZQtMnA6s0zg+GZBlt0Gdo7EPHgpE3Q6nZ8YyLhc8Xj8MJh/aKTAY+5FPAKHLE7RdwuYJZmNwzyCMkBCYyKROJBMJl9B/PXXCjjmCmDOVzH3fiPpObEWGqoKe4EBl8v1hlqsdLvd23mkxHM9pc9kMpmno9HoeTii7ewbHEZPPx1ztLS1tV3AnGuMjiNjvbQFuHw6zDo5By7dTPAQNBgMLrRarTkSls1mnwT7uwp9virx9QzbW/HuV/j5d/b+6jniKlllP8lkeONJDk+dq9GsQTnC4fB1heO0K47Hwe7WdDr9nAKgXwOBwHI+C45Htj1d6sd429TUNEcmUdc+PRaLHcvn87dXW4ugzdsaGxufL94NFv9zi1J7GVbhlvb2dnaJ3SVrxfc+n2+NTsZ7/H7/Mr3g5XdSIHyJSH1PZ+7fToyl2+ErqilgZ4NaLYB9goVGaHjR93Hv1ZrU4XDsFT20kH3PObzbWk0CgG1jacVIUnAQb9F+VexyLMzkpcLv0IJV7AHQIOCAUYHx7v5qgScmYHtTqSAyZLEJTK22Bie4iq3xsqpm4SAf9Hq9a2DnJ4uLK3SEULcdRvp3i3zHySqpficxEdsQc1NrlYXXvR+O7qASSezXB+h1SuUomgg9LL8BUoV4749EIolKh+EiqWmqVEZlDgHks2pxHw7xTqUQw9J5NcAXOK10AGIoZ6Zli6JY6Z1Q461KoZ4NiKLHarW+KDsxlDUPHZ5zPQZqUVDPJsTqb5n9malbpAh8C2XXDLl62+WZIDFRUlNVOiwencnNU3aQEkL+cDMSoLvZo2fQB7AJssNAuFuvorlDVVkkg2I87+jo2K2QAVphDrfyViK5VqtO34OkaxXCp+7drdDBCAdubm6eidX+2WwqT5komwh4YQLk+H4aE93h8Xg2gvHekQZOGSgLZTLyDTLJ4Lx9/KZWKBSainT4Iy3FqQBfnUZR42PKQFksBr9QKVXCPusD3OiA/RkQ5kP8qV/Jl1WywAp/6+dcmPM2zL1UrUahe4JqfnWWKXIul3uUbfP8njAFLW1OFr3gdFtZ72cNH+PtQT7/brW+NXqJAHh0y9V8/U/A1U7AfwIMAD7mS3pCbuWJAAAAAElFTkSuQmCC">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
12
go.mod
12
go.mod
@@ -1,9 +1,13 @@
|
|||||||
module github.com/diebietse/invertergui
|
module github.com/diebietse/invertergui
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gorilla/websocket v1.4.0
|
github.com/eclipse/paho.mqtt.golang v1.3.3
|
||||||
github.com/prometheus/client_golang v0.9.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/rakyll/statik v0.1.5
|
github.com/jessevdk/go-flags v1.5.0
|
||||||
|
github.com/prometheus/client_golang v1.10.0
|
||||||
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
github.com/stretchr/testify v1.7.0
|
||||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|||||||
433
go.sum
433
go.sum
@@ -1,25 +1,426 @@
|
|||||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||||
|
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||||
|
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||||
|
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||||
|
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||||
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||||
|
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||||
|
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||||
|
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||||
|
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||||
|
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||||
|
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||||
|
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
||||||
|
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||||
|
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
||||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||||
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
|
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||||
|
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||||
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
|
||||||
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
|
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
||||||
|
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||||
|
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||||
|
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||||
|
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
|
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
|
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
|
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||||
|
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||||
|
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||||
|
github.com/eclipse/paho.mqtt.golang v1.3.3 h1:Fh1zsLniMFJByLqKrSB9ZRjkbpU0k1Xne23ZqEE/O08=
|
||||||
|
github.com/eclipse/paho.mqtt.golang v1.3.3/go.mod h1:eTzb4gxwwyWpqBUHGQZ4ABAV7+Jgm1PklsYT/eo8Hcc=
|
||||||
|
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
|
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
|
||||||
|
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
|
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||||
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
|
||||||
|
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||||
|
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||||
|
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||||
|
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||||
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
|
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||||
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
|
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
|
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||||
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
|
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
|
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||||
|
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||||
|
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
|
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
|
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||||
|
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||||
|
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||||
|
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||||
|
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||||
|
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||||
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||||
|
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||||
|
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||||
|
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||||
|
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||||
|
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||||
|
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||||
|
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
|
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
|
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
|
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
|
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||||
|
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||||
|
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||||
|
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||||
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
|
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||||
|
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
||||||
|
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||||
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||||
|
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||||
|
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||||
|
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
|
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
|
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||||
|
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||||
|
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||||
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||||
|
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||||
|
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||||
|
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||||
|
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
|
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
|
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740=
|
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
|
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
|
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||||
|
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||||
|
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
||||||
|
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||||
|
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
|
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
|
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||||
|
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
|
||||||
|
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
|
||||||
|
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
||||||
|
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||||
|
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||||
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
|
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||||
|
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||||
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||||
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||||
|
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
|
||||||
|
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
||||||
|
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||||
|
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||||
|
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
|
||||||
|
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||||
|
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||||
|
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||||
|
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
|
||||||
|
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||||
|
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||||
|
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
||||||
|
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||||
|
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||||
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||||
|
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
|
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||||
|
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||||
|
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
||||||
|
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||||
|
github.com/prometheus/client_golang v1.10.0 h1:/o0BDeWzLWXNZ+4q5gXltUvaMpJqckTa+jTNoB+z4cg=
|
||||||
|
github.com/prometheus/client_golang v1.10.0/go.mod h1:WJM3cc3yu7XKBKa/I8WeZm+V3eltZnBwfENSU7mdogU=
|
||||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8=
|
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/rakyll/statik v0.1.5 h1:Ly2UjURzxnsSYS0zI50fZ+srA+Fu7EbpV5hglvJvJG0=
|
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
|
||||||
github.com/rakyll/statik v0.1.5/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
|
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||||
|
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||||
|
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
||||||
|
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||||
|
github.com/prometheus/common v0.18.0 h1:WCVKW7aL6LEe1uryfI9dnEc2ZqNB1Fn0ok930v0iL1Y=
|
||||||
|
github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||||
|
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||||
|
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||||
|
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
|
||||||
|
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
|
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||||
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
|
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
||||||
|
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
|
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||||
|
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||||
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
|
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
|
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||||
|
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||||
|
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||||
|
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
|
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||||
|
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||||
|
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
||||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||||
|
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||||
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
|
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
|
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||||
|
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||||
|
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
||||||
|
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
|
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
|
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||||
|
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
|
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||||
|
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||||
|
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||||
|
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||||
|
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||||
|
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||||
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
|
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
|
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||||
|
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
|
||||||
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313 h1:pczuHS43Cp2ktBEEmLwScxgjWsBSzdaQiKzUyf3DTTc=
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc=
|
||||||
|
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
|
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
||||||
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||||
|
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||||
|
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
|
||||||
|
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
|
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||||
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
|
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
|
||||||
|
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||||
|
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||||
|
google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||||
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
|
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
||||||
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||||
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
||||||
|
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||||
|
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||||
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
|
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
|
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
"fillColor": "rgba(31, 118, 189, 0.18)",
|
"fillColor": "rgba(31, 118, 189, 0.18)",
|
||||||
"full": false,
|
"full": false,
|
||||||
"lineColor": "rgb(31, 120, 193)",
|
"lineColor": "rgb(31, 120, 193)",
|
||||||
"show": false
|
"show": true
|
||||||
},
|
},
|
||||||
"tableColumn": "",
|
"tableColumn": "",
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -176,7 +176,7 @@
|
|||||||
"fillColor": "rgba(31, 118, 189, 0.18)",
|
"fillColor": "rgba(31, 118, 189, 0.18)",
|
||||||
"full": false,
|
"full": false,
|
||||||
"lineColor": "rgb(31, 120, 193)",
|
"lineColor": "rgb(31, 120, 193)",
|
||||||
"show": false
|
"show": true
|
||||||
},
|
},
|
||||||
"tableColumn": "",
|
"tableColumn": "",
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -258,7 +258,7 @@
|
|||||||
"fillColor": "rgba(31, 118, 189, 0.18)",
|
"fillColor": "rgba(31, 118, 189, 0.18)",
|
||||||
"full": false,
|
"full": false,
|
||||||
"lineColor": "rgb(31, 120, 193)",
|
"lineColor": "rgb(31, 120, 193)",
|
||||||
"show": false
|
"show": true
|
||||||
},
|
},
|
||||||
"tableColumn": "",
|
"tableColumn": "",
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -339,7 +339,7 @@
|
|||||||
"fillColor": "rgba(31, 118, 189, 0.18)",
|
"fillColor": "rgba(31, 118, 189, 0.18)",
|
||||||
"full": false,
|
"full": false,
|
||||||
"lineColor": "rgb(31, 120, 193)",
|
"lineColor": "rgb(31, 120, 193)",
|
||||||
"show": false
|
"show": true
|
||||||
},
|
},
|
||||||
"tableColumn": "",
|
"tableColumn": "",
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -420,7 +420,7 @@
|
|||||||
"fillColor": "rgba(31, 118, 189, 0.18)",
|
"fillColor": "rgba(31, 118, 189, 0.18)",
|
||||||
"full": false,
|
"full": false,
|
||||||
"lineColor": "rgb(31, 120, 193)",
|
"lineColor": "rgb(31, 120, 193)",
|
||||||
"show": false
|
"show": true
|
||||||
},
|
},
|
||||||
"tableColumn": "",
|
"tableColumn": "",
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -501,7 +501,7 @@
|
|||||||
"fillColor": "rgba(31, 118, 189, 0.18)",
|
"fillColor": "rgba(31, 118, 189, 0.18)",
|
||||||
"full": false,
|
"full": false,
|
||||||
"lineColor": "rgb(31, 120, 193)",
|
"lineColor": "rgb(31, 120, 193)",
|
||||||
"show": false
|
"show": true
|
||||||
},
|
},
|
||||||
"tableColumn": "",
|
"tableColumn": "",
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -1345,5 +1345,5 @@
|
|||||||
"timezone": "",
|
"timezone": "",
|
||||||
"title": "Victron",
|
"title": "Victron",
|
||||||
"uid": "000000004",
|
"uid": "000000004",
|
||||||
"version": 1
|
"version": 2
|
||||||
}
|
}
|
||||||
57
mk2core/core.go
Normal file
57
mk2core/core.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package mk2core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Core struct {
|
||||||
|
mk2driver.Mk2
|
||||||
|
plugins map[*subscription]bool
|
||||||
|
register chan *subscription
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCore(m mk2driver.Mk2) *Core {
|
||||||
|
core := &Core{
|
||||||
|
Mk2: m,
|
||||||
|
register: make(chan *subscription, 255),
|
||||||
|
plugins: map[*subscription]bool{},
|
||||||
|
}
|
||||||
|
go core.run()
|
||||||
|
return core
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) NewSubscription() mk2driver.Mk2 {
|
||||||
|
sub := &subscription{
|
||||||
|
send: make(chan *mk2driver.Mk2Info),
|
||||||
|
}
|
||||||
|
c.register <- sub
|
||||||
|
return sub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) run() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case r := <-c.register:
|
||||||
|
c.plugins[r] = true
|
||||||
|
case e := <-c.C():
|
||||||
|
for plugin := range c.plugins {
|
||||||
|
select {
|
||||||
|
case plugin.send <- e:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type subscription struct {
|
||||||
|
send chan *mk2driver.Mk2Info
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *subscription) C() chan *mk2driver.Mk2Info {
|
||||||
|
return s.send
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *subscription) Close() {
|
||||||
|
close(s.send)
|
||||||
|
}
|
||||||
@@ -1,20 +1,75 @@
|
|||||||
package mk2if
|
package mk2driver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"math"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type scaling struct {
|
type scaling struct {
|
||||||
scale float64
|
scale float64
|
||||||
offset float64
|
offset float64
|
||||||
|
signed bool
|
||||||
|
supported bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:deadcode,varcheck
|
||||||
|
const (
|
||||||
|
ramVarVMains = iota
|
||||||
|
ramVarIMains
|
||||||
|
ramVarVInverter
|
||||||
|
ramVarIInverter
|
||||||
|
ramVarVBat
|
||||||
|
ramVarIBat
|
||||||
|
ramVarVBatRipple
|
||||||
|
ramVarInverterPeriod
|
||||||
|
ramVarMainPeriod
|
||||||
|
ramVarIACLoad
|
||||||
|
ramVarVirSwitchPos
|
||||||
|
ramVarIgnACInState
|
||||||
|
ramVarMultiFuncRelay
|
||||||
|
ramVarChargeState
|
||||||
|
ramVarInverterPower1
|
||||||
|
ramVarInverterPower2
|
||||||
|
ramVarOutPower
|
||||||
|
|
||||||
|
ramVarMaxOffset = 14
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
infoFrameHeader = 0x20
|
||||||
|
frameHeader = 0xff
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
acL1InfoFrame = 0x08
|
||||||
|
dcInfoFrame = 0x0C
|
||||||
|
setTargetFrame = 0x41
|
||||||
|
infoReqFrame = 0x46 //F
|
||||||
|
ledFrame = 0x4C
|
||||||
|
vFrame = 0x56
|
||||||
|
winmonFrame = 0x57
|
||||||
|
)
|
||||||
|
|
||||||
|
// info frame types
|
||||||
|
const (
|
||||||
|
infoReqAddrDC = 0x00
|
||||||
|
infoReqAddrACL1 = 0x01
|
||||||
|
)
|
||||||
|
|
||||||
|
// winmon frame commands
|
||||||
|
const (
|
||||||
|
commandReadRAMVar = 0x30
|
||||||
|
commandGetRAMVarInfo = 0x36
|
||||||
|
|
||||||
|
commandReadRAMResponse = 0x85
|
||||||
|
commandGetRAMVarInfoResponse = 0x8E
|
||||||
|
)
|
||||||
|
|
||||||
type mk2Ser struct {
|
type mk2Ser struct {
|
||||||
info *Mk2Info
|
info *Mk2Info
|
||||||
p io.ReadWriter
|
p io.ReadWriter
|
||||||
@@ -26,13 +81,13 @@ type mk2Ser struct {
|
|||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMk2Connection(dev io.ReadWriter) (Mk2If, error) {
|
func NewMk2Connection(dev io.ReadWriter) (Mk2, error) {
|
||||||
mk2 := &mk2Ser{}
|
mk2 := &mk2Ser{}
|
||||||
mk2.p = dev
|
mk2.p = dev
|
||||||
mk2.info = &Mk2Info{}
|
mk2.info = &Mk2Info{}
|
||||||
mk2.scaleCount = 0
|
mk2.scaleCount = 0
|
||||||
mk2.frameLock = false
|
mk2.frameLock = false
|
||||||
mk2.scales = make([]scaling, 0, 14)
|
mk2.scales = make([]scaling, 0, ramVarMaxOffset)
|
||||||
mk2.setTarget()
|
mk2.setTarget()
|
||||||
mk2.run = make(chan struct{})
|
mk2.run = make(chan struct{})
|
||||||
mk2.infochan = make(chan *Mk2Info)
|
mk2.infochan = make(chan *Mk2Info)
|
||||||
@@ -43,9 +98,8 @@ func NewMk2Connection(dev io.ReadWriter) (Mk2If, error) {
|
|||||||
|
|
||||||
// Locks to incoming frame.
|
// Locks to incoming frame.
|
||||||
func (m *mk2Ser) frameLocker() {
|
func (m *mk2Ser) frameLocker() {
|
||||||
|
|
||||||
frame := make([]byte, 256)
|
frame := make([]byte, 256)
|
||||||
var size byte
|
var frameLength byte
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-m.run:
|
case <-m.run:
|
||||||
@@ -54,34 +108,36 @@ func (m *mk2Ser) frameLocker() {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if m.frameLock {
|
if m.frameLock {
|
||||||
size = m.readByte()
|
frameLength = m.readByte()
|
||||||
l, err := io.ReadFull(m.p, frame[0:int(size)+1])
|
frameLengthOffset := int(frameLength) + 1
|
||||||
|
l, err := io.ReadFull(m.p, frame[:frameLengthOffset])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.addError(fmt.Errorf("Read Error: %v", err))
|
m.addError(fmt.Errorf("Read Error: %v", err))
|
||||||
m.frameLock = false
|
m.frameLock = false
|
||||||
} else if l != int(size)+1 {
|
} else if l != frameLengthOffset {
|
||||||
m.addError(errors.New("Read Length Error"))
|
m.addError(errors.New("Read Length Error"))
|
||||||
m.frameLock = false
|
m.frameLock = false
|
||||||
} else {
|
} else {
|
||||||
m.handleFrame(size, frame[0:int(size+1)])
|
m.handleFrame(frameLength, frame[:frameLengthOffset])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmp := m.readByte()
|
tmp := m.readByte()
|
||||||
if tmp == 0xff || tmp == 0x20 {
|
frameLengthOffset := int(frameLength)
|
||||||
l, err := io.ReadFull(m.p, frame[0:int(size)])
|
if tmp == frameHeader || tmp == infoFrameHeader {
|
||||||
|
l, err := io.ReadFull(m.p, frame[:frameLengthOffset])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.addError(fmt.Errorf("Read Error: %v", err))
|
m.addError(fmt.Errorf("Read Error: %v", err))
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
} else if l != int(size) {
|
} else if l != frameLengthOffset {
|
||||||
m.addError(errors.New("Read Length Error"))
|
m.addError(errors.New("Read Length Error"))
|
||||||
} else {
|
} else {
|
||||||
if checkChecksum(size, tmp, frame[0:int(size)]) {
|
if checkChecksum(frameLength, tmp, frame[:frameLengthOffset]) {
|
||||||
m.frameLock = true
|
m.frameLock = true
|
||||||
log.Printf("Locked")
|
logrus.Info("Locked")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size = tmp
|
frameLength = tmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,34 +183,35 @@ func (m *mk2Ser) updateReport() {
|
|||||||
|
|
||||||
// Checks for valid frame and chooses decoding.
|
// Checks for valid frame and chooses decoding.
|
||||||
func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
||||||
|
logrus.Debugf("frame %#v", frame)
|
||||||
if checkChecksum(l, frame[0], frame[1:]) {
|
if checkChecksum(l, frame[0], frame[1:]) {
|
||||||
switch frame[0] {
|
switch frame[0] {
|
||||||
case 0xff:
|
case frameHeader:
|
||||||
switch frame[1] {
|
switch frame[1] {
|
||||||
case 0x56: // V
|
case vFrame:
|
||||||
m.versionDecode(frame[2:])
|
m.versionDecode(frame[2:])
|
||||||
case 0x57:
|
case winmonFrame:
|
||||||
switch frame[2] {
|
switch frame[2] {
|
||||||
case 0x8e:
|
case commandGetRAMVarInfoResponse:
|
||||||
m.scaleDecode(frame[2:])
|
m.scaleDecode(frame[2:])
|
||||||
case 0x85:
|
case commandReadRAMResponse:
|
||||||
m.stateDecode(frame[2:])
|
m.stateDecode(frame[2:])
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0x4C: // L
|
case ledFrame:
|
||||||
m.ledDecode(frame[2:])
|
m.ledDecode(frame[2:])
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0x20:
|
case infoFrameHeader:
|
||||||
switch frame[5] {
|
switch frame[5] {
|
||||||
case 0x0C:
|
case dcInfoFrame:
|
||||||
m.dcDecode(frame[1:])
|
m.dcDecode(frame[1:])
|
||||||
case 0x08:
|
case acL1InfoFrame:
|
||||||
m.acDecode(frame[1:])
|
m.acDecode(frame[1:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Invalid incoming frame checksum: %x", frame)
|
logrus.Errorf("Invalid incoming frame checksum: %x", frame)
|
||||||
m.frameLock = false
|
m.frameLock = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +219,7 @@ func (m *mk2Ser) handleFrame(l byte, frame []byte) {
|
|||||||
// Set the target VBus device.
|
// Set the target VBus device.
|
||||||
func (m *mk2Ser) setTarget() {
|
func (m *mk2Ser) setTarget() {
|
||||||
cmd := make([]byte, 3)
|
cmd := make([]byte, 3)
|
||||||
cmd[0] = 0x41 // A
|
cmd[0] = setTargetFrame
|
||||||
cmd[1] = 0x01
|
cmd[1] = 0x01
|
||||||
cmd[2] = 0x00
|
cmd[2] = 0x00
|
||||||
m.sendCommand(cmd)
|
m.sendCommand(cmd)
|
||||||
@@ -171,57 +228,98 @@ func (m *mk2Ser) setTarget() {
|
|||||||
// Request the scaling factor for entry 'in'.
|
// Request the scaling factor for entry 'in'.
|
||||||
func (m *mk2Ser) reqScaleFactor(in byte) {
|
func (m *mk2Ser) reqScaleFactor(in byte) {
|
||||||
cmd := make([]byte, 4)
|
cmd := make([]byte, 4)
|
||||||
cmd[0] = 0x57 // W
|
cmd[0] = winmonFrame
|
||||||
cmd[1] = 0x36
|
cmd[1] = commandGetRAMVarInfo
|
||||||
cmd[2] = in
|
cmd[2] = in
|
||||||
m.sendCommand(cmd)
|
m.sendCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func int16Abs(in int16) uint16 {
|
||||||
|
if in < 0 {
|
||||||
|
return uint16(-in)
|
||||||
|
}
|
||||||
|
return uint16(in)
|
||||||
|
}
|
||||||
|
|
||||||
// Decode the scale factor frame.
|
// Decode the scale factor frame.
|
||||||
func (m *mk2Ser) scaleDecode(frame []byte) {
|
func (m *mk2Ser) scaleDecode(frame []byte) {
|
||||||
scl := uint16(frame[2])<<8 + uint16(frame[1])
|
|
||||||
ofs := int16(uint16(frame[5])<<8 + uint16(frame[4]))
|
|
||||||
|
|
||||||
tmp := scaling{}
|
tmp := scaling{}
|
||||||
tmp.offset = float64(ofs)
|
logrus.Debugf("Scale frame(%d): 0x%x", len(frame), frame)
|
||||||
if scl >= 0x4000 {
|
if len(frame) < 6 {
|
||||||
tmp.scale = math.Abs(1 / (0x8000 - float64(scl)))
|
tmp.supported = false
|
||||||
|
logrus.Warnf("Skiping scaling factors for: %d", m.scaleCount)
|
||||||
} else {
|
} else {
|
||||||
tmp.scale = math.Abs(float64(scl))
|
tmp.supported = true
|
||||||
|
var scl int16
|
||||||
|
var ofs int16
|
||||||
|
if len(frame) == 6 {
|
||||||
|
scl = int16(frame[2])<<8 + int16(frame[1])
|
||||||
|
ofs = int16(uint16(frame[4])<<8 + uint16(frame[3]))
|
||||||
|
} else {
|
||||||
|
scl = int16(frame[2])<<8 + int16(frame[1])
|
||||||
|
ofs = int16(uint16(frame[5])<<8 + uint16(frame[4]))
|
||||||
|
}
|
||||||
|
if scl < 0 {
|
||||||
|
tmp.signed = true
|
||||||
|
}
|
||||||
|
tmp.offset = float64(ofs)
|
||||||
|
scale := int16Abs(scl)
|
||||||
|
if scale >= 0x4000 {
|
||||||
|
tmp.scale = 1 / (0x8000 - float64(scale))
|
||||||
|
} else {
|
||||||
|
tmp.scale = float64(scale)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
logrus.Debugf("scalecount %v: %#v \n", m.scaleCount, tmp)
|
||||||
m.scales = append(m.scales, tmp)
|
m.scales = append(m.scales, tmp)
|
||||||
|
|
||||||
m.scaleCount++
|
m.scaleCount++
|
||||||
if m.scaleCount < 14 {
|
if m.scaleCount < ramVarMaxOffset {
|
||||||
m.reqScaleFactor(byte(m.scaleCount))
|
m.reqScaleFactor(byte(m.scaleCount))
|
||||||
} else {
|
} else {
|
||||||
log.Print("Monitoring starting.")
|
logrus.Info("Monitoring starting.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the version number
|
// Decode the version number
|
||||||
func (m *mk2Ser) versionDecode(frame []byte) {
|
func (m *mk2Ser) versionDecode(frame []byte) {
|
||||||
|
logrus.Debugf("versiondecode %v", frame)
|
||||||
m.info.Version = 0
|
m.info.Version = 0
|
||||||
m.info.Valid = true
|
m.info.Valid = true
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
m.info.Version += uint32(frame[i]) << uint(i) * 8
|
m.info.Version += uint32(frame[i]) << uint(i) * 8
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.scaleCount < 14 {
|
if m.scaleCount < ramVarMaxOffset {
|
||||||
log.Print("Get scaling factors.")
|
logrus.Info("Get scaling factors.")
|
||||||
m.reqScaleFactor(byte(m.scaleCount))
|
m.reqScaleFactor(byte(m.scaleCount))
|
||||||
} else {
|
} else {
|
||||||
// Send DC status request
|
// Send DC status request
|
||||||
cmd := make([]byte, 2)
|
cmd := make([]byte, 2)
|
||||||
cmd[0] = 0x46 //F
|
cmd[0] = infoReqFrame
|
||||||
cmd[1] = 0
|
cmd[1] = infoReqAddrDC
|
||||||
m.sendCommand(cmd)
|
m.sendCommand(cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode with correct signedness and apply scale
|
||||||
|
func (m *mk2Ser) applyScaleAndSign(data []byte, scale int) float64 {
|
||||||
|
var value float64
|
||||||
|
if !m.scales[scale].supported {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if m.scales[scale].signed {
|
||||||
|
value = getSigned(data)
|
||||||
|
} else {
|
||||||
|
value = getUnsigned16(data)
|
||||||
|
}
|
||||||
|
return m.applyScale(value, scale)
|
||||||
|
}
|
||||||
|
|
||||||
// Apply scaling to float
|
// Apply scaling to float
|
||||||
func (m *mk2Ser) applyScale(value float64, scale int) float64 {
|
func (m *mk2Ser) applyScale(value float64, scale int) float64 {
|
||||||
|
if !m.scales[scale].supported {
|
||||||
|
return value
|
||||||
|
}
|
||||||
return m.scales[scale].scale * (value + m.scales[scale].offset)
|
return m.scales[scale].scale * (value + m.scales[scale].offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,6 +328,11 @@ func getSigned(data []byte) float64 {
|
|||||||
return float64(int16(data[0]) + int16(data[1])<<8)
|
return float64(int16(data[0]) + int16(data[1])<<8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert bytes->int16->float
|
||||||
|
func getUnsigned16(data []byte) float64 {
|
||||||
|
return float64(uint16(data[0]) + uint16(data[1])<<8)
|
||||||
|
}
|
||||||
|
|
||||||
// Convert bytes->uint32->float
|
// Convert bytes->uint32->float
|
||||||
func getUnsigned(data []byte) float64 {
|
func getUnsigned(data []byte) float64 {
|
||||||
return float64(uint32(data[0]) + uint32(data[1])<<8 + uint32(data[2])<<16)
|
return float64(uint32(data[0]) + uint32(data[1])<<8 + uint32(data[2])<<16)
|
||||||
@@ -237,43 +340,49 @@ func getUnsigned(data []byte) float64 {
|
|||||||
|
|
||||||
// Decodes DC frame.
|
// Decodes DC frame.
|
||||||
func (m *mk2Ser) dcDecode(frame []byte) {
|
func (m *mk2Ser) dcDecode(frame []byte) {
|
||||||
m.info.BatVoltage = m.applyScale(getSigned(frame[5:7]), 4)
|
m.info.BatVoltage = m.applyScaleAndSign(frame[5:7], ramVarVBat)
|
||||||
|
|
||||||
usedC := m.applyScale(getUnsigned(frame[7:10]), 5)
|
usedC := m.applyScale(getUnsigned(frame[7:10]), ramVarIBat)
|
||||||
chargeC := m.applyScale(getUnsigned(frame[10:13]), 5)
|
chargeC := m.applyScale(getUnsigned(frame[10:13]), ramVarIBat)
|
||||||
m.info.BatCurrent = usedC - chargeC
|
m.info.BatCurrent = usedC - chargeC
|
||||||
|
|
||||||
m.info.OutFrequency = 10 / (m.applyScale(float64(frame[13]), 7))
|
m.info.OutFrequency = m.calcFreq(frame[13], ramVarInverterPeriod)
|
||||||
|
logrus.Debugf("dcDecode %#v", m.info)
|
||||||
|
|
||||||
// Send L1 status request
|
// Send L1 status request
|
||||||
cmd := make([]byte, 2)
|
cmd := make([]byte, 2)
|
||||||
cmd[0] = 0x46 //F
|
cmd[0] = infoReqFrame
|
||||||
cmd[1] = 1
|
cmd[1] = infoReqAddrACL1
|
||||||
m.sendCommand(cmd)
|
m.sendCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decodes AC frame.
|
// Decodes AC frame.
|
||||||
func (m *mk2Ser) acDecode(frame []byte) {
|
func (m *mk2Ser) acDecode(frame []byte) {
|
||||||
m.info.InVoltage = m.applyScale(getSigned(frame[5:7]), 0)
|
m.info.InVoltage = m.applyScale(getSigned(frame[5:7]), ramVarVMains)
|
||||||
m.info.InCurrent = m.applyScale(getSigned(frame[7:9]), 1)
|
m.info.InCurrent = m.applyScale(getSigned(frame[7:9]), ramVarIMains)
|
||||||
m.info.OutVoltage = m.applyScale(getSigned(frame[9:11]), 2)
|
m.info.OutVoltage = m.applyScale(getSigned(frame[9:11]), ramVarVInverter)
|
||||||
m.info.OutCurrent = m.applyScale(getSigned(frame[11:13]), 3)
|
m.info.OutCurrent = m.applyScale(getSigned(frame[11:13]), ramVarIInverter)
|
||||||
|
m.info.InFrequency = m.calcFreq(frame[13], ramVarMainPeriod)
|
||||||
|
|
||||||
if frame[13] == 0xff {
|
logrus.Debugf("acDecode %#v", m.info)
|
||||||
m.info.InFrequency = 0
|
|
||||||
} else {
|
|
||||||
m.info.InFrequency = 10 / (m.applyScale(float64(frame[13]), 8))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send status request
|
// Send status request
|
||||||
cmd := make([]byte, 1)
|
cmd := make([]byte, 1)
|
||||||
cmd[0] = 0x4C //F
|
cmd[0] = ledFrame
|
||||||
m.sendCommand(cmd)
|
m.sendCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mk2Ser) calcFreq(data byte, scaleIndex int) float64 {
|
||||||
|
if data == 0xff || data == 0x00 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return 10 / (m.applyScale(float64(data), scaleIndex))
|
||||||
|
}
|
||||||
|
|
||||||
// Decode charge state of battery.
|
// Decode charge state of battery.
|
||||||
func (m *mk2Ser) stateDecode(frame []byte) {
|
func (m *mk2Ser) stateDecode(frame []byte) {
|
||||||
m.info.ChargeState = m.applyScale(getSigned(frame[1:3]), 13)
|
m.info.ChargeState = m.applyScaleAndSign(frame[1:3], ramVarChargeState)
|
||||||
|
logrus.Debugf("battery state decode %#v", m.info)
|
||||||
m.updateReport()
|
m.updateReport()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,9 +392,9 @@ func (m *mk2Ser) ledDecode(frame []byte) {
|
|||||||
m.info.LEDs = getLEDs(frame[0], frame[1])
|
m.info.LEDs = getLEDs(frame[0], frame[1])
|
||||||
// Send charge state request
|
// Send charge state request
|
||||||
cmd := make([]byte, 4)
|
cmd := make([]byte, 4)
|
||||||
cmd[0] = 0x57 //W
|
cmd[0] = winmonFrame
|
||||||
cmd[1] = 0x30
|
cmd[1] = commandReadRAMVar
|
||||||
cmd[2] = 13
|
cmd[2] = ramVarChargeState
|
||||||
m.sendCommand(cmd)
|
m.sendCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +421,7 @@ func (m *mk2Ser) sendCommand(data []byte) {
|
|||||||
l := len(data)
|
l := len(data)
|
||||||
dataOut := make([]byte, l+3)
|
dataOut := make([]byte, l+3)
|
||||||
dataOut[0] = byte(l + 1)
|
dataOut[0] = byte(l + 1)
|
||||||
dataOut[1] = 0xff
|
dataOut[1] = frameHeader
|
||||||
cr := -dataOut[0] - dataOut[1]
|
cr := -dataOut[0] - dataOut[1]
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
cr = cr - data[i]
|
cr = cr - data[i]
|
||||||
@@ -320,6 +429,7 @@ func (m *mk2Ser) sendCommand(data []byte) {
|
|||||||
}
|
}
|
||||||
dataOut[l+2] = cr
|
dataOut[l+2] = cr
|
||||||
|
|
||||||
|
logrus.Debugf("sendCommand %#v", dataOut)
|
||||||
_, err := m.p.Write(dataOut)
|
_, err := m.p.Write(dataOut)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.addError(fmt.Errorf("Write error: %v", err))
|
m.addError(fmt.Errorf("Write error: %v", err))
|
||||||
311
mk2driver/mk2_test.go
Normal file
311
mk2driver/mk2_test.go
Normal file
@@ -0,0 +1,311 @@
|
|||||||
|
package mk2driver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
var knownWrites = []byte{
|
||||||
|
0x04, 0xff, 0x41, 0x01, 0x00, 0xbb,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x00, 0x00, 0x6f,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x01, 0x00, 0x6e,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x02, 0x00, 0x6d,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x03, 0x00, 0x6c,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x04, 0x00, 0x6b,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x05, 0x00, 0x6a,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x06, 0x00, 0x69,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x07, 0x00, 0x68,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x08, 0x00, 0x67,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x09, 0x00, 0x66,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0a, 0x00, 0x65,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0b, 0x00, 0x64,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0c, 0x00, 0x63,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0d, 0x00, 0x62,
|
||||||
|
0x03, 0xff, 0x46, 0x00, 0xb8,
|
||||||
|
0x03, 0xff, 0x46, 0x01, 0xb7,
|
||||||
|
0x02, 0xff, 0x4c, 0xb3,
|
||||||
|
0x05, 0xff, 0x57, 0x30, 0x0d, 0x00, 0x68,
|
||||||
|
}
|
||||||
|
|
||||||
|
var writeBuffer = bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
const (
|
||||||
|
testDelta = 0.00000001
|
||||||
|
)
|
||||||
|
|
||||||
|
type testIo struct {
|
||||||
|
io.Reader
|
||||||
|
io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIOStub(readBuffer []byte) io.ReadWriter {
|
||||||
|
return &testIo{
|
||||||
|
Reader: bytes.NewBuffer(readBuffer),
|
||||||
|
Writer: writeBuffer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test a know sequence as reference as extracted from Mk2
|
||||||
|
func TestSync(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
knownReadBuffer []byte
|
||||||
|
knownWrites []byte
|
||||||
|
result Mk2Info
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "basic",
|
||||||
|
knownReadBuffer: []byte{
|
||||||
|
//Len Cmd
|
||||||
|
0x04, 0xff, 0x41, 0x01, 0x00, 0xbb,
|
||||||
|
0x07, 0xff, 0x56, 0x96, 0x3e, 0x11, 0x00, 0x00, 0xbf,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x00, 0x00, 0x6a,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x64, 0x80, 0x8f, 0x00, 0x00, 0xa1,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x00, 0x00, 0x6a,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x00, 0x00, 0x6a,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x00, 0x00, 0x6a,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x64, 0x80, 0x8f, 0x00, 0x00, 0xa1,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x00, 0x00, 0x6a,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x57, 0x78, 0x8f, 0x00, 0x01, 0xb5,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x2f, 0x7c, 0x8f, 0x00, 0x00, 0xda,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x64, 0x80, 0x8f, 0x00, 0x00, 0xa1,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x04, 0x00, 0x8f, 0x00, 0x80, 0x01,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x01, 0x00, 0x8f, 0x00, 0x80, 0x04,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x02, 0x00, 0x8f, 0x00, 0x80, 0x03,
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x38, 0x7f, 0x8f, 0x00, 0x00, 0xce,
|
||||||
|
0x07, 0xff, 0x56, 0x96, 0x3e, 0x11, 0x00, 0x00, 0xbf,
|
||||||
|
0x0f, 0x20, 0xf3, 0x00, 0xc8, 0x02, 0x0c, 0xa1, 0x05, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x88, 0xb2,
|
||||||
|
0x0f, 0x20, 0x01, 0x01, 0xca, 0x09, 0x08, 0xaa, 0x58, 0xab, 0x00, 0xaa, 0x58, 0x9a, 0x00, 0xc3, 0xe8,
|
||||||
|
0x06, 0xff, 0x4c, 0x03, 0x00, 0x00, 0x00, 0xac,
|
||||||
|
0x05, 0xff, 0x57, 0x85, 0xc8, 0x00, 0x58,
|
||||||
|
},
|
||||||
|
knownWrites: []byte{
|
||||||
|
0x04, 0xff, 0x41, 0x01, 0x00, 0xbb,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x00, 0x00, 0x6f,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x01, 0x00, 0x6e,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x02, 0x00, 0x6d,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x03, 0x00, 0x6c,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x04, 0x00, 0x6b,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x05, 0x00, 0x6a,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x06, 0x00, 0x69,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x07, 0x00, 0x68,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x08, 0x00, 0x67,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x09, 0x00, 0x66,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0a, 0x00, 0x65,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0b, 0x00, 0x64,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0c, 0x00, 0x63,
|
||||||
|
0x05, 0xff, 0x57, 0x36, 0x0d, 0x00, 0x62,
|
||||||
|
0x03, 0xff, 0x46, 0x00, 0xb8,
|
||||||
|
0x03, 0xff, 0x46, 0x01, 0xb7,
|
||||||
|
0x02, 0xff, 0x4c, 0xb3,
|
||||||
|
0x05, 0xff, 0x57, 0x30, 0x0d, 0x00, 0x68,
|
||||||
|
},
|
||||||
|
result: Mk2Info{
|
||||||
|
Version: uint32(2736),
|
||||||
|
BatVoltage: 14.41,
|
||||||
|
BatCurrent: -0.4,
|
||||||
|
InVoltage: 226.98,
|
||||||
|
InCurrent: 1.71,
|
||||||
|
InFrequency: 50.10256410256411,
|
||||||
|
OutVoltage: 226.980,
|
||||||
|
OutCurrent: 1.54,
|
||||||
|
OutFrequency: 50.025510204081634,
|
||||||
|
ChargeState: 1,
|
||||||
|
LEDs: map[Led]LEDstate{
|
||||||
|
LedMain: LedOn,
|
||||||
|
LedAbsorption: LedOn,
|
||||||
|
LedBulk: LedOff,
|
||||||
|
LedFloat: LedOff,
|
||||||
|
LedInverter: LedOff,
|
||||||
|
LedOverload: LedOff,
|
||||||
|
LedLowBattery: LedOff,
|
||||||
|
LedTemperature: LedOff,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "multiplus24/3000",
|
||||||
|
knownReadBuffer: []byte{
|
||||||
|
//Len Cmd
|
||||||
|
0x04, 0xff, 0x41, 0x01, 0x00, 0xbb,
|
||||||
|
0x07, 0xff, 0x56, 0x98, 0x3e, 0x11, 0x00, 0x00, 0xbd, // version
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x0, 0x0, 0x6a, // scale 0
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x0, 0x0, 0x6a, // scale 1
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x0, 0x0, 0x6a, // scale 2
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x0, 0x0, 0x6a, // scale 3
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x0, 0x0, 0x6a, // scale 4
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x64, 0x80, 0x8f, 0x0, 0x0, 0xa1, // scale 5
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x9c, 0x7f, 0x8f, 0x0, 0x0, 0x6a, // scale 6
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x57, 0x78, 0x8f, 0x0, 0x1, 0xb5, // scale 7
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x2f, 0x7c, 0x8f, 0x0, 0x0, 0xda, // scale 8
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x64, 0x80, 0x8f, 0x0, 0x0, 0xa1, //scale 9
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x4, 0x0, 0x8f, 0x0, 0x80, 0x1, // scale 10
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x1, 0x0, 0x8f, 0x0, 0x80, 0x4, // scale 11
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x6, 0x0, 0x8f, 0x0, 0x80, 0xff, // scale 12
|
||||||
|
0x08, 0xff, 0x57, 0x8e, 0x38, 0x7f, 0x8f, 0x0, 0x0, 0xce, // scale 13
|
||||||
|
0x07, 0xff, 0x56, 0x98, 0x3e, 0x11, 0x0, 0x0, 0xbd, // version
|
||||||
|
0x0f, 0x20, 0xb6, 0x89, 0x6d, 0xb7, 0xc, 0x4e, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x88, 0x82, // dc info
|
||||||
|
0x0f, 0x20, 0x1, 0x1, 0x6d, 0xb7, 0x8, 0x77, 0x5b, 0x21, 0x0, 0x77, 0x5b, 0xfe, 0xff, 0xc3, 0x1e, // ac info
|
||||||
|
0x08, 0xff, 0x4c, 0x9, 0x0, 0x0, 0x0, 0x3, 0x0, 0xa1,
|
||||||
|
0x05, 0xff, 0x57, 0x85, 0xc8, 0x0, 0x58,
|
||||||
|
},
|
||||||
|
knownWrites: []byte{},
|
||||||
|
result: Mk2Info{
|
||||||
|
Version: 0xac0,
|
||||||
|
BatVoltage: 26.38,
|
||||||
|
BatCurrent: 0,
|
||||||
|
InVoltage: 234.15,
|
||||||
|
InCurrent: 0.33,
|
||||||
|
InFrequency: 50.1025641025641,
|
||||||
|
OutVoltage: 234.15,
|
||||||
|
OutCurrent: -0.02,
|
||||||
|
OutFrequency: 50.025510204081634,
|
||||||
|
ChargeState: 1,
|
||||||
|
LEDs: map[Led]LEDstate{
|
||||||
|
LedMain: LedOn,
|
||||||
|
LedAbsorption: LedOff,
|
||||||
|
LedBulk: LedOff,
|
||||||
|
LedFloat: LedOn,
|
||||||
|
LedInverter: LedOff,
|
||||||
|
LedOverload: LedOff,
|
||||||
|
LedLowBattery: LedOff,
|
||||||
|
LedTemperature: LedOff,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
testIO := NewIOStub(tt.knownReadBuffer)
|
||||||
|
mk2, err := NewMk2Connection(testIO)
|
||||||
|
assert.NoError(t, err, "Could not open MK2")
|
||||||
|
|
||||||
|
event := <-mk2.C()
|
||||||
|
mk2.Close()
|
||||||
|
|
||||||
|
if len(tt.knownWrites) > 0 {
|
||||||
|
assert.Equal(t, 0, bytes.Compare(writeBuffer.Bytes(), knownWrites), "Expected writes did not match received writes")
|
||||||
|
}
|
||||||
|
assert.True(t, event.Valid, "data not valid")
|
||||||
|
assert.Equal(t, tt.result.Version, event.Version, "Invalid version decoded")
|
||||||
|
assert.Equal(t, 0, len(event.Errors), "Reported errors not empty")
|
||||||
|
assert.Equal(t, tt.result.LEDs, event.LEDs, "Reported LEDs incorrect")
|
||||||
|
|
||||||
|
assert.InDelta(t, tt.result.BatVoltage, event.BatVoltage, testDelta, "BatVoltage conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.BatCurrent, event.BatCurrent, testDelta, "BatCurrent conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.InVoltage, event.InVoltage, testDelta, "InVoltage conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.InCurrent, event.InCurrent, testDelta, "InCurrent conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.InFrequency, event.InFrequency, testDelta, "InFrequency conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.OutVoltage, event.OutVoltage, testDelta, "OutVoltage conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.OutCurrent, event.OutCurrent, testDelta, "OutCurrent conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.OutFrequency, event.OutFrequency, testDelta, "OutFrequency conversion failed")
|
||||||
|
assert.InDelta(t, tt.result.ChargeState, event.ChargeState, testDelta, "ChargeState conversion failed")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_scaleDecode(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
frame []byte
|
||||||
|
expectedScaling scaling
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Valid scale",
|
||||||
|
frame: []byte{0x8e, 0x9c, 0x7f, 0x8f, 0x01, 0x00, 0x6a},
|
||||||
|
expectedScaling: scaling{
|
||||||
|
scale: 0.01,
|
||||||
|
offset: 1,
|
||||||
|
supported: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Unsupported frame",
|
||||||
|
frame: []byte{0x00},
|
||||||
|
expectedScaling: scaling{
|
||||||
|
supported: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
m := &mk2Ser{
|
||||||
|
scales: make([]scaling, 0, ramVarMaxOffset),
|
||||||
|
p: NewIOStub([]byte{}),
|
||||||
|
}
|
||||||
|
m.scaleDecode(tt.frame)
|
||||||
|
assert.Equal(t, 1, len(m.scales))
|
||||||
|
assert.Equal(t, 1, m.scaleCount)
|
||||||
|
assert.Equal(t, tt.expectedScaling.supported, m.scales[0].supported)
|
||||||
|
assert.Equal(t, tt.expectedScaling.signed, m.scales[0].signed)
|
||||||
|
if tt.expectedScaling.supported {
|
||||||
|
assert.InDelta(t, tt.expectedScaling.offset, m.scales[0].offset, testDelta)
|
||||||
|
assert.InDelta(t, tt.expectedScaling.scale, m.scales[0].scale, testDelta)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_mk2Ser_calcFreq(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
scales []scaling
|
||||||
|
data byte
|
||||||
|
scaleIndex int
|
||||||
|
want float64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Calculate working low",
|
||||||
|
scales: []scaling{
|
||||||
|
{supported: false},
|
||||||
|
},
|
||||||
|
data: 0x01,
|
||||||
|
scaleIndex: 0,
|
||||||
|
want: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Calculate working high",
|
||||||
|
scales: []scaling{
|
||||||
|
{
|
||||||
|
supported: true,
|
||||||
|
offset: 0,
|
||||||
|
scale: 0.01,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: 0xFE,
|
||||||
|
scaleIndex: 0,
|
||||||
|
want: 3.937007874015748,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Calculate clip high",
|
||||||
|
scales: []scaling{
|
||||||
|
{supported: false},
|
||||||
|
},
|
||||||
|
data: 0xff,
|
||||||
|
scaleIndex: 0,
|
||||||
|
want: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Calculate clip low",
|
||||||
|
scales: []scaling{
|
||||||
|
{supported: false},
|
||||||
|
},
|
||||||
|
data: 0x00,
|
||||||
|
scaleIndex: 0,
|
||||||
|
want: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
m := &mk2Ser{
|
||||||
|
scales: tt.scales,
|
||||||
|
}
|
||||||
|
got := m.calcFreq(tt.data, tt.scaleIndex)
|
||||||
|
assert.InDelta(t, tt.want, got, testDelta)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package mk2if
|
package mk2driver
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ type Mk2Info struct {
|
|||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mk2If interface {
|
type Mk2 interface {
|
||||||
C() chan *Mk2Info
|
C() chan *Mk2Info
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package mk2if
|
package mk2driver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ type mock struct {
|
|||||||
c chan *Mk2Info
|
c chan *Mk2Info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMk2Mock() Mk2If {
|
func NewMk2Mock() Mk2 {
|
||||||
tmp := &mock{
|
tmp := &mock{
|
||||||
c: make(chan *Mk2Info, 1),
|
c: make(chan *Mk2Info, 1),
|
||||||
}
|
}
|
||||||
@@ -64,7 +63,6 @@ func (m *mock) genMockValues() {
|
|||||||
if mult < 0 {
|
if mult < 0 {
|
||||||
mult = 1.0
|
mult = 1.0
|
||||||
}
|
}
|
||||||
fmt.Printf("Sending\n")
|
|
||||||
m.c <- input
|
m.c <- input
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
47
plugins/cli/cli.go
Normal file
47
plugins/cli/cli.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = logrus.WithField("ctx", "inverter-gui-cli")
|
||||||
|
|
||||||
|
type Cli struct {
|
||||||
|
mk2driver.Mk2
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCli(mk2 mk2driver.Mk2) {
|
||||||
|
newCli := &Cli{
|
||||||
|
Mk2: mk2,
|
||||||
|
}
|
||||||
|
go newCli.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cli) run() {
|
||||||
|
for e := range c.C() {
|
||||||
|
if e.Valid {
|
||||||
|
printInfo(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func printInfo(info *mk2driver.Mk2Info) {
|
||||||
|
log.Infof("Version: %v", info.Version)
|
||||||
|
log.Infof("Bat Volt: %.2fV Bat Cur: %.2fA", info.BatVoltage, info.BatCurrent)
|
||||||
|
log.Infof("In Volt: %.2fV In Cur: %.2fA In Freq %.2fHz", info.InVoltage, info.InCurrent, info.InFrequency)
|
||||||
|
log.Infof("Out Volt: %.2fV Out Cur: %.2fA Out Freq %.2fHz", info.OutVoltage, info.OutCurrent, info.OutFrequency)
|
||||||
|
log.Infof("In Power %.2fW Out Power %.2fW", info.InVoltage*info.InCurrent, info.OutVoltage*info.OutCurrent)
|
||||||
|
log.Infof("Charge State: %.2f%%", info.ChargeState*100)
|
||||||
|
log.Info("LEDs state:")
|
||||||
|
for k, v := range info.LEDs {
|
||||||
|
log.Infof(" %s %s", mk2driver.LedNames[k], mk2driver.StateNames[v])
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(info.Errors) != 0 {
|
||||||
|
log.Info("Errors:")
|
||||||
|
for _, err := range info.Errors {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
73
plugins/mqttclient/mqtt.go
Normal file
73
plugins/mqttclient/mqtt.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package mqttclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = logrus.WithField("ctx", "inverter-gui-mqtt")
|
||||||
|
|
||||||
|
const keepAlive = 5 * time.Second
|
||||||
|
|
||||||
|
// Config sets MQTT client configuration
|
||||||
|
type Config struct {
|
||||||
|
Broker string
|
||||||
|
ClientID string
|
||||||
|
Topic string
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an MQTT client that starts publishing MK2 data as it is received.
|
||||||
|
func New(mk2 mk2driver.Mk2, config Config) error {
|
||||||
|
c := mqtt.NewClient(getOpts(config))
|
||||||
|
if token := c.Connect(); token.Wait() && token.Error() != nil {
|
||||||
|
return token.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for e := range mk2.C() {
|
||||||
|
if e.Valid {
|
||||||
|
data, err := json.Marshal(e)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Could not parse data source: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
t := c.Publish(config.Topic, 0, false, data)
|
||||||
|
t.Wait()
|
||||||
|
if t.Error() != nil {
|
||||||
|
log.Errorf("Could not publish data: %v", t.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOpts(config Config) *mqtt.ClientOptions {
|
||||||
|
opts := mqtt.NewClientOptions()
|
||||||
|
opts.AddBroker(config.Broker)
|
||||||
|
opts.SetClientID(config.ClientID)
|
||||||
|
|
||||||
|
if config.Username != "" {
|
||||||
|
opts.SetUsername(config.Username)
|
||||||
|
}
|
||||||
|
if config.Password != "" {
|
||||||
|
opts.SetPassword(config.Password)
|
||||||
|
}
|
||||||
|
opts.SetKeepAlive(keepAlive)
|
||||||
|
|
||||||
|
opts.SetOnConnectHandler(func(mqtt.Client) {
|
||||||
|
log.Info("Client connected to broker")
|
||||||
|
})
|
||||||
|
opts.SetConnectionLostHandler(func(cli mqtt.Client, err error) {
|
||||||
|
log.Errorf("Client connection to broker lost: %v", err)
|
||||||
|
|
||||||
|
})
|
||||||
|
return opts
|
||||||
|
}
|
||||||
218
plugins/munin/munin.go
Normal file
218
plugins/munin/munin.go
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2015, Hendrik van Wyk
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of invertergui nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package munin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = logrus.WithField("ctx", "inverter-gui-munin")
|
||||||
|
|
||||||
|
type Munin struct {
|
||||||
|
mk2driver.Mk2
|
||||||
|
muninResponse chan muninData
|
||||||
|
}
|
||||||
|
|
||||||
|
type muninData struct {
|
||||||
|
status mk2driver.Mk2Info
|
||||||
|
timesUpdated int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMunin(mk2 mk2driver.Mk2) *Munin {
|
||||||
|
m := &Munin{
|
||||||
|
Mk2: mk2,
|
||||||
|
muninResponse: make(chan muninData),
|
||||||
|
}
|
||||||
|
|
||||||
|
go m.run()
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Munin) ServeMuninHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
muninDat := <-m.muninResponse
|
||||||
|
if muninDat.timesUpdated == 0 {
|
||||||
|
log.Error("No data returned")
|
||||||
|
rw.WriteHeader(500)
|
||||||
|
_, _ = rw.Write([]byte("No data to return.\n"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
calcMuninAverages(&muninDat)
|
||||||
|
|
||||||
|
status := muninDat.status
|
||||||
|
tmpInput := buildTemplateInput(&status)
|
||||||
|
outputBuf := &bytes.Buffer{}
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_batvolt\n")
|
||||||
|
fmt.Fprintf(outputBuf, "volt.value %s\n", tmpInput.BatVoltage)
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_batcharge\n")
|
||||||
|
fmt.Fprintf(outputBuf, "charge.value %s\n", tmpInput.BatCharge)
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_batcurrent\n")
|
||||||
|
fmt.Fprintf(outputBuf, "current.value %s\n", tmpInput.BatCurrent)
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_batpower\n")
|
||||||
|
fmt.Fprintf(outputBuf, "power.value %s\n", tmpInput.BatPower)
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_mainscurrent\n")
|
||||||
|
fmt.Fprintf(outputBuf, "currentin.value %s\n", tmpInput.InCurrent)
|
||||||
|
fmt.Fprintf(outputBuf, "currentout.value %s\n", tmpInput.OutCurrent)
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_mainsvoltage\n")
|
||||||
|
fmt.Fprintf(outputBuf, "voltagein.value %s\n", tmpInput.InVoltage)
|
||||||
|
fmt.Fprintf(outputBuf, "voltageout.value %s\n", tmpInput.OutVoltage)
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_mainspower\n")
|
||||||
|
fmt.Fprintf(outputBuf, "powerin.value %s\n", tmpInput.InPower)
|
||||||
|
fmt.Fprintf(outputBuf, "powerout.value %s\n", tmpInput.OutPower)
|
||||||
|
fmt.Fprintf(outputBuf, "multigraph in_mainsfreq\n")
|
||||||
|
fmt.Fprintf(outputBuf, "freqin.value %s\n", tmpInput.InFreq)
|
||||||
|
fmt.Fprintf(outputBuf, "freqout.value %s\n", tmpInput.OutFreq)
|
||||||
|
|
||||||
|
_, err := rw.Write(outputBuf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Could not write data response: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Munin) ServeMuninConfigHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
output := muninConfig
|
||||||
|
_, err := rw.Write([]byte(output))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Could not write config response: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Munin) run() {
|
||||||
|
muninValues := &muninData{
|
||||||
|
status: mk2driver.Mk2Info{},
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case e := <-m.C():
|
||||||
|
if e.Valid {
|
||||||
|
calcMuninValues(muninValues, e)
|
||||||
|
}
|
||||||
|
case m.muninResponse <- *muninValues:
|
||||||
|
zeroMuninValues(muninValues)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Munin only samples once every 5 minutes so averages have to be calculated for some values.
|
||||||
|
func calcMuninValues(m *muninData, newStatus *mk2driver.Mk2Info) {
|
||||||
|
m.timesUpdated++
|
||||||
|
m.status.OutCurrent += newStatus.OutCurrent
|
||||||
|
m.status.InCurrent += newStatus.InCurrent
|
||||||
|
m.status.BatCurrent += newStatus.BatCurrent
|
||||||
|
|
||||||
|
m.status.OutVoltage += newStatus.OutVoltage
|
||||||
|
m.status.InVoltage += newStatus.InVoltage
|
||||||
|
m.status.BatVoltage += newStatus.BatVoltage
|
||||||
|
|
||||||
|
m.status.InFrequency = newStatus.InFrequency
|
||||||
|
m.status.OutFrequency = newStatus.OutFrequency
|
||||||
|
|
||||||
|
m.status.ChargeState = newStatus.ChargeState
|
||||||
|
}
|
||||||
|
|
||||||
|
func calcMuninAverages(m *muninData) {
|
||||||
|
m.status.OutCurrent /= float64(m.timesUpdated)
|
||||||
|
m.status.InCurrent /= float64(m.timesUpdated)
|
||||||
|
m.status.BatCurrent /= float64(m.timesUpdated)
|
||||||
|
|
||||||
|
m.status.OutVoltage /= float64(m.timesUpdated)
|
||||||
|
m.status.InVoltage /= float64(m.timesUpdated)
|
||||||
|
m.status.BatVoltage /= float64(m.timesUpdated)
|
||||||
|
}
|
||||||
|
|
||||||
|
func zeroMuninValues(m *muninData) {
|
||||||
|
m.timesUpdated = 0
|
||||||
|
m.status.OutCurrent = 0
|
||||||
|
m.status.InCurrent = 0
|
||||||
|
m.status.BatCurrent = 0
|
||||||
|
|
||||||
|
m.status.OutVoltage = 0
|
||||||
|
m.status.InVoltage = 0
|
||||||
|
m.status.BatVoltage = 0
|
||||||
|
|
||||||
|
m.status.InFrequency = 0
|
||||||
|
m.status.OutFrequency = 0
|
||||||
|
|
||||||
|
m.status.ChargeState = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type templateInput struct {
|
||||||
|
Date string `json:"date"`
|
||||||
|
|
||||||
|
OutCurrent string `json:"output_current"`
|
||||||
|
OutVoltage string `json:"output_voltage"`
|
||||||
|
OutPower string `json:"output_power"`
|
||||||
|
|
||||||
|
InCurrent string `json:"input_current"`
|
||||||
|
InVoltage string `json:"input_voltage"`
|
||||||
|
InPower string `json:"input_power"`
|
||||||
|
|
||||||
|
InMinOut string
|
||||||
|
|
||||||
|
BatVoltage string `json:"battery_voltage"`
|
||||||
|
BatCurrent string `json:"battery_current"`
|
||||||
|
BatPower string `json:"battery_power"`
|
||||||
|
BatCharge string `json:"battery_charge"`
|
||||||
|
|
||||||
|
InFreq string `json:"input_frequency"`
|
||||||
|
OutFreq string `json:"output_frequency"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildTemplateInput(status *mk2driver.Mk2Info) *templateInput {
|
||||||
|
outPower := status.OutVoltage * status.OutCurrent
|
||||||
|
inPower := status.InCurrent * status.InVoltage
|
||||||
|
|
||||||
|
newInput := &templateInput{
|
||||||
|
Date: status.Timestamp.Format(time.RFC1123Z),
|
||||||
|
OutCurrent: fmt.Sprintf("%.2f", status.OutCurrent),
|
||||||
|
OutVoltage: fmt.Sprintf("%.2f", status.OutVoltage),
|
||||||
|
OutPower: fmt.Sprintf("%.2f", outPower),
|
||||||
|
InCurrent: fmt.Sprintf("%.2f", status.InCurrent),
|
||||||
|
InVoltage: fmt.Sprintf("%.2f", status.InVoltage),
|
||||||
|
InFreq: fmt.Sprintf("%.2f", status.InFrequency),
|
||||||
|
OutFreq: fmt.Sprintf("%.2f", status.OutFrequency),
|
||||||
|
InPower: fmt.Sprintf("%.2f", inPower),
|
||||||
|
|
||||||
|
InMinOut: fmt.Sprintf("%.2f", inPower-outPower),
|
||||||
|
|
||||||
|
BatCurrent: fmt.Sprintf("%.2f", status.BatCurrent),
|
||||||
|
BatVoltage: fmt.Sprintf("%.2f", status.BatVoltage),
|
||||||
|
BatPower: fmt.Sprintf("%.2f", status.BatVoltage*status.BatCurrent),
|
||||||
|
BatCharge: fmt.Sprintf("%.2f", status.ChargeState*100),
|
||||||
|
}
|
||||||
|
return newInput
|
||||||
|
}
|
||||||
29
plugins/munin/munin_test.go
Normal file
29
plugins/munin/munin_test.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package munin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestServer(t *testing.T) {
|
||||||
|
|
||||||
|
mockMk2 := mk2driver.NewMk2Mock()
|
||||||
|
muninServer := NewMunin(mockMk2)
|
||||||
|
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(muninServer.ServeMuninHTTP))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
res, err := http.Get(ts.URL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = ioutil.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
82
plugins/munin/muninconfig.go
Normal file
82
plugins/munin/muninconfig.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package munin
|
||||||
|
|
||||||
|
const muninConfig = `multigraph in_batvolt
|
||||||
|
graph_title Battery Voltage
|
||||||
|
graph_vlabel Voltage (V)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Battery voltage
|
||||||
|
|
||||||
|
volt.info Voltage of battery
|
||||||
|
volt.label Voltage of battery (V)
|
||||||
|
|
||||||
|
multigraph in_batcharge
|
||||||
|
graph_title Battery Charge
|
||||||
|
graph_vlabel Charge (%)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Battery charge
|
||||||
|
|
||||||
|
charge.info Estimated charge of battery
|
||||||
|
charge.label Battery charge (%)
|
||||||
|
|
||||||
|
multigraph in_batcurrent
|
||||||
|
graph_title Battery Current
|
||||||
|
graph_vlabel Current (A)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Battery current
|
||||||
|
|
||||||
|
current.info Battery current
|
||||||
|
current.label Battery current (A)
|
||||||
|
|
||||||
|
multigraph in_batpower
|
||||||
|
graph_title Battery Power
|
||||||
|
graph_vlabel Power (W)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Battery power
|
||||||
|
|
||||||
|
power.info Battery power
|
||||||
|
power.label Battery power (W)
|
||||||
|
|
||||||
|
multigraph in_mainscurrent
|
||||||
|
graph_title Mains Current
|
||||||
|
graph_vlabel Current (A)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Mains current
|
||||||
|
|
||||||
|
currentin.info Input current
|
||||||
|
currentin.label Input current (A)
|
||||||
|
currentout.info Output current
|
||||||
|
currentout.label Output current (A)
|
||||||
|
|
||||||
|
multigraph in_mainsvoltage
|
||||||
|
graph_title Mains Voltage
|
||||||
|
graph_vlabel Voltage (V)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Mains voltage
|
||||||
|
|
||||||
|
voltagein.info Input voltage
|
||||||
|
voltagein.label Input voltage (V)
|
||||||
|
voltageout.info Output voltage
|
||||||
|
voltageout.label Output voltage (V)
|
||||||
|
|
||||||
|
multigraph in_mainspower
|
||||||
|
graph_title Mains Power
|
||||||
|
graph_vlabel Power (VA)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Mains power
|
||||||
|
|
||||||
|
powerin.info Input power
|
||||||
|
powerin.label Input power (VA)
|
||||||
|
powerout.info Output power
|
||||||
|
powerout.label Output power (VA)
|
||||||
|
|
||||||
|
multigraph in_mainsfreq
|
||||||
|
graph_title Mains frequency
|
||||||
|
graph_vlabel Frequency (Hz)
|
||||||
|
graph_category inverter
|
||||||
|
graph_info Mains frequency
|
||||||
|
|
||||||
|
freqin.info In frequency
|
||||||
|
freqin.label In frequency (Hz)
|
||||||
|
freqout.info Out frequency
|
||||||
|
freqout.label Out frequency (Hz)
|
||||||
|
`
|
||||||
@@ -28,14 +28,15 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package webgui
|
package prometheus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/diebietse/invertergui/mk2if"
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type prometheusUpdater struct {
|
type Prometheus struct {
|
||||||
|
mk2driver.Mk2
|
||||||
batteryVoltage prometheus.Gauge
|
batteryVoltage prometheus.Gauge
|
||||||
batteryCharge prometheus.Gauge
|
batteryCharge prometheus.Gauge
|
||||||
batteryCurrent prometheus.Gauge
|
batteryCurrent prometheus.Gauge
|
||||||
@@ -50,8 +51,9 @@ type prometheusUpdater struct {
|
|||||||
mainsFreqOut prometheus.Gauge
|
mainsFreqOut prometheus.Gauge
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPrometheusUpdater() *prometheusUpdater {
|
func NewPrometheus(mk2 mk2driver.Mk2) {
|
||||||
tmp := &prometheusUpdater{
|
tmp := &Prometheus{
|
||||||
|
Mk2: mk2,
|
||||||
batteryVoltage: prometheus.NewGauge(prometheus.GaugeOpts{
|
batteryVoltage: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "battery_voltage_v",
|
Name: "battery_voltage_v",
|
||||||
Help: "Voltage of the battery.",
|
Help: "Voltage of the battery.",
|
||||||
@@ -101,7 +103,8 @@ func newPrometheusUpdater() *prometheusUpdater {
|
|||||||
Help: "Mains frequency at inverter output",
|
Help: "Mains frequency at inverter output",
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
prometheus.MustRegister(tmp.batteryVoltage,
|
prometheus.MustRegister(
|
||||||
|
tmp.batteryVoltage,
|
||||||
tmp.batteryCharge,
|
tmp.batteryCharge,
|
||||||
tmp.batteryCurrent,
|
tmp.batteryCurrent,
|
||||||
tmp.batteryPower,
|
tmp.batteryPower,
|
||||||
@@ -114,21 +117,30 @@ func newPrometheusUpdater() *prometheusUpdater {
|
|||||||
tmp.mainsFreqIn,
|
tmp.mainsFreqIn,
|
||||||
tmp.mainsFreqOut,
|
tmp.mainsFreqOut,
|
||||||
)
|
)
|
||||||
return tmp
|
|
||||||
|
go tmp.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pu *prometheusUpdater) updatePrometheus(newStatus *mk2if.Mk2Info) {
|
func (p *Prometheus) run() {
|
||||||
s := newStatus
|
for e := range p.C() {
|
||||||
pu.batteryVoltage.Set(s.BatVoltage)
|
if e.Valid {
|
||||||
pu.batteryCharge.Set(newStatus.ChargeState * 100)
|
p.updatePrometheus(e)
|
||||||
pu.batteryCurrent.Set(s.BatCurrent)
|
}
|
||||||
pu.batteryPower.Set(s.BatVoltage * s.BatCurrent)
|
}
|
||||||
pu.mainsCurrentIn.Set(s.InCurrent)
|
}
|
||||||
pu.mainsCurrentOut.Set(s.OutCurrent)
|
|
||||||
pu.mainsVoltageIn.Set(s.InVoltage)
|
func (p *Prometheus) updatePrometheus(newStatus *mk2driver.Mk2Info) {
|
||||||
pu.mainsVoltageOut.Set(s.OutVoltage)
|
s := newStatus
|
||||||
pu.mainsPowerIn.Set(s.InVoltage * s.InCurrent)
|
p.batteryVoltage.Set(s.BatVoltage)
|
||||||
pu.mainsPowerOut.Set(s.OutVoltage * s.OutCurrent)
|
p.batteryCharge.Set(newStatus.ChargeState * 100)
|
||||||
pu.mainsFreqIn.Set(s.InFrequency)
|
p.batteryCurrent.Set(s.BatCurrent)
|
||||||
pu.mainsFreqOut.Set(s.OutFrequency)
|
p.batteryPower.Set(s.BatVoltage * s.BatCurrent)
|
||||||
|
p.mainsCurrentIn.Set(s.InCurrent)
|
||||||
|
p.mainsCurrentOut.Set(s.OutCurrent)
|
||||||
|
p.mainsVoltageIn.Set(s.InVoltage)
|
||||||
|
p.mainsVoltageOut.Set(s.OutVoltage)
|
||||||
|
p.mainsPowerIn.Set(s.InVoltage * s.InCurrent)
|
||||||
|
p.mainsPowerOut.Set(s.OutVoltage * s.OutCurrent)
|
||||||
|
p.mainsFreqIn.Set(s.InFrequency)
|
||||||
|
p.mainsFreqOut.Set(s.OutFrequency)
|
||||||
}
|
}
|
||||||
14
plugins/webui/static/binary.go
Normal file
14
plugins/webui/static/binary.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package static
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed css js index.html favicon.ico
|
||||||
|
var content embed.FS
|
||||||
|
|
||||||
|
// New exports the static part of the webgui that is served via embed
|
||||||
|
func New() http.Handler {
|
||||||
|
return http.FileServer(http.FS(content))
|
||||||
|
}
|
||||||
12
plugins/webui/static/css/bootstrap.min.css
vendored
Normal file
12
plugins/webui/static/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
6
plugins/webui/static/js/vue.js
Normal file
6
plugins/webui/static/js/vue.js
Normal file
File diff suppressed because one or more lines are too long
@@ -28,19 +28,21 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package webgui
|
package webui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2if"
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
"github.com/diebietse/invertergui/websocket"
|
"github.com/diebietse/invertergui/websocket"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = logrus.WithField("ctx", "inverter-gui-webgui")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LedOff = "dot-off"
|
LedOff = "dot-off"
|
||||||
LedRed = "dot-red"
|
LedRed = "dot-red"
|
||||||
@@ -50,24 +52,19 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WebGui struct {
|
type WebGui struct {
|
||||||
|
mk2driver.Mk2
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
|
|
||||||
muninRespChan chan muninData
|
wg sync.WaitGroup
|
||||||
poller mk2if.Mk2If
|
hub *websocket.Hub
|
||||||
wg sync.WaitGroup
|
|
||||||
hub *websocket.Hub
|
|
||||||
|
|
||||||
pu *prometheusUpdater
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebGui(source mk2if.Mk2If) *WebGui {
|
func NewWebGui(source mk2driver.Mk2) *WebGui {
|
||||||
w := new(WebGui)
|
w := &WebGui{
|
||||||
w.muninRespChan = make(chan muninData)
|
stopChan: make(chan struct{}),
|
||||||
w.stopChan = make(chan struct{})
|
Mk2: source,
|
||||||
w.poller = source
|
hub: websocket.NewHub(),
|
||||||
w.pu = newPrometheusUpdater()
|
}
|
||||||
w.hub = websocket.NewHub()
|
|
||||||
|
|
||||||
w.wg.Add(1)
|
w.wg.Add(1)
|
||||||
go w.dataPoll()
|
go w.dataPoll()
|
||||||
return w
|
return w
|
||||||
@@ -99,27 +96,19 @@ type templateInput struct {
|
|||||||
LedMap map[string]string `json:"led_map"`
|
LedMap map[string]string `json:"led_map"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebGui) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|
||||||
http.ServeFile(rw, r, "./frontend/index.html")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebGui) ServeJS(rw http.ResponseWriter, r *http.Request) {
|
|
||||||
http.ServeFile(rw, r, "./frontend/js/controller.js")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebGui) ServeHub(rw http.ResponseWriter, r *http.Request) {
|
func (w *WebGui) ServeHub(rw http.ResponseWriter, r *http.Request) {
|
||||||
w.hub.ServeHTTP(rw, r)
|
w.hub.ServeHTTP(rw, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ledName(led mk2if.Led) string {
|
func ledName(led mk2driver.Led) string {
|
||||||
name, ok := mk2if.LedNames[led]
|
name, ok := mk2driver.LedNames[led]
|
||||||
if !ok {
|
if !ok {
|
||||||
return "Unknown led"
|
return "Unknown led"
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildTemplateInput(status *mk2if.Mk2Info) *templateInput {
|
func buildTemplateInput(status *mk2driver.Mk2Info) *templateInput {
|
||||||
outPower := status.OutVoltage * status.OutCurrent
|
outPower := status.OutVoltage * status.OutCurrent
|
||||||
inPower := status.InCurrent * status.InVoltage
|
inPower := status.InCurrent * status.InVoltage
|
||||||
|
|
||||||
@@ -145,20 +134,20 @@ func buildTemplateInput(status *mk2if.Mk2Info) *templateInput {
|
|||||||
LedMap: map[string]string{},
|
LedMap: map[string]string{},
|
||||||
}
|
}
|
||||||
for k, v := range status.LEDs {
|
for k, v := range status.LEDs {
|
||||||
if k == mk2if.LedOverload || k == mk2if.LedTemperature || k == mk2if.LedLowBattery {
|
if k == mk2driver.LedOverload || k == mk2driver.LedTemperature || k == mk2driver.LedLowBattery {
|
||||||
switch v {
|
switch v {
|
||||||
case mk2if.LedOn:
|
case mk2driver.LedOn:
|
||||||
tmpInput.LedMap[ledName(k)] = LedRed
|
tmpInput.LedMap[ledName(k)] = LedRed
|
||||||
case mk2if.LedBlink:
|
case mk2driver.LedBlink:
|
||||||
tmpInput.LedMap[ledName(k)] = BlinkRed
|
tmpInput.LedMap[ledName(k)] = BlinkRed
|
||||||
default:
|
default:
|
||||||
tmpInput.LedMap[ledName(k)] = LedOff
|
tmpInput.LedMap[ledName(k)] = LedOff
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch v {
|
switch v {
|
||||||
case mk2if.LedOn:
|
case mk2driver.LedOn:
|
||||||
tmpInput.LedMap[ledName(k)] = LedGreen
|
tmpInput.LedMap[ledName(k)] = LedGreen
|
||||||
case mk2if.LedBlink:
|
case mk2driver.LedBlink:
|
||||||
tmpInput.LedMap[ledName(k)] = BlinkGreen
|
tmpInput.LedMap[ledName(k)] = BlinkGreen
|
||||||
default:
|
default:
|
||||||
tmpInput.LedMap[ledName(k)] = LedOff
|
tmpInput.LedMap[ledName(k)] = LedOff
|
||||||
@@ -176,21 +165,15 @@ func (w *WebGui) Stop() {
|
|||||||
// dataPoll waits for data from the w.poller channel. It will send its currently stored status
|
// dataPoll waits for data from the w.poller channel. It will send its currently stored status
|
||||||
// to respChan if anything reads from it.
|
// to respChan if anything reads from it.
|
||||||
func (w *WebGui) dataPoll() {
|
func (w *WebGui) dataPoll() {
|
||||||
pollChan := w.poller.C()
|
|
||||||
var muninValues muninData
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case s := <-pollChan:
|
case s := <-w.C():
|
||||||
if s.Valid {
|
if s.Valid {
|
||||||
calcMuninValues(&muninValues, s)
|
|
||||||
w.pu.updatePrometheus(s)
|
|
||||||
err := w.hub.Broadcast(buildTemplateInput(s))
|
err := w.hub.Broadcast(buildTemplateInput(s))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Could not send update to clients: %v", err)
|
log.Errorf("Could not send update to clients: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case w.muninRespChan <- muninValues:
|
|
||||||
zeroMuninValues(&muninValues)
|
|
||||||
case <-w.stopChan:
|
case <-w.stopChan:
|
||||||
w.wg.Done()
|
w.wg.Done()
|
||||||
return
|
return
|
||||||
@@ -28,7 +28,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package webgui
|
package webui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -36,23 +36,18 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/diebietse/invertergui/mk2if"
|
"github.com/diebietse/invertergui/mk2driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWebGui(t *testing.T) {
|
|
||||||
t.Skip("Not yet implimented")
|
|
||||||
//TODO figure out how to test template output.
|
|
||||||
}
|
|
||||||
|
|
||||||
type templateTest struct {
|
type templateTest struct {
|
||||||
input *mk2if.Mk2Info
|
input *mk2driver.Mk2Info
|
||||||
output *templateInput
|
output *templateInput
|
||||||
}
|
}
|
||||||
|
|
||||||
var fakenow = time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC)
|
var fakenow = time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC)
|
||||||
var templateInputTests = []templateTest{
|
var templateInputTests = []templateTest{
|
||||||
{
|
{
|
||||||
input: &mk2if.Mk2Info{
|
input: &mk2driver.Mk2Info{
|
||||||
OutCurrent: 2.0,
|
OutCurrent: 2.0,
|
||||||
InCurrent: 2.3,
|
InCurrent: 2.3,
|
||||||
OutVoltage: 230.0,
|
OutVoltage: 230.0,
|
||||||
@@ -62,7 +57,7 @@ var templateInputTests = []templateTest{
|
|||||||
InFrequency: 50,
|
InFrequency: 50,
|
||||||
OutFrequency: 50,
|
OutFrequency: 50,
|
||||||
ChargeState: 1,
|
ChargeState: 1,
|
||||||
LEDs: map[mk2if.Led]mk2if.LEDstate{mk2if.LedMain: mk2if.LedOn},
|
LEDs: map[mk2driver.Led]mk2driver.LEDstate{mk2driver.LedMain: mk2driver.LedOn},
|
||||||
Errors: nil,
|
Errors: nil,
|
||||||
Timestamp: fakenow,
|
Timestamp: fakenow,
|
||||||
},
|
},
|
||||||
20
vendor/github.com/beorn7/perks/LICENSE
generated
vendored
Normal file
20
vendor/github.com/beorn7/perks/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
Copyright (C) 2013 Blake Mizerany
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
2388
vendor/github.com/beorn7/perks/quantile/exampledata.txt
generated
vendored
Normal file
2388
vendor/github.com/beorn7/perks/quantile/exampledata.txt
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
316
vendor/github.com/beorn7/perks/quantile/stream.go
generated
vendored
Normal file
316
vendor/github.com/beorn7/perks/quantile/stream.go
generated
vendored
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
// Package quantile computes approximate quantiles over an unbounded data
|
||||||
|
// stream within low memory and CPU bounds.
|
||||||
|
//
|
||||||
|
// A small amount of accuracy is traded to achieve the above properties.
|
||||||
|
//
|
||||||
|
// Multiple streams can be merged before calling Query to generate a single set
|
||||||
|
// of results. This is meaningful when the streams represent the same type of
|
||||||
|
// data. See Merge and Samples.
|
||||||
|
//
|
||||||
|
// For more detailed information about the algorithm used, see:
|
||||||
|
//
|
||||||
|
// Effective Computation of Biased Quantiles over Data Streams
|
||||||
|
//
|
||||||
|
// http://www.cs.rutgers.edu/~muthu/bquant.pdf
|
||||||
|
package quantile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sample holds an observed value and meta information for compression. JSON
|
||||||
|
// tags have been added for convenience.
|
||||||
|
type Sample struct {
|
||||||
|
Value float64 `json:",string"`
|
||||||
|
Width float64 `json:",string"`
|
||||||
|
Delta float64 `json:",string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Samples represents a slice of samples. It implements sort.Interface.
|
||||||
|
type Samples []Sample
|
||||||
|
|
||||||
|
func (a Samples) Len() int { return len(a) }
|
||||||
|
func (a Samples) Less(i, j int) bool { return a[i].Value < a[j].Value }
|
||||||
|
func (a Samples) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
|
||||||
|
type invariant func(s *stream, r float64) float64
|
||||||
|
|
||||||
|
// NewLowBiased returns an initialized Stream for low-biased quantiles
|
||||||
|
// (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but
|
||||||
|
// error guarantees can still be given even for the lower ranks of the data
|
||||||
|
// distribution.
|
||||||
|
//
|
||||||
|
// The provided epsilon is a relative error, i.e. the true quantile of a value
|
||||||
|
// returned by a query is guaranteed to be within (1±Epsilon)*Quantile.
|
||||||
|
//
|
||||||
|
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error
|
||||||
|
// properties.
|
||||||
|
func NewLowBiased(epsilon float64) *Stream {
|
||||||
|
ƒ := func(s *stream, r float64) float64 {
|
||||||
|
return 2 * epsilon * r
|
||||||
|
}
|
||||||
|
return newStream(ƒ)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHighBiased returns an initialized Stream for high-biased quantiles
|
||||||
|
// (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but
|
||||||
|
// error guarantees can still be given even for the higher ranks of the data
|
||||||
|
// distribution.
|
||||||
|
//
|
||||||
|
// The provided epsilon is a relative error, i.e. the true quantile of a value
|
||||||
|
// returned by a query is guaranteed to be within 1-(1±Epsilon)*(1-Quantile).
|
||||||
|
//
|
||||||
|
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error
|
||||||
|
// properties.
|
||||||
|
func NewHighBiased(epsilon float64) *Stream {
|
||||||
|
ƒ := func(s *stream, r float64) float64 {
|
||||||
|
return 2 * epsilon * (s.n - r)
|
||||||
|
}
|
||||||
|
return newStream(ƒ)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTargeted returns an initialized Stream concerned with a particular set of
|
||||||
|
// quantile values that are supplied a priori. Knowing these a priori reduces
|
||||||
|
// space and computation time. The targets map maps the desired quantiles to
|
||||||
|
// their absolute errors, i.e. the true quantile of a value returned by a query
|
||||||
|
// is guaranteed to be within (Quantile±Epsilon).
|
||||||
|
//
|
||||||
|
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
|
||||||
|
func NewTargeted(targetMap map[float64]float64) *Stream {
|
||||||
|
// Convert map to slice to avoid slow iterations on a map.
|
||||||
|
// ƒ is called on the hot path, so converting the map to a slice
|
||||||
|
// beforehand results in significant CPU savings.
|
||||||
|
targets := targetMapToSlice(targetMap)
|
||||||
|
|
||||||
|
ƒ := func(s *stream, r float64) float64 {
|
||||||
|
var m = math.MaxFloat64
|
||||||
|
var f float64
|
||||||
|
for _, t := range targets {
|
||||||
|
if t.quantile*s.n <= r {
|
||||||
|
f = (2 * t.epsilon * r) / t.quantile
|
||||||
|
} else {
|
||||||
|
f = (2 * t.epsilon * (s.n - r)) / (1 - t.quantile)
|
||||||
|
}
|
||||||
|
if f < m {
|
||||||
|
m = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
return newStream(ƒ)
|
||||||
|
}
|
||||||
|
|
||||||
|
type target struct {
|
||||||
|
quantile float64
|
||||||
|
epsilon float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func targetMapToSlice(targetMap map[float64]float64) []target {
|
||||||
|
targets := make([]target, 0, len(targetMap))
|
||||||
|
|
||||||
|
for quantile, epsilon := range targetMap {
|
||||||
|
t := target{
|
||||||
|
quantile: quantile,
|
||||||
|
epsilon: epsilon,
|
||||||
|
}
|
||||||
|
targets = append(targets, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
return targets
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream computes quantiles for a stream of float64s. It is not thread-safe by
|
||||||
|
// design. Take care when using across multiple goroutines.
|
||||||
|
type Stream struct {
|
||||||
|
*stream
|
||||||
|
b Samples
|
||||||
|
sorted bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newStream(ƒ invariant) *Stream {
|
||||||
|
x := &stream{ƒ: ƒ}
|
||||||
|
return &Stream{x, make(Samples, 0, 500), true}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert inserts v into the stream.
|
||||||
|
func (s *Stream) Insert(v float64) {
|
||||||
|
s.insert(Sample{Value: v, Width: 1})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stream) insert(sample Sample) {
|
||||||
|
s.b = append(s.b, sample)
|
||||||
|
s.sorted = false
|
||||||
|
if len(s.b) == cap(s.b) {
|
||||||
|
s.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns the computed qth percentiles value. If s was created with
|
||||||
|
// NewTargeted, and q is not in the set of quantiles provided a priori, Query
|
||||||
|
// will return an unspecified result.
|
||||||
|
func (s *Stream) Query(q float64) float64 {
|
||||||
|
if !s.flushed() {
|
||||||
|
// Fast path when there hasn't been enough data for a flush;
|
||||||
|
// this also yields better accuracy for small sets of data.
|
||||||
|
l := len(s.b)
|
||||||
|
if l == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
i := int(math.Ceil(float64(l) * q))
|
||||||
|
if i > 0 {
|
||||||
|
i -= 1
|
||||||
|
}
|
||||||
|
s.maybeSort()
|
||||||
|
return s.b[i].Value
|
||||||
|
}
|
||||||
|
s.flush()
|
||||||
|
return s.stream.query(q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge merges samples into the underlying streams samples. This is handy when
|
||||||
|
// merging multiple streams from separate threads, database shards, etc.
|
||||||
|
//
|
||||||
|
// ATTENTION: This method is broken and does not yield correct results. The
|
||||||
|
// underlying algorithm is not capable of merging streams correctly.
|
||||||
|
func (s *Stream) Merge(samples Samples) {
|
||||||
|
sort.Sort(samples)
|
||||||
|
s.stream.merge(samples)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset reinitializes and clears the list reusing the samples buffer memory.
|
||||||
|
func (s *Stream) Reset() {
|
||||||
|
s.stream.reset()
|
||||||
|
s.b = s.b[:0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Samples returns stream samples held by s.
|
||||||
|
func (s *Stream) Samples() Samples {
|
||||||
|
if !s.flushed() {
|
||||||
|
return s.b
|
||||||
|
}
|
||||||
|
s.flush()
|
||||||
|
return s.stream.samples()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the total number of samples observed in the stream
|
||||||
|
// since initialization.
|
||||||
|
func (s *Stream) Count() int {
|
||||||
|
return len(s.b) + s.stream.count()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stream) flush() {
|
||||||
|
s.maybeSort()
|
||||||
|
s.stream.merge(s.b)
|
||||||
|
s.b = s.b[:0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stream) maybeSort() {
|
||||||
|
if !s.sorted {
|
||||||
|
s.sorted = true
|
||||||
|
sort.Sort(s.b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stream) flushed() bool {
|
||||||
|
return len(s.stream.l) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type stream struct {
|
||||||
|
n float64
|
||||||
|
l []Sample
|
||||||
|
ƒ invariant
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stream) reset() {
|
||||||
|
s.l = s.l[:0]
|
||||||
|
s.n = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stream) insert(v float64) {
|
||||||
|
s.merge(Samples{{v, 1, 0}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stream) merge(samples Samples) {
|
||||||
|
// TODO(beorn7): This tries to merge not only individual samples, but
|
||||||
|
// whole summaries. The paper doesn't mention merging summaries at
|
||||||
|
// all. Unittests show that the merging is inaccurate. Find out how to
|
||||||
|
// do merges properly.
|
||||||
|
var r float64
|
||||||
|
i := 0
|
||||||
|
for _, sample := range samples {
|
||||||
|
for ; i < len(s.l); i++ {
|
||||||
|
c := s.l[i]
|
||||||
|
if c.Value > sample.Value {
|
||||||
|
// Insert at position i.
|
||||||
|
s.l = append(s.l, Sample{})
|
||||||
|
copy(s.l[i+1:], s.l[i:])
|
||||||
|
s.l[i] = Sample{
|
||||||
|
sample.Value,
|
||||||
|
sample.Width,
|
||||||
|
math.Max(sample.Delta, math.Floor(s.ƒ(s, r))-1),
|
||||||
|
// TODO(beorn7): How to calculate delta correctly?
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
goto inserted
|
||||||
|
}
|
||||||
|
r += c.Width
|
||||||
|
}
|
||||||
|
s.l = append(s.l, Sample{sample.Value, sample.Width, 0})
|
||||||
|
i++
|
||||||
|
inserted:
|
||||||
|
s.n += sample.Width
|
||||||
|
r += sample.Width
|
||||||
|
}
|
||||||
|
s.compress()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stream) count() int {
|
||||||
|
return int(s.n)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stream) query(q float64) float64 {
|
||||||
|
t := math.Ceil(q * s.n)
|
||||||
|
t += math.Ceil(s.ƒ(s, t) / 2)
|
||||||
|
p := s.l[0]
|
||||||
|
var r float64
|
||||||
|
for _, c := range s.l[1:] {
|
||||||
|
r += p.Width
|
||||||
|
if r+c.Width+c.Delta > t {
|
||||||
|
return p.Value
|
||||||
|
}
|
||||||
|
p = c
|
||||||
|
}
|
||||||
|
return p.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stream) compress() {
|
||||||
|
if len(s.l) < 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
x := s.l[len(s.l)-1]
|
||||||
|
xi := len(s.l) - 1
|
||||||
|
r := s.n - 1 - x.Width
|
||||||
|
|
||||||
|
for i := len(s.l) - 2; i >= 0; i-- {
|
||||||
|
c := s.l[i]
|
||||||
|
if c.Width+x.Width+x.Delta <= s.ƒ(s, r) {
|
||||||
|
x.Width += c.Width
|
||||||
|
s.l[xi] = x
|
||||||
|
// Remove element at i.
|
||||||
|
copy(s.l[i:], s.l[i+1:])
|
||||||
|
s.l = s.l[:len(s.l)-1]
|
||||||
|
xi -= 1
|
||||||
|
} else {
|
||||||
|
x = c
|
||||||
|
xi = i
|
||||||
|
}
|
||||||
|
r -= c.Width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stream) samples() Samples {
|
||||||
|
samples := make(Samples, len(s.l))
|
||||||
|
copy(samples, s.l)
|
||||||
|
return samples
|
||||||
|
}
|
||||||
8
vendor/github.com/cespare/xxhash/v2/.travis.yml
generated
vendored
Normal file
8
vendor/github.com/cespare/xxhash/v2/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
language: go
|
||||||
|
go:
|
||||||
|
- "1.x"
|
||||||
|
- master
|
||||||
|
env:
|
||||||
|
- TAGS=""
|
||||||
|
- TAGS="-tags purego"
|
||||||
|
script: go test $TAGS -v ./...
|
||||||
22
vendor/github.com/cespare/xxhash/v2/LICENSE.txt
generated
vendored
Normal file
22
vendor/github.com/cespare/xxhash/v2/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
Copyright (c) 2016 Caleb Spare
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
67
vendor/github.com/cespare/xxhash/v2/README.md
generated
vendored
Normal file
67
vendor/github.com/cespare/xxhash/v2/README.md
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# xxhash
|
||||||
|
|
||||||
|
[](https://godoc.org/github.com/cespare/xxhash)
|
||||||
|
[](https://travis-ci.org/cespare/xxhash)
|
||||||
|
|
||||||
|
xxhash is a Go implementation of the 64-bit
|
||||||
|
[xxHash](http://cyan4973.github.io/xxHash/) algorithm, XXH64. This is a
|
||||||
|
high-quality hashing algorithm that is much faster than anything in the Go
|
||||||
|
standard library.
|
||||||
|
|
||||||
|
This package provides a straightforward API:
|
||||||
|
|
||||||
|
```
|
||||||
|
func Sum64(b []byte) uint64
|
||||||
|
func Sum64String(s string) uint64
|
||||||
|
type Digest struct{ ... }
|
||||||
|
func New() *Digest
|
||||||
|
```
|
||||||
|
|
||||||
|
The `Digest` type implements hash.Hash64. Its key methods are:
|
||||||
|
|
||||||
|
```
|
||||||
|
func (*Digest) Write([]byte) (int, error)
|
||||||
|
func (*Digest) WriteString(string) (int, error)
|
||||||
|
func (*Digest) Sum64() uint64
|
||||||
|
```
|
||||||
|
|
||||||
|
This implementation provides a fast pure-Go implementation and an even faster
|
||||||
|
assembly implementation for amd64.
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
This package is in a module and the latest code is in version 2 of the module.
|
||||||
|
You need a version of Go with at least "minimal module compatibility" to use
|
||||||
|
github.com/cespare/xxhash/v2:
|
||||||
|
|
||||||
|
* 1.9.7+ for Go 1.9
|
||||||
|
* 1.10.3+ for Go 1.10
|
||||||
|
* Go 1.11 or later
|
||||||
|
|
||||||
|
I recommend using the latest release of Go.
|
||||||
|
|
||||||
|
## Benchmarks
|
||||||
|
|
||||||
|
Here are some quick benchmarks comparing the pure-Go and assembly
|
||||||
|
implementations of Sum64.
|
||||||
|
|
||||||
|
| input size | purego | asm |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 5 B | 979.66 MB/s | 1291.17 MB/s |
|
||||||
|
| 100 B | 7475.26 MB/s | 7973.40 MB/s |
|
||||||
|
| 4 KB | 17573.46 MB/s | 17602.65 MB/s |
|
||||||
|
| 10 MB | 17131.46 MB/s | 17142.16 MB/s |
|
||||||
|
|
||||||
|
These numbers were generated on Ubuntu 18.04 with an Intel i7-8700K CPU using
|
||||||
|
the following commands under Go 1.11.2:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go test -tags purego -benchtime 10s -bench '/xxhash,direct,bytes'
|
||||||
|
$ go test -benchtime 10s -bench '/xxhash,direct,bytes'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Projects using this package
|
||||||
|
|
||||||
|
- [InfluxDB](https://github.com/influxdata/influxdb)
|
||||||
|
- [Prometheus](https://github.com/prometheus/prometheus)
|
||||||
|
- [FreeCache](https://github.com/coocood/freecache)
|
||||||
3
vendor/github.com/cespare/xxhash/v2/go.mod
generated
vendored
Normal file
3
vendor/github.com/cespare/xxhash/v2/go.mod
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module github.com/cespare/xxhash/v2
|
||||||
|
|
||||||
|
go 1.11
|
||||||
0
vendor/github.com/cespare/xxhash/v2/go.sum
generated
vendored
Normal file
0
vendor/github.com/cespare/xxhash/v2/go.sum
generated
vendored
Normal file
236
vendor/github.com/cespare/xxhash/v2/xxhash.go
generated
vendored
Normal file
236
vendor/github.com/cespare/xxhash/v2/xxhash.go
generated
vendored
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
// Package xxhash implements the 64-bit variant of xxHash (XXH64) as described
|
||||||
|
// at http://cyan4973.github.io/xxHash/.
|
||||||
|
package xxhash
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
"math/bits"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
prime1 uint64 = 11400714785074694791
|
||||||
|
prime2 uint64 = 14029467366897019727
|
||||||
|
prime3 uint64 = 1609587929392839161
|
||||||
|
prime4 uint64 = 9650029242287828579
|
||||||
|
prime5 uint64 = 2870177450012600261
|
||||||
|
)
|
||||||
|
|
||||||
|
// NOTE(caleb): I'm using both consts and vars of the primes. Using consts where
|
||||||
|
// possible in the Go code is worth a small (but measurable) performance boost
|
||||||
|
// by avoiding some MOVQs. Vars are needed for the asm and also are useful for
|
||||||
|
// convenience in the Go code in a few places where we need to intentionally
|
||||||
|
// avoid constant arithmetic (e.g., v1 := prime1 + prime2 fails because the
|
||||||
|
// result overflows a uint64).
|
||||||
|
var (
|
||||||
|
prime1v = prime1
|
||||||
|
prime2v = prime2
|
||||||
|
prime3v = prime3
|
||||||
|
prime4v = prime4
|
||||||
|
prime5v = prime5
|
||||||
|
)
|
||||||
|
|
||||||
|
// Digest implements hash.Hash64.
|
||||||
|
type Digest struct {
|
||||||
|
v1 uint64
|
||||||
|
v2 uint64
|
||||||
|
v3 uint64
|
||||||
|
v4 uint64
|
||||||
|
total uint64
|
||||||
|
mem [32]byte
|
||||||
|
n int // how much of mem is used
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new Digest that computes the 64-bit xxHash algorithm.
|
||||||
|
func New() *Digest {
|
||||||
|
var d Digest
|
||||||
|
d.Reset()
|
||||||
|
return &d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset clears the Digest's state so that it can be reused.
|
||||||
|
func (d *Digest) Reset() {
|
||||||
|
d.v1 = prime1v + prime2
|
||||||
|
d.v2 = prime2
|
||||||
|
d.v3 = 0
|
||||||
|
d.v4 = -prime1v
|
||||||
|
d.total = 0
|
||||||
|
d.n = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size always returns 8 bytes.
|
||||||
|
func (d *Digest) Size() int { return 8 }
|
||||||
|
|
||||||
|
// BlockSize always returns 32 bytes.
|
||||||
|
func (d *Digest) BlockSize() int { return 32 }
|
||||||
|
|
||||||
|
// Write adds more data to d. It always returns len(b), nil.
|
||||||
|
func (d *Digest) Write(b []byte) (n int, err error) {
|
||||||
|
n = len(b)
|
||||||
|
d.total += uint64(n)
|
||||||
|
|
||||||
|
if d.n+n < 32 {
|
||||||
|
// This new data doesn't even fill the current block.
|
||||||
|
copy(d.mem[d.n:], b)
|
||||||
|
d.n += n
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.n > 0 {
|
||||||
|
// Finish off the partial block.
|
||||||
|
copy(d.mem[d.n:], b)
|
||||||
|
d.v1 = round(d.v1, u64(d.mem[0:8]))
|
||||||
|
d.v2 = round(d.v2, u64(d.mem[8:16]))
|
||||||
|
d.v3 = round(d.v3, u64(d.mem[16:24]))
|
||||||
|
d.v4 = round(d.v4, u64(d.mem[24:32]))
|
||||||
|
b = b[32-d.n:]
|
||||||
|
d.n = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b) >= 32 {
|
||||||
|
// One or more full blocks left.
|
||||||
|
nw := writeBlocks(d, b)
|
||||||
|
b = b[nw:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store any remaining partial block.
|
||||||
|
copy(d.mem[:], b)
|
||||||
|
d.n = len(b)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum appends the current hash to b and returns the resulting slice.
|
||||||
|
func (d *Digest) Sum(b []byte) []byte {
|
||||||
|
s := d.Sum64()
|
||||||
|
return append(
|
||||||
|
b,
|
||||||
|
byte(s>>56),
|
||||||
|
byte(s>>48),
|
||||||
|
byte(s>>40),
|
||||||
|
byte(s>>32),
|
||||||
|
byte(s>>24),
|
||||||
|
byte(s>>16),
|
||||||
|
byte(s>>8),
|
||||||
|
byte(s),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum64 returns the current hash.
|
||||||
|
func (d *Digest) Sum64() uint64 {
|
||||||
|
var h uint64
|
||||||
|
|
||||||
|
if d.total >= 32 {
|
||||||
|
v1, v2, v3, v4 := d.v1, d.v2, d.v3, d.v4
|
||||||
|
h = rol1(v1) + rol7(v2) + rol12(v3) + rol18(v4)
|
||||||
|
h = mergeRound(h, v1)
|
||||||
|
h = mergeRound(h, v2)
|
||||||
|
h = mergeRound(h, v3)
|
||||||
|
h = mergeRound(h, v4)
|
||||||
|
} else {
|
||||||
|
h = d.v3 + prime5
|
||||||
|
}
|
||||||
|
|
||||||
|
h += d.total
|
||||||
|
|
||||||
|
i, end := 0, d.n
|
||||||
|
for ; i+8 <= end; i += 8 {
|
||||||
|
k1 := round(0, u64(d.mem[i:i+8]))
|
||||||
|
h ^= k1
|
||||||
|
h = rol27(h)*prime1 + prime4
|
||||||
|
}
|
||||||
|
if i+4 <= end {
|
||||||
|
h ^= uint64(u32(d.mem[i:i+4])) * prime1
|
||||||
|
h = rol23(h)*prime2 + prime3
|
||||||
|
i += 4
|
||||||
|
}
|
||||||
|
for i < end {
|
||||||
|
h ^= uint64(d.mem[i]) * prime5
|
||||||
|
h = rol11(h) * prime1
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
h ^= h >> 33
|
||||||
|
h *= prime2
|
||||||
|
h ^= h >> 29
|
||||||
|
h *= prime3
|
||||||
|
h ^= h >> 32
|
||||||
|
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
magic = "xxh\x06"
|
||||||
|
marshaledSize = len(magic) + 8*5 + 32
|
||||||
|
)
|
||||||
|
|
||||||
|
// MarshalBinary implements the encoding.BinaryMarshaler interface.
|
||||||
|
func (d *Digest) MarshalBinary() ([]byte, error) {
|
||||||
|
b := make([]byte, 0, marshaledSize)
|
||||||
|
b = append(b, magic...)
|
||||||
|
b = appendUint64(b, d.v1)
|
||||||
|
b = appendUint64(b, d.v2)
|
||||||
|
b = appendUint64(b, d.v3)
|
||||||
|
b = appendUint64(b, d.v4)
|
||||||
|
b = appendUint64(b, d.total)
|
||||||
|
b = append(b, d.mem[:d.n]...)
|
||||||
|
b = b[:len(b)+len(d.mem)-d.n]
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
|
||||||
|
func (d *Digest) UnmarshalBinary(b []byte) error {
|
||||||
|
if len(b) < len(magic) || string(b[:len(magic)]) != magic {
|
||||||
|
return errors.New("xxhash: invalid hash state identifier")
|
||||||
|
}
|
||||||
|
if len(b) != marshaledSize {
|
||||||
|
return errors.New("xxhash: invalid hash state size")
|
||||||
|
}
|
||||||
|
b = b[len(magic):]
|
||||||
|
b, d.v1 = consumeUint64(b)
|
||||||
|
b, d.v2 = consumeUint64(b)
|
||||||
|
b, d.v3 = consumeUint64(b)
|
||||||
|
b, d.v4 = consumeUint64(b)
|
||||||
|
b, d.total = consumeUint64(b)
|
||||||
|
copy(d.mem[:], b)
|
||||||
|
b = b[len(d.mem):]
|
||||||
|
d.n = int(d.total % uint64(len(d.mem)))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendUint64(b []byte, x uint64) []byte {
|
||||||
|
var a [8]byte
|
||||||
|
binary.LittleEndian.PutUint64(a[:], x)
|
||||||
|
return append(b, a[:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func consumeUint64(b []byte) ([]byte, uint64) {
|
||||||
|
x := u64(b)
|
||||||
|
return b[8:], x
|
||||||
|
}
|
||||||
|
|
||||||
|
func u64(b []byte) uint64 { return binary.LittleEndian.Uint64(b) }
|
||||||
|
func u32(b []byte) uint32 { return binary.LittleEndian.Uint32(b) }
|
||||||
|
|
||||||
|
func round(acc, input uint64) uint64 {
|
||||||
|
acc += input * prime2
|
||||||
|
acc = rol31(acc)
|
||||||
|
acc *= prime1
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
|
||||||
|
func mergeRound(acc, val uint64) uint64 {
|
||||||
|
val = round(0, val)
|
||||||
|
acc ^= val
|
||||||
|
acc = acc*prime1 + prime4
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
|
||||||
|
func rol1(x uint64) uint64 { return bits.RotateLeft64(x, 1) }
|
||||||
|
func rol7(x uint64) uint64 { return bits.RotateLeft64(x, 7) }
|
||||||
|
func rol11(x uint64) uint64 { return bits.RotateLeft64(x, 11) }
|
||||||
|
func rol12(x uint64) uint64 { return bits.RotateLeft64(x, 12) }
|
||||||
|
func rol18(x uint64) uint64 { return bits.RotateLeft64(x, 18) }
|
||||||
|
func rol23(x uint64) uint64 { return bits.RotateLeft64(x, 23) }
|
||||||
|
func rol27(x uint64) uint64 { return bits.RotateLeft64(x, 27) }
|
||||||
|
func rol31(x uint64) uint64 { return bits.RotateLeft64(x, 31) }
|
||||||
13
vendor/github.com/cespare/xxhash/v2/xxhash_amd64.go
generated
vendored
Normal file
13
vendor/github.com/cespare/xxhash/v2/xxhash_amd64.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// +build !appengine
|
||||||
|
// +build gc
|
||||||
|
// +build !purego
|
||||||
|
|
||||||
|
package xxhash
|
||||||
|
|
||||||
|
// Sum64 computes the 64-bit xxHash digest of b.
|
||||||
|
//
|
||||||
|
//go:noescape
|
||||||
|
func Sum64(b []byte) uint64
|
||||||
|
|
||||||
|
//go:noescape
|
||||||
|
func writeBlocks(d *Digest, b []byte) int
|
||||||
215
vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s
generated
vendored
Normal file
215
vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
// +build !appengine
|
||||||
|
// +build gc
|
||||||
|
// +build !purego
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// Register allocation:
|
||||||
|
// AX h
|
||||||
|
// CX pointer to advance through b
|
||||||
|
// DX n
|
||||||
|
// BX loop end
|
||||||
|
// R8 v1, k1
|
||||||
|
// R9 v2
|
||||||
|
// R10 v3
|
||||||
|
// R11 v4
|
||||||
|
// R12 tmp
|
||||||
|
// R13 prime1v
|
||||||
|
// R14 prime2v
|
||||||
|
// R15 prime4v
|
||||||
|
|
||||||
|
// round reads from and advances the buffer pointer in CX.
|
||||||
|
// It assumes that R13 has prime1v and R14 has prime2v.
|
||||||
|
#define round(r) \
|
||||||
|
MOVQ (CX), R12 \
|
||||||
|
ADDQ $8, CX \
|
||||||
|
IMULQ R14, R12 \
|
||||||
|
ADDQ R12, r \
|
||||||
|
ROLQ $31, r \
|
||||||
|
IMULQ R13, r
|
||||||
|
|
||||||
|
// mergeRound applies a merge round on the two registers acc and val.
|
||||||
|
// It assumes that R13 has prime1v, R14 has prime2v, and R15 has prime4v.
|
||||||
|
#define mergeRound(acc, val) \
|
||||||
|
IMULQ R14, val \
|
||||||
|
ROLQ $31, val \
|
||||||
|
IMULQ R13, val \
|
||||||
|
XORQ val, acc \
|
||||||
|
IMULQ R13, acc \
|
||||||
|
ADDQ R15, acc
|
||||||
|
|
||||||
|
// func Sum64(b []byte) uint64
|
||||||
|
TEXT ·Sum64(SB), NOSPLIT, $0-32
|
||||||
|
// Load fixed primes.
|
||||||
|
MOVQ ·prime1v(SB), R13
|
||||||
|
MOVQ ·prime2v(SB), R14
|
||||||
|
MOVQ ·prime4v(SB), R15
|
||||||
|
|
||||||
|
// Load slice.
|
||||||
|
MOVQ b_base+0(FP), CX
|
||||||
|
MOVQ b_len+8(FP), DX
|
||||||
|
LEAQ (CX)(DX*1), BX
|
||||||
|
|
||||||
|
// The first loop limit will be len(b)-32.
|
||||||
|
SUBQ $32, BX
|
||||||
|
|
||||||
|
// Check whether we have at least one block.
|
||||||
|
CMPQ DX, $32
|
||||||
|
JLT noBlocks
|
||||||
|
|
||||||
|
// Set up initial state (v1, v2, v3, v4).
|
||||||
|
MOVQ R13, R8
|
||||||
|
ADDQ R14, R8
|
||||||
|
MOVQ R14, R9
|
||||||
|
XORQ R10, R10
|
||||||
|
XORQ R11, R11
|
||||||
|
SUBQ R13, R11
|
||||||
|
|
||||||
|
// Loop until CX > BX.
|
||||||
|
blockLoop:
|
||||||
|
round(R8)
|
||||||
|
round(R9)
|
||||||
|
round(R10)
|
||||||
|
round(R11)
|
||||||
|
|
||||||
|
CMPQ CX, BX
|
||||||
|
JLE blockLoop
|
||||||
|
|
||||||
|
MOVQ R8, AX
|
||||||
|
ROLQ $1, AX
|
||||||
|
MOVQ R9, R12
|
||||||
|
ROLQ $7, R12
|
||||||
|
ADDQ R12, AX
|
||||||
|
MOVQ R10, R12
|
||||||
|
ROLQ $12, R12
|
||||||
|
ADDQ R12, AX
|
||||||
|
MOVQ R11, R12
|
||||||
|
ROLQ $18, R12
|
||||||
|
ADDQ R12, AX
|
||||||
|
|
||||||
|
mergeRound(AX, R8)
|
||||||
|
mergeRound(AX, R9)
|
||||||
|
mergeRound(AX, R10)
|
||||||
|
mergeRound(AX, R11)
|
||||||
|
|
||||||
|
JMP afterBlocks
|
||||||
|
|
||||||
|
noBlocks:
|
||||||
|
MOVQ ·prime5v(SB), AX
|
||||||
|
|
||||||
|
afterBlocks:
|
||||||
|
ADDQ DX, AX
|
||||||
|
|
||||||
|
// Right now BX has len(b)-32, and we want to loop until CX > len(b)-8.
|
||||||
|
ADDQ $24, BX
|
||||||
|
|
||||||
|
CMPQ CX, BX
|
||||||
|
JG fourByte
|
||||||
|
|
||||||
|
wordLoop:
|
||||||
|
// Calculate k1.
|
||||||
|
MOVQ (CX), R8
|
||||||
|
ADDQ $8, CX
|
||||||
|
IMULQ R14, R8
|
||||||
|
ROLQ $31, R8
|
||||||
|
IMULQ R13, R8
|
||||||
|
|
||||||
|
XORQ R8, AX
|
||||||
|
ROLQ $27, AX
|
||||||
|
IMULQ R13, AX
|
||||||
|
ADDQ R15, AX
|
||||||
|
|
||||||
|
CMPQ CX, BX
|
||||||
|
JLE wordLoop
|
||||||
|
|
||||||
|
fourByte:
|
||||||
|
ADDQ $4, BX
|
||||||
|
CMPQ CX, BX
|
||||||
|
JG singles
|
||||||
|
|
||||||
|
MOVL (CX), R8
|
||||||
|
ADDQ $4, CX
|
||||||
|
IMULQ R13, R8
|
||||||
|
XORQ R8, AX
|
||||||
|
|
||||||
|
ROLQ $23, AX
|
||||||
|
IMULQ R14, AX
|
||||||
|
ADDQ ·prime3v(SB), AX
|
||||||
|
|
||||||
|
singles:
|
||||||
|
ADDQ $4, BX
|
||||||
|
CMPQ CX, BX
|
||||||
|
JGE finalize
|
||||||
|
|
||||||
|
singlesLoop:
|
||||||
|
MOVBQZX (CX), R12
|
||||||
|
ADDQ $1, CX
|
||||||
|
IMULQ ·prime5v(SB), R12
|
||||||
|
XORQ R12, AX
|
||||||
|
|
||||||
|
ROLQ $11, AX
|
||||||
|
IMULQ R13, AX
|
||||||
|
|
||||||
|
CMPQ CX, BX
|
||||||
|
JL singlesLoop
|
||||||
|
|
||||||
|
finalize:
|
||||||
|
MOVQ AX, R12
|
||||||
|
SHRQ $33, R12
|
||||||
|
XORQ R12, AX
|
||||||
|
IMULQ R14, AX
|
||||||
|
MOVQ AX, R12
|
||||||
|
SHRQ $29, R12
|
||||||
|
XORQ R12, AX
|
||||||
|
IMULQ ·prime3v(SB), AX
|
||||||
|
MOVQ AX, R12
|
||||||
|
SHRQ $32, R12
|
||||||
|
XORQ R12, AX
|
||||||
|
|
||||||
|
MOVQ AX, ret+24(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// writeBlocks uses the same registers as above except that it uses AX to store
|
||||||
|
// the d pointer.
|
||||||
|
|
||||||
|
// func writeBlocks(d *Digest, b []byte) int
|
||||||
|
TEXT ·writeBlocks(SB), NOSPLIT, $0-40
|
||||||
|
// Load fixed primes needed for round.
|
||||||
|
MOVQ ·prime1v(SB), R13
|
||||||
|
MOVQ ·prime2v(SB), R14
|
||||||
|
|
||||||
|
// Load slice.
|
||||||
|
MOVQ b_base+8(FP), CX
|
||||||
|
MOVQ b_len+16(FP), DX
|
||||||
|
LEAQ (CX)(DX*1), BX
|
||||||
|
SUBQ $32, BX
|
||||||
|
|
||||||
|
// Load vN from d.
|
||||||
|
MOVQ d+0(FP), AX
|
||||||
|
MOVQ 0(AX), R8 // v1
|
||||||
|
MOVQ 8(AX), R9 // v2
|
||||||
|
MOVQ 16(AX), R10 // v3
|
||||||
|
MOVQ 24(AX), R11 // v4
|
||||||
|
|
||||||
|
// We don't need to check the loop condition here; this function is
|
||||||
|
// always called with at least one block of data to process.
|
||||||
|
blockLoop:
|
||||||
|
round(R8)
|
||||||
|
round(R9)
|
||||||
|
round(R10)
|
||||||
|
round(R11)
|
||||||
|
|
||||||
|
CMPQ CX, BX
|
||||||
|
JLE blockLoop
|
||||||
|
|
||||||
|
// Copy vN back to d.
|
||||||
|
MOVQ R8, 0(AX)
|
||||||
|
MOVQ R9, 8(AX)
|
||||||
|
MOVQ R10, 16(AX)
|
||||||
|
MOVQ R11, 24(AX)
|
||||||
|
|
||||||
|
// The number of bytes written is CX minus the old base pointer.
|
||||||
|
SUBQ b_base+8(FP), CX
|
||||||
|
MOVQ CX, ret+32(FP)
|
||||||
|
|
||||||
|
RET
|
||||||
76
vendor/github.com/cespare/xxhash/v2/xxhash_other.go
generated
vendored
Normal file
76
vendor/github.com/cespare/xxhash/v2/xxhash_other.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
// +build !amd64 appengine !gc purego
|
||||||
|
|
||||||
|
package xxhash
|
||||||
|
|
||||||
|
// Sum64 computes the 64-bit xxHash digest of b.
|
||||||
|
func Sum64(b []byte) uint64 {
|
||||||
|
// A simpler version would be
|
||||||
|
// d := New()
|
||||||
|
// d.Write(b)
|
||||||
|
// return d.Sum64()
|
||||||
|
// but this is faster, particularly for small inputs.
|
||||||
|
|
||||||
|
n := len(b)
|
||||||
|
var h uint64
|
||||||
|
|
||||||
|
if n >= 32 {
|
||||||
|
v1 := prime1v + prime2
|
||||||
|
v2 := prime2
|
||||||
|
v3 := uint64(0)
|
||||||
|
v4 := -prime1v
|
||||||
|
for len(b) >= 32 {
|
||||||
|
v1 = round(v1, u64(b[0:8:len(b)]))
|
||||||
|
v2 = round(v2, u64(b[8:16:len(b)]))
|
||||||
|
v3 = round(v3, u64(b[16:24:len(b)]))
|
||||||
|
v4 = round(v4, u64(b[24:32:len(b)]))
|
||||||
|
b = b[32:len(b):len(b)]
|
||||||
|
}
|
||||||
|
h = rol1(v1) + rol7(v2) + rol12(v3) + rol18(v4)
|
||||||
|
h = mergeRound(h, v1)
|
||||||
|
h = mergeRound(h, v2)
|
||||||
|
h = mergeRound(h, v3)
|
||||||
|
h = mergeRound(h, v4)
|
||||||
|
} else {
|
||||||
|
h = prime5
|
||||||
|
}
|
||||||
|
|
||||||
|
h += uint64(n)
|
||||||
|
|
||||||
|
i, end := 0, len(b)
|
||||||
|
for ; i+8 <= end; i += 8 {
|
||||||
|
k1 := round(0, u64(b[i:i+8:len(b)]))
|
||||||
|
h ^= k1
|
||||||
|
h = rol27(h)*prime1 + prime4
|
||||||
|
}
|
||||||
|
if i+4 <= end {
|
||||||
|
h ^= uint64(u32(b[i:i+4:len(b)])) * prime1
|
||||||
|
h = rol23(h)*prime2 + prime3
|
||||||
|
i += 4
|
||||||
|
}
|
||||||
|
for ; i < end; i++ {
|
||||||
|
h ^= uint64(b[i]) * prime5
|
||||||
|
h = rol11(h) * prime1
|
||||||
|
}
|
||||||
|
|
||||||
|
h ^= h >> 33
|
||||||
|
h *= prime2
|
||||||
|
h ^= h >> 29
|
||||||
|
h *= prime3
|
||||||
|
h ^= h >> 32
|
||||||
|
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeBlocks(d *Digest, b []byte) int {
|
||||||
|
v1, v2, v3, v4 := d.v1, d.v2, d.v3, d.v4
|
||||||
|
n := len(b)
|
||||||
|
for len(b) >= 32 {
|
||||||
|
v1 = round(v1, u64(b[0:8:len(b)]))
|
||||||
|
v2 = round(v2, u64(b[8:16:len(b)]))
|
||||||
|
v3 = round(v3, u64(b[16:24:len(b)]))
|
||||||
|
v4 = round(v4, u64(b[24:32:len(b)]))
|
||||||
|
b = b[32:len(b):len(b)]
|
||||||
|
}
|
||||||
|
d.v1, d.v2, d.v3, d.v4 = v1, v2, v3, v4
|
||||||
|
return n - len(b)
|
||||||
|
}
|
||||||
15
vendor/github.com/cespare/xxhash/v2/xxhash_safe.go
generated
vendored
Normal file
15
vendor/github.com/cespare/xxhash/v2/xxhash_safe.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// +build appengine
|
||||||
|
|
||||||
|
// This file contains the safe implementations of otherwise unsafe-using code.
|
||||||
|
|
||||||
|
package xxhash
|
||||||
|
|
||||||
|
// Sum64String computes the 64-bit xxHash digest of s.
|
||||||
|
func Sum64String(s string) uint64 {
|
||||||
|
return Sum64([]byte(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteString adds more data to d. It always returns len(s), nil.
|
||||||
|
func (d *Digest) WriteString(s string) (n int, err error) {
|
||||||
|
return d.Write([]byte(s))
|
||||||
|
}
|
||||||
46
vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go
generated
vendored
Normal file
46
vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// +build !appengine
|
||||||
|
|
||||||
|
// This file encapsulates usage of unsafe.
|
||||||
|
// xxhash_safe.go contains the safe implementations.
|
||||||
|
|
||||||
|
package xxhash
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notes:
|
||||||
|
//
|
||||||
|
// See https://groups.google.com/d/msg/golang-nuts/dcjzJy-bSpw/tcZYBzQqAQAJ
|
||||||
|
// for some discussion about these unsafe conversions.
|
||||||
|
//
|
||||||
|
// In the future it's possible that compiler optimizations will make these
|
||||||
|
// unsafe operations unnecessary: https://golang.org/issue/2205.
|
||||||
|
//
|
||||||
|
// Both of these wrapper functions still incur function call overhead since they
|
||||||
|
// will not be inlined. We could write Go/asm copies of Sum64 and Digest.Write
|
||||||
|
// for strings to squeeze out a bit more speed. Mid-stack inlining should
|
||||||
|
// eventually fix this.
|
||||||
|
|
||||||
|
// Sum64String computes the 64-bit xxHash digest of s.
|
||||||
|
// It may be faster than Sum64([]byte(s)) by avoiding a copy.
|
||||||
|
func Sum64String(s string) uint64 {
|
||||||
|
var b []byte
|
||||||
|
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||||
|
bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
|
||||||
|
bh.Len = len(s)
|
||||||
|
bh.Cap = len(s)
|
||||||
|
return Sum64(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteString adds more data to d. It always returns len(s), nil.
|
||||||
|
// It may be faster than Write([]byte(s)) by avoiding a copy.
|
||||||
|
func (d *Digest) WriteString(s string) (n int, err error) {
|
||||||
|
var b []byte
|
||||||
|
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||||
|
bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
|
||||||
|
bh.Len = len(s)
|
||||||
|
bh.Cap = len(s)
|
||||||
|
return d.Write(b)
|
||||||
|
}
|
||||||
15
vendor/github.com/davecgh/go-spew/LICENSE
generated
vendored
Normal file
15
vendor/github.com/davecgh/go-spew/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
ISC License
|
||||||
|
|
||||||
|
Copyright (c) 2012-2016 Dave Collins <dave@davec.name>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
145
vendor/github.com/davecgh/go-spew/spew/bypass.go
generated
vendored
Normal file
145
vendor/github.com/davecgh/go-spew/spew/bypass.go
generated
vendored
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
// Copyright (c) 2015-2016 Dave Collins <dave@davec.name>
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice appear in all copies.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
// NOTE: Due to the following build constraints, this file will only be compiled
|
||||||
|
// when the code is not running on Google App Engine, compiled by GopherJS, and
|
||||||
|
// "-tags safe" is not added to the go build command line. The "disableunsafe"
|
||||||
|
// tag is deprecated and thus should not be used.
|
||||||
|
// Go versions prior to 1.4 are disabled because they use a different layout
|
||||||
|
// for interfaces which make the implementation of unsafeReflectValue more complex.
|
||||||
|
// +build !js,!appengine,!safe,!disableunsafe,go1.4
|
||||||
|
|
||||||
|
package spew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// UnsafeDisabled is a build-time constant which specifies whether or
|
||||||
|
// not access to the unsafe package is available.
|
||||||
|
UnsafeDisabled = false
|
||||||
|
|
||||||
|
// ptrSize is the size of a pointer on the current arch.
|
||||||
|
ptrSize = unsafe.Sizeof((*byte)(nil))
|
||||||
|
)
|
||||||
|
|
||||||
|
type flag uintptr
|
||||||
|
|
||||||
|
var (
|
||||||
|
// flagRO indicates whether the value field of a reflect.Value
|
||||||
|
// is read-only.
|
||||||
|
flagRO flag
|
||||||
|
|
||||||
|
// flagAddr indicates whether the address of the reflect.Value's
|
||||||
|
// value may be taken.
|
||||||
|
flagAddr flag
|
||||||
|
)
|
||||||
|
|
||||||
|
// flagKindMask holds the bits that make up the kind
|
||||||
|
// part of the flags field. In all the supported versions,
|
||||||
|
// it is in the lower 5 bits.
|
||||||
|
const flagKindMask = flag(0x1f)
|
||||||
|
|
||||||
|
// Different versions of Go have used different
|
||||||
|
// bit layouts for the flags type. This table
|
||||||
|
// records the known combinations.
|
||||||
|
var okFlags = []struct {
|
||||||
|
ro, addr flag
|
||||||
|
}{{
|
||||||
|
// From Go 1.4 to 1.5
|
||||||
|
ro: 1 << 5,
|
||||||
|
addr: 1 << 7,
|
||||||
|
}, {
|
||||||
|
// Up to Go tip.
|
||||||
|
ro: 1<<5 | 1<<6,
|
||||||
|
addr: 1 << 8,
|
||||||
|
}}
|
||||||
|
|
||||||
|
var flagValOffset = func() uintptr {
|
||||||
|
field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag")
|
||||||
|
if !ok {
|
||||||
|
panic("reflect.Value has no flag field")
|
||||||
|
}
|
||||||
|
return field.Offset
|
||||||
|
}()
|
||||||
|
|
||||||
|
// flagField returns a pointer to the flag field of a reflect.Value.
|
||||||
|
func flagField(v *reflect.Value) *flag {
|
||||||
|
return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset))
|
||||||
|
}
|
||||||
|
|
||||||
|
// unsafeReflectValue converts the passed reflect.Value into a one that bypasses
|
||||||
|
// the typical safety restrictions preventing access to unaddressable and
|
||||||
|
// unexported data. It works by digging the raw pointer to the underlying
|
||||||
|
// value out of the protected value and generating a new unprotected (unsafe)
|
||||||
|
// reflect.Value to it.
|
||||||
|
//
|
||||||
|
// This allows us to check for implementations of the Stringer and error
|
||||||
|
// interfaces to be used for pretty printing ordinarily unaddressable and
|
||||||
|
// inaccessible values such as unexported struct fields.
|
||||||
|
func unsafeReflectValue(v reflect.Value) reflect.Value {
|
||||||
|
if !v.IsValid() || (v.CanInterface() && v.CanAddr()) {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
flagFieldPtr := flagField(&v)
|
||||||
|
*flagFieldPtr &^= flagRO
|
||||||
|
*flagFieldPtr |= flagAddr
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity checks against future reflect package changes
|
||||||
|
// to the type or semantics of the Value.flag field.
|
||||||
|
func init() {
|
||||||
|
field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag")
|
||||||
|
if !ok {
|
||||||
|
panic("reflect.Value has no flag field")
|
||||||
|
}
|
||||||
|
if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() {
|
||||||
|
panic("reflect.Value flag field has changed kind")
|
||||||
|
}
|
||||||
|
type t0 int
|
||||||
|
var t struct {
|
||||||
|
A t0
|
||||||
|
// t0 will have flagEmbedRO set.
|
||||||
|
t0
|
||||||
|
// a will have flagStickyRO set
|
||||||
|
a t0
|
||||||
|
}
|
||||||
|
vA := reflect.ValueOf(t).FieldByName("A")
|
||||||
|
va := reflect.ValueOf(t).FieldByName("a")
|
||||||
|
vt0 := reflect.ValueOf(t).FieldByName("t0")
|
||||||
|
|
||||||
|
// Infer flagRO from the difference between the flags
|
||||||
|
// for the (otherwise identical) fields in t.
|
||||||
|
flagPublic := *flagField(&vA)
|
||||||
|
flagWithRO := *flagField(&va) | *flagField(&vt0)
|
||||||
|
flagRO = flagPublic ^ flagWithRO
|
||||||
|
|
||||||
|
// Infer flagAddr from the difference between a value
|
||||||
|
// taken from a pointer and not.
|
||||||
|
vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A")
|
||||||
|
flagNoPtr := *flagField(&vA)
|
||||||
|
flagPtr := *flagField(&vPtrA)
|
||||||
|
flagAddr = flagNoPtr ^ flagPtr
|
||||||
|
|
||||||
|
// Check that the inferred flags tally with one of the known versions.
|
||||||
|
for _, f := range okFlags {
|
||||||
|
if flagRO == f.ro && flagAddr == f.addr {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("reflect.Value read-only flag has changed semantics")
|
||||||
|
}
|
||||||
38
vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
generated
vendored
Normal file
38
vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (c) 2015-2016 Dave Collins <dave@davec.name>
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice appear in all copies.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
// NOTE: Due to the following build constraints, this file will only be compiled
|
||||||
|
// when the code is running on Google App Engine, compiled by GopherJS, or
|
||||||
|
// "-tags safe" is added to the go build command line. The "disableunsafe"
|
||||||
|
// tag is deprecated and thus should not be used.
|
||||||
|
// +build js appengine safe disableunsafe !go1.4
|
||||||
|
|
||||||
|
package spew
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
const (
|
||||||
|
// UnsafeDisabled is a build-time constant which specifies whether or
|
||||||
|
// not access to the unsafe package is available.
|
||||||
|
UnsafeDisabled = true
|
||||||
|
)
|
||||||
|
|
||||||
|
// unsafeReflectValue typically converts the passed reflect.Value into a one
|
||||||
|
// that bypasses the typical safety restrictions preventing access to
|
||||||
|
// unaddressable and unexported data. However, doing this relies on access to
|
||||||
|
// the unsafe package. This is a stub version which simply returns the passed
|
||||||
|
// reflect.Value when the unsafe package is not available.
|
||||||
|
func unsafeReflectValue(v reflect.Value) reflect.Value {
|
||||||
|
return v
|
||||||
|
}
|
||||||
341
vendor/github.com/davecgh/go-spew/spew/common.go
generated
vendored
Normal file
341
vendor/github.com/davecgh/go-spew/spew/common.go
generated
vendored
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package spew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Some constants in the form of bytes to avoid string overhead. This mirrors
|
||||||
|
// the technique used in the fmt package.
|
||||||
|
var (
|
||||||
|
panicBytes = []byte("(PANIC=")
|
||||||
|
plusBytes = []byte("+")
|
||||||
|
iBytes = []byte("i")
|
||||||
|
trueBytes = []byte("true")
|
||||||
|
falseBytes = []byte("false")
|
||||||
|
interfaceBytes = []byte("(interface {})")
|
||||||
|
commaNewlineBytes = []byte(",\n")
|
||||||
|
newlineBytes = []byte("\n")
|
||||||
|
openBraceBytes = []byte("{")
|
||||||
|
openBraceNewlineBytes = []byte("{\n")
|
||||||
|
closeBraceBytes = []byte("}")
|
||||||
|
asteriskBytes = []byte("*")
|
||||||
|
colonBytes = []byte(":")
|
||||||
|
colonSpaceBytes = []byte(": ")
|
||||||
|
openParenBytes = []byte("(")
|
||||||
|
closeParenBytes = []byte(")")
|
||||||
|
spaceBytes = []byte(" ")
|
||||||
|
pointerChainBytes = []byte("->")
|
||||||
|
nilAngleBytes = []byte("<nil>")
|
||||||
|
maxNewlineBytes = []byte("<max depth reached>\n")
|
||||||
|
maxShortBytes = []byte("<max>")
|
||||||
|
circularBytes = []byte("<already shown>")
|
||||||
|
circularShortBytes = []byte("<shown>")
|
||||||
|
invalidAngleBytes = []byte("<invalid>")
|
||||||
|
openBracketBytes = []byte("[")
|
||||||
|
closeBracketBytes = []byte("]")
|
||||||
|
percentBytes = []byte("%")
|
||||||
|
precisionBytes = []byte(".")
|
||||||
|
openAngleBytes = []byte("<")
|
||||||
|
closeAngleBytes = []byte(">")
|
||||||
|
openMapBytes = []byte("map[")
|
||||||
|
closeMapBytes = []byte("]")
|
||||||
|
lenEqualsBytes = []byte("len=")
|
||||||
|
capEqualsBytes = []byte("cap=")
|
||||||
|
)
|
||||||
|
|
||||||
|
// hexDigits is used to map a decimal value to a hex digit.
|
||||||
|
var hexDigits = "0123456789abcdef"
|
||||||
|
|
||||||
|
// catchPanic handles any panics that might occur during the handleMethods
|
||||||
|
// calls.
|
||||||
|
func catchPanic(w io.Writer, v reflect.Value) {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
w.Write(panicBytes)
|
||||||
|
fmt.Fprintf(w, "%v", err)
|
||||||
|
w.Write(closeParenBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleMethods attempts to call the Error and String methods on the underlying
|
||||||
|
// type the passed reflect.Value represents and outputes the result to Writer w.
|
||||||
|
//
|
||||||
|
// It handles panics in any called methods by catching and displaying the error
|
||||||
|
// as the formatted value.
|
||||||
|
func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) {
|
||||||
|
// We need an interface to check if the type implements the error or
|
||||||
|
// Stringer interface. However, the reflect package won't give us an
|
||||||
|
// interface on certain things like unexported struct fields in order
|
||||||
|
// to enforce visibility rules. We use unsafe, when it's available,
|
||||||
|
// to bypass these restrictions since this package does not mutate the
|
||||||
|
// values.
|
||||||
|
if !v.CanInterface() {
|
||||||
|
if UnsafeDisabled {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
v = unsafeReflectValue(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose whether or not to do error and Stringer interface lookups against
|
||||||
|
// the base type or a pointer to the base type depending on settings.
|
||||||
|
// Technically calling one of these methods with a pointer receiver can
|
||||||
|
// mutate the value, however, types which choose to satisify an error or
|
||||||
|
// Stringer interface with a pointer receiver should not be mutating their
|
||||||
|
// state inside these interface methods.
|
||||||
|
if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() {
|
||||||
|
v = unsafeReflectValue(v)
|
||||||
|
}
|
||||||
|
if v.CanAddr() {
|
||||||
|
v = v.Addr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is it an error or Stringer?
|
||||||
|
switch iface := v.Interface().(type) {
|
||||||
|
case error:
|
||||||
|
defer catchPanic(w, v)
|
||||||
|
if cs.ContinueOnMethod {
|
||||||
|
w.Write(openParenBytes)
|
||||||
|
w.Write([]byte(iface.Error()))
|
||||||
|
w.Write(closeParenBytes)
|
||||||
|
w.Write(spaceBytes)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write([]byte(iface.Error()))
|
||||||
|
return true
|
||||||
|
|
||||||
|
case fmt.Stringer:
|
||||||
|
defer catchPanic(w, v)
|
||||||
|
if cs.ContinueOnMethod {
|
||||||
|
w.Write(openParenBytes)
|
||||||
|
w.Write([]byte(iface.String()))
|
||||||
|
w.Write(closeParenBytes)
|
||||||
|
w.Write(spaceBytes)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
w.Write([]byte(iface.String()))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// printBool outputs a boolean value as true or false to Writer w.
|
||||||
|
func printBool(w io.Writer, val bool) {
|
||||||
|
if val {
|
||||||
|
w.Write(trueBytes)
|
||||||
|
} else {
|
||||||
|
w.Write(falseBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// printInt outputs a signed integer value to Writer w.
|
||||||
|
func printInt(w io.Writer, val int64, base int) {
|
||||||
|
w.Write([]byte(strconv.FormatInt(val, base)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// printUint outputs an unsigned integer value to Writer w.
|
||||||
|
func printUint(w io.Writer, val uint64, base int) {
|
||||||
|
w.Write([]byte(strconv.FormatUint(val, base)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// printFloat outputs a floating point value using the specified precision,
|
||||||
|
// which is expected to be 32 or 64bit, to Writer w.
|
||||||
|
func printFloat(w io.Writer, val float64, precision int) {
|
||||||
|
w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// printComplex outputs a complex value using the specified float precision
|
||||||
|
// for the real and imaginary parts to Writer w.
|
||||||
|
func printComplex(w io.Writer, c complex128, floatPrecision int) {
|
||||||
|
r := real(c)
|
||||||
|
w.Write(openParenBytes)
|
||||||
|
w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision)))
|
||||||
|
i := imag(c)
|
||||||
|
if i >= 0 {
|
||||||
|
w.Write(plusBytes)
|
||||||
|
}
|
||||||
|
w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision)))
|
||||||
|
w.Write(iBytes)
|
||||||
|
w.Write(closeParenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x'
|
||||||
|
// prefix to Writer w.
|
||||||
|
func printHexPtr(w io.Writer, p uintptr) {
|
||||||
|
// Null pointer.
|
||||||
|
num := uint64(p)
|
||||||
|
if num == 0 {
|
||||||
|
w.Write(nilAngleBytes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix
|
||||||
|
buf := make([]byte, 18)
|
||||||
|
|
||||||
|
// It's simpler to construct the hex string right to left.
|
||||||
|
base := uint64(16)
|
||||||
|
i := len(buf) - 1
|
||||||
|
for num >= base {
|
||||||
|
buf[i] = hexDigits[num%base]
|
||||||
|
num /= base
|
||||||
|
i--
|
||||||
|
}
|
||||||
|
buf[i] = hexDigits[num]
|
||||||
|
|
||||||
|
// Add '0x' prefix.
|
||||||
|
i--
|
||||||
|
buf[i] = 'x'
|
||||||
|
i--
|
||||||
|
buf[i] = '0'
|
||||||
|
|
||||||
|
// Strip unused leading bytes.
|
||||||
|
buf = buf[i:]
|
||||||
|
w.Write(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
// valuesSorter implements sort.Interface to allow a slice of reflect.Value
|
||||||
|
// elements to be sorted.
|
||||||
|
type valuesSorter struct {
|
||||||
|
values []reflect.Value
|
||||||
|
strings []string // either nil or same len and values
|
||||||
|
cs *ConfigState
|
||||||
|
}
|
||||||
|
|
||||||
|
// newValuesSorter initializes a valuesSorter instance, which holds a set of
|
||||||
|
// surrogate keys on which the data should be sorted. It uses flags in
|
||||||
|
// ConfigState to decide if and how to populate those surrogate keys.
|
||||||
|
func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface {
|
||||||
|
vs := &valuesSorter{values: values, cs: cs}
|
||||||
|
if canSortSimply(vs.values[0].Kind()) {
|
||||||
|
return vs
|
||||||
|
}
|
||||||
|
if !cs.DisableMethods {
|
||||||
|
vs.strings = make([]string, len(values))
|
||||||
|
for i := range vs.values {
|
||||||
|
b := bytes.Buffer{}
|
||||||
|
if !handleMethods(cs, &b, vs.values[i]) {
|
||||||
|
vs.strings = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
vs.strings[i] = b.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if vs.strings == nil && cs.SpewKeys {
|
||||||
|
vs.strings = make([]string, len(values))
|
||||||
|
for i := range vs.values {
|
||||||
|
vs.strings[i] = Sprintf("%#v", vs.values[i].Interface())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vs
|
||||||
|
}
|
||||||
|
|
||||||
|
// canSortSimply tests whether a reflect.Kind is a primitive that can be sorted
|
||||||
|
// directly, or whether it should be considered for sorting by surrogate keys
|
||||||
|
// (if the ConfigState allows it).
|
||||||
|
func canSortSimply(kind reflect.Kind) bool {
|
||||||
|
// This switch parallels valueSortLess, except for the default case.
|
||||||
|
switch kind {
|
||||||
|
case reflect.Bool:
|
||||||
|
return true
|
||||||
|
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
|
||||||
|
return true
|
||||||
|
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
|
||||||
|
return true
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
return true
|
||||||
|
case reflect.String:
|
||||||
|
return true
|
||||||
|
case reflect.Uintptr:
|
||||||
|
return true
|
||||||
|
case reflect.Array:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Len returns the number of values in the slice. It is part of the
|
||||||
|
// sort.Interface implementation.
|
||||||
|
func (s *valuesSorter) Len() int {
|
||||||
|
return len(s.values)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap swaps the values at the passed indices. It is part of the
|
||||||
|
// sort.Interface implementation.
|
||||||
|
func (s *valuesSorter) Swap(i, j int) {
|
||||||
|
s.values[i], s.values[j] = s.values[j], s.values[i]
|
||||||
|
if s.strings != nil {
|
||||||
|
s.strings[i], s.strings[j] = s.strings[j], s.strings[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// valueSortLess returns whether the first value should sort before the second
|
||||||
|
// value. It is used by valueSorter.Less as part of the sort.Interface
|
||||||
|
// implementation.
|
||||||
|
func valueSortLess(a, b reflect.Value) bool {
|
||||||
|
switch a.Kind() {
|
||||||
|
case reflect.Bool:
|
||||||
|
return !a.Bool() && b.Bool()
|
||||||
|
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
|
||||||
|
return a.Int() < b.Int()
|
||||||
|
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
|
||||||
|
return a.Uint() < b.Uint()
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
return a.Float() < b.Float()
|
||||||
|
case reflect.String:
|
||||||
|
return a.String() < b.String()
|
||||||
|
case reflect.Uintptr:
|
||||||
|
return a.Uint() < b.Uint()
|
||||||
|
case reflect.Array:
|
||||||
|
// Compare the contents of both arrays.
|
||||||
|
l := a.Len()
|
||||||
|
for i := 0; i < l; i++ {
|
||||||
|
av := a.Index(i)
|
||||||
|
bv := b.Index(i)
|
||||||
|
if av.Interface() == bv.Interface() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return valueSortLess(av, bv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return a.String() < b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Less returns whether the value at index i should sort before the
|
||||||
|
// value at index j. It is part of the sort.Interface implementation.
|
||||||
|
func (s *valuesSorter) Less(i, j int) bool {
|
||||||
|
if s.strings == nil {
|
||||||
|
return valueSortLess(s.values[i], s.values[j])
|
||||||
|
}
|
||||||
|
return s.strings[i] < s.strings[j]
|
||||||
|
}
|
||||||
|
|
||||||
|
// sortValues is a sort function that handles both native types and any type that
|
||||||
|
// can be converted to error or Stringer. Other inputs are sorted according to
|
||||||
|
// their Value.String() value to ensure display stability.
|
||||||
|
func sortValues(values []reflect.Value, cs *ConfigState) {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sort.Sort(newValuesSorter(values, cs))
|
||||||
|
}
|
||||||
306
vendor/github.com/davecgh/go-spew/spew/config.go
generated
vendored
Normal file
306
vendor/github.com/davecgh/go-spew/spew/config.go
generated
vendored
Normal file
@@ -0,0 +1,306 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package spew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConfigState houses the configuration options used by spew to format and
|
||||||
|
// display values. There is a global instance, Config, that is used to control
|
||||||
|
// all top-level Formatter and Dump functionality. Each ConfigState instance
|
||||||
|
// provides methods equivalent to the top-level functions.
|
||||||
|
//
|
||||||
|
// The zero value for ConfigState provides no indentation. You would typically
|
||||||
|
// want to set it to a space or a tab.
|
||||||
|
//
|
||||||
|
// Alternatively, you can use NewDefaultConfig to get a ConfigState instance
|
||||||
|
// with default settings. See the documentation of NewDefaultConfig for default
|
||||||
|
// values.
|
||||||
|
type ConfigState struct {
|
||||||
|
// Indent specifies the string to use for each indentation level. The
|
||||||
|
// global config instance that all top-level functions use set this to a
|
||||||
|
// single space by default. If you would like more indentation, you might
|
||||||
|
// set this to a tab with "\t" or perhaps two spaces with " ".
|
||||||
|
Indent string
|
||||||
|
|
||||||
|
// MaxDepth controls the maximum number of levels to descend into nested
|
||||||
|
// data structures. The default, 0, means there is no limit.
|
||||||
|
//
|
||||||
|
// NOTE: Circular data structures are properly detected, so it is not
|
||||||
|
// necessary to set this value unless you specifically want to limit deeply
|
||||||
|
// nested data structures.
|
||||||
|
MaxDepth int
|
||||||
|
|
||||||
|
// DisableMethods specifies whether or not error and Stringer interfaces are
|
||||||
|
// invoked for types that implement them.
|
||||||
|
DisableMethods bool
|
||||||
|
|
||||||
|
// DisablePointerMethods specifies whether or not to check for and invoke
|
||||||
|
// error and Stringer interfaces on types which only accept a pointer
|
||||||
|
// receiver when the current type is not a pointer.
|
||||||
|
//
|
||||||
|
// NOTE: This might be an unsafe action since calling one of these methods
|
||||||
|
// with a pointer receiver could technically mutate the value, however,
|
||||||
|
// in practice, types which choose to satisify an error or Stringer
|
||||||
|
// interface with a pointer receiver should not be mutating their state
|
||||||
|
// inside these interface methods. As a result, this option relies on
|
||||||
|
// access to the unsafe package, so it will not have any effect when
|
||||||
|
// running in environments without access to the unsafe package such as
|
||||||
|
// Google App Engine or with the "safe" build tag specified.
|
||||||
|
DisablePointerMethods bool
|
||||||
|
|
||||||
|
// DisablePointerAddresses specifies whether to disable the printing of
|
||||||
|
// pointer addresses. This is useful when diffing data structures in tests.
|
||||||
|
DisablePointerAddresses bool
|
||||||
|
|
||||||
|
// DisableCapacities specifies whether to disable the printing of capacities
|
||||||
|
// for arrays, slices, maps and channels. This is useful when diffing
|
||||||
|
// data structures in tests.
|
||||||
|
DisableCapacities bool
|
||||||
|
|
||||||
|
// ContinueOnMethod specifies whether or not recursion should continue once
|
||||||
|
// a custom error or Stringer interface is invoked. The default, false,
|
||||||
|
// means it will print the results of invoking the custom error or Stringer
|
||||||
|
// interface and return immediately instead of continuing to recurse into
|
||||||
|
// the internals of the data type.
|
||||||
|
//
|
||||||
|
// NOTE: This flag does not have any effect if method invocation is disabled
|
||||||
|
// via the DisableMethods or DisablePointerMethods options.
|
||||||
|
ContinueOnMethod bool
|
||||||
|
|
||||||
|
// SortKeys specifies map keys should be sorted before being printed. Use
|
||||||
|
// this to have a more deterministic, diffable output. Note that only
|
||||||
|
// native types (bool, int, uint, floats, uintptr and string) and types
|
||||||
|
// that support the error or Stringer interfaces (if methods are
|
||||||
|
// enabled) are supported, with other types sorted according to the
|
||||||
|
// reflect.Value.String() output which guarantees display stability.
|
||||||
|
SortKeys bool
|
||||||
|
|
||||||
|
// SpewKeys specifies that, as a last resort attempt, map keys should
|
||||||
|
// be spewed to strings and sorted by those strings. This is only
|
||||||
|
// considered if SortKeys is true.
|
||||||
|
SpewKeys bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config is the active configuration of the top-level functions.
|
||||||
|
// The configuration can be changed by modifying the contents of spew.Config.
|
||||||
|
var Config = ConfigState{Indent: " "}
|
||||||
|
|
||||||
|
// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the formatted string as a value that satisfies error. See NewFormatter
|
||||||
|
// for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Errorf(format, c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Errorf(format string, a ...interface{}) (err error) {
|
||||||
|
return fmt.Errorf(format, c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Fprint(w, c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprint(w, c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Fprintf(w, format, c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprintf(w, format, c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Fprintln(w, c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprintln(w, c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print is a wrapper for fmt.Print that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Print(c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Print(a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Print(c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printf is a wrapper for fmt.Printf that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Printf(format, c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Printf(format string, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Printf(format, c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Println is a wrapper for fmt.Println that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Println(c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Println(a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Println(c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the resulting string. See NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Sprint(c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Sprint(a ...interface{}) string {
|
||||||
|
return fmt.Sprint(c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were
|
||||||
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
// the resulting string. See NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Sprintf(format, c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Sprintf(format string, a ...interface{}) string {
|
||||||
|
return fmt.Sprintf(format, c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it
|
||||||
|
// were passed with a Formatter interface returned by c.NewFormatter. It
|
||||||
|
// returns the resulting string. See NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Sprintln(c.NewFormatter(a), c.NewFormatter(b))
|
||||||
|
func (c *ConfigState) Sprintln(a ...interface{}) string {
|
||||||
|
return fmt.Sprintln(c.convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
NewFormatter returns a custom formatter that satisfies the fmt.Formatter
|
||||||
|
interface. As a result, it integrates cleanly with standard fmt package
|
||||||
|
printing functions. The formatter is useful for inline printing of smaller data
|
||||||
|
types similar to the standard %v format specifier.
|
||||||
|
|
||||||
|
The custom formatter only responds to the %v (most compact), %+v (adds pointer
|
||||||
|
addresses), %#v (adds types), and %#+v (adds types and pointer addresses) verb
|
||||||
|
combinations. Any other verbs such as %x and %q will be sent to the the
|
||||||
|
standard fmt package for formatting. In addition, the custom formatter ignores
|
||||||
|
the width and precision arguments (however they will still work on the format
|
||||||
|
specifiers not handled by the custom formatter).
|
||||||
|
|
||||||
|
Typically this function shouldn't be called directly. It is much easier to make
|
||||||
|
use of the custom formatter by calling one of the convenience functions such as
|
||||||
|
c.Printf, c.Println, or c.Printf.
|
||||||
|
*/
|
||||||
|
func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter {
|
||||||
|
return newFormatter(c, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fdump formats and displays the passed arguments to io.Writer w. It formats
|
||||||
|
// exactly the same as Dump.
|
||||||
|
func (c *ConfigState) Fdump(w io.Writer, a ...interface{}) {
|
||||||
|
fdump(c, w, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Dump displays the passed parameters to standard out with newlines, customizable
|
||||||
|
indentation, and additional debug information such as complete types and all
|
||||||
|
pointer addresses used to indirect to the final value. It provides the
|
||||||
|
following features over the built-in printing facilities provided by the fmt
|
||||||
|
package:
|
||||||
|
|
||||||
|
* Pointers are dereferenced and followed
|
||||||
|
* Circular data structures are detected and handled properly
|
||||||
|
* Custom Stringer/error interfaces are optionally invoked, including
|
||||||
|
on unexported types
|
||||||
|
* Custom types which only implement the Stringer/error interfaces via
|
||||||
|
a pointer receiver are optionally invoked when passing non-pointer
|
||||||
|
variables
|
||||||
|
* Byte arrays and slices are dumped like the hexdump -C command which
|
||||||
|
includes offsets, byte values in hex, and ASCII output
|
||||||
|
|
||||||
|
The configuration options are controlled by modifying the public members
|
||||||
|
of c. See ConfigState for options documentation.
|
||||||
|
|
||||||
|
See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to
|
||||||
|
get the formatted result as a string.
|
||||||
|
*/
|
||||||
|
func (c *ConfigState) Dump(a ...interface{}) {
|
||||||
|
fdump(c, os.Stdout, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sdump returns a string with the passed arguments formatted exactly the same
|
||||||
|
// as Dump.
|
||||||
|
func (c *ConfigState) Sdump(a ...interface{}) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fdump(c, &buf, a...)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertArgs accepts a slice of arguments and returns a slice of the same
|
||||||
|
// length with each argument converted to a spew Formatter interface using
|
||||||
|
// the ConfigState associated with s.
|
||||||
|
func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{}) {
|
||||||
|
formatters = make([]interface{}, len(args))
|
||||||
|
for index, arg := range args {
|
||||||
|
formatters[index] = newFormatter(c, arg)
|
||||||
|
}
|
||||||
|
return formatters
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDefaultConfig returns a ConfigState with the following default settings.
|
||||||
|
//
|
||||||
|
// Indent: " "
|
||||||
|
// MaxDepth: 0
|
||||||
|
// DisableMethods: false
|
||||||
|
// DisablePointerMethods: false
|
||||||
|
// ContinueOnMethod: false
|
||||||
|
// SortKeys: false
|
||||||
|
func NewDefaultConfig() *ConfigState {
|
||||||
|
return &ConfigState{Indent: " "}
|
||||||
|
}
|
||||||
211
vendor/github.com/davecgh/go-spew/spew/doc.go
generated
vendored
Normal file
211
vendor/github.com/davecgh/go-spew/spew/doc.go
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package spew implements a deep pretty printer for Go data structures to aid in
|
||||||
|
debugging.
|
||||||
|
|
||||||
|
A quick overview of the additional features spew provides over the built-in
|
||||||
|
printing facilities for Go data types are as follows:
|
||||||
|
|
||||||
|
* Pointers are dereferenced and followed
|
||||||
|
* Circular data structures are detected and handled properly
|
||||||
|
* Custom Stringer/error interfaces are optionally invoked, including
|
||||||
|
on unexported types
|
||||||
|
* Custom types which only implement the Stringer/error interfaces via
|
||||||
|
a pointer receiver are optionally invoked when passing non-pointer
|
||||||
|
variables
|
||||||
|
* Byte arrays and slices are dumped like the hexdump -C command which
|
||||||
|
includes offsets, byte values in hex, and ASCII output (only when using
|
||||||
|
Dump style)
|
||||||
|
|
||||||
|
There are two different approaches spew allows for dumping Go data structures:
|
||||||
|
|
||||||
|
* Dump style which prints with newlines, customizable indentation,
|
||||||
|
and additional debug information such as types and all pointer addresses
|
||||||
|
used to indirect to the final value
|
||||||
|
* A custom Formatter interface that integrates cleanly with the standard fmt
|
||||||
|
package and replaces %v, %+v, %#v, and %#+v to provide inline printing
|
||||||
|
similar to the default %v while providing the additional functionality
|
||||||
|
outlined above and passing unsupported format verbs such as %x and %q
|
||||||
|
along to fmt
|
||||||
|
|
||||||
|
Quick Start
|
||||||
|
|
||||||
|
This section demonstrates how to quickly get started with spew. See the
|
||||||
|
sections below for further details on formatting and configuration options.
|
||||||
|
|
||||||
|
To dump a variable with full newlines, indentation, type, and pointer
|
||||||
|
information use Dump, Fdump, or Sdump:
|
||||||
|
spew.Dump(myVar1, myVar2, ...)
|
||||||
|
spew.Fdump(someWriter, myVar1, myVar2, ...)
|
||||||
|
str := spew.Sdump(myVar1, myVar2, ...)
|
||||||
|
|
||||||
|
Alternatively, if you would prefer to use format strings with a compacted inline
|
||||||
|
printing style, use the convenience wrappers Printf, Fprintf, etc with
|
||||||
|
%v (most compact), %+v (adds pointer addresses), %#v (adds types), or
|
||||||
|
%#+v (adds types and pointer addresses):
|
||||||
|
spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
||||||
|
spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
||||||
|
spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
||||||
|
spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
||||||
|
|
||||||
|
Configuration Options
|
||||||
|
|
||||||
|
Configuration of spew is handled by fields in the ConfigState type. For
|
||||||
|
convenience, all of the top-level functions use a global state available
|
||||||
|
via the spew.Config global.
|
||||||
|
|
||||||
|
It is also possible to create a ConfigState instance that provides methods
|
||||||
|
equivalent to the top-level functions. This allows concurrent configuration
|
||||||
|
options. See the ConfigState documentation for more details.
|
||||||
|
|
||||||
|
The following configuration options are available:
|
||||||
|
* Indent
|
||||||
|
String to use for each indentation level for Dump functions.
|
||||||
|
It is a single space by default. A popular alternative is "\t".
|
||||||
|
|
||||||
|
* MaxDepth
|
||||||
|
Maximum number of levels to descend into nested data structures.
|
||||||
|
There is no limit by default.
|
||||||
|
|
||||||
|
* DisableMethods
|
||||||
|
Disables invocation of error and Stringer interface methods.
|
||||||
|
Method invocation is enabled by default.
|
||||||
|
|
||||||
|
* DisablePointerMethods
|
||||||
|
Disables invocation of error and Stringer interface methods on types
|
||||||
|
which only accept pointer receivers from non-pointer variables.
|
||||||
|
Pointer method invocation is enabled by default.
|
||||||
|
|
||||||
|
* DisablePointerAddresses
|
||||||
|
DisablePointerAddresses specifies whether to disable the printing of
|
||||||
|
pointer addresses. This is useful when diffing data structures in tests.
|
||||||
|
|
||||||
|
* DisableCapacities
|
||||||
|
DisableCapacities specifies whether to disable the printing of
|
||||||
|
capacities for arrays, slices, maps and channels. This is useful when
|
||||||
|
diffing data structures in tests.
|
||||||
|
|
||||||
|
* ContinueOnMethod
|
||||||
|
Enables recursion into types after invoking error and Stringer interface
|
||||||
|
methods. Recursion after method invocation is disabled by default.
|
||||||
|
|
||||||
|
* SortKeys
|
||||||
|
Specifies map keys should be sorted before being printed. Use
|
||||||
|
this to have a more deterministic, diffable output. Note that
|
||||||
|
only native types (bool, int, uint, floats, uintptr and string)
|
||||||
|
and types which implement error or Stringer interfaces are
|
||||||
|
supported with other types sorted according to the
|
||||||
|
reflect.Value.String() output which guarantees display
|
||||||
|
stability. Natural map order is used by default.
|
||||||
|
|
||||||
|
* SpewKeys
|
||||||
|
Specifies that, as a last resort attempt, map keys should be
|
||||||
|
spewed to strings and sorted by those strings. This is only
|
||||||
|
considered if SortKeys is true.
|
||||||
|
|
||||||
|
Dump Usage
|
||||||
|
|
||||||
|
Simply call spew.Dump with a list of variables you want to dump:
|
||||||
|
|
||||||
|
spew.Dump(myVar1, myVar2, ...)
|
||||||
|
|
||||||
|
You may also call spew.Fdump if you would prefer to output to an arbitrary
|
||||||
|
io.Writer. For example, to dump to standard error:
|
||||||
|
|
||||||
|
spew.Fdump(os.Stderr, myVar1, myVar2, ...)
|
||||||
|
|
||||||
|
A third option is to call spew.Sdump to get the formatted output as a string:
|
||||||
|
|
||||||
|
str := spew.Sdump(myVar1, myVar2, ...)
|
||||||
|
|
||||||
|
Sample Dump Output
|
||||||
|
|
||||||
|
See the Dump example for details on the setup of the types and variables being
|
||||||
|
shown here.
|
||||||
|
|
||||||
|
(main.Foo) {
|
||||||
|
unexportedField: (*main.Bar)(0xf84002e210)({
|
||||||
|
flag: (main.Flag) flagTwo,
|
||||||
|
data: (uintptr) <nil>
|
||||||
|
}),
|
||||||
|
ExportedField: (map[interface {}]interface {}) (len=1) {
|
||||||
|
(string) (len=3) "one": (bool) true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C
|
||||||
|
command as shown.
|
||||||
|
([]uint8) (len=32 cap=32) {
|
||||||
|
00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... |
|
||||||
|
00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0|
|
||||||
|
00000020 31 32 |12|
|
||||||
|
}
|
||||||
|
|
||||||
|
Custom Formatter
|
||||||
|
|
||||||
|
Spew provides a custom formatter that implements the fmt.Formatter interface
|
||||||
|
so that it integrates cleanly with standard fmt package printing functions. The
|
||||||
|
formatter is useful for inline printing of smaller data types similar to the
|
||||||
|
standard %v format specifier.
|
||||||
|
|
||||||
|
The custom formatter only responds to the %v (most compact), %+v (adds pointer
|
||||||
|
addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb
|
||||||
|
combinations. Any other verbs such as %x and %q will be sent to the the
|
||||||
|
standard fmt package for formatting. In addition, the custom formatter ignores
|
||||||
|
the width and precision arguments (however they will still work on the format
|
||||||
|
specifiers not handled by the custom formatter).
|
||||||
|
|
||||||
|
Custom Formatter Usage
|
||||||
|
|
||||||
|
The simplest way to make use of the spew custom formatter is to call one of the
|
||||||
|
convenience functions such as spew.Printf, spew.Println, or spew.Printf. The
|
||||||
|
functions have syntax you are most likely already familiar with:
|
||||||
|
|
||||||
|
spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
||||||
|
spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
||||||
|
spew.Println(myVar, myVar2)
|
||||||
|
spew.Fprintf(os.Stderr, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
||||||
|
spew.Fprintf(os.Stderr, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
||||||
|
|
||||||
|
See the Index for the full list convenience functions.
|
||||||
|
|
||||||
|
Sample Formatter Output
|
||||||
|
|
||||||
|
Double pointer to a uint8:
|
||||||
|
%v: <**>5
|
||||||
|
%+v: <**>(0xf8400420d0->0xf8400420c8)5
|
||||||
|
%#v: (**uint8)5
|
||||||
|
%#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5
|
||||||
|
|
||||||
|
Pointer to circular struct with a uint8 field and a pointer to itself:
|
||||||
|
%v: <*>{1 <*><shown>}
|
||||||
|
%+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)<shown>}
|
||||||
|
%#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)<shown>}
|
||||||
|
%#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)<shown>}
|
||||||
|
|
||||||
|
See the Printf example for details on the setup of variables being shown
|
||||||
|
here.
|
||||||
|
|
||||||
|
Errors
|
||||||
|
|
||||||
|
Since it is possible for custom Stringer/error interfaces to panic, spew
|
||||||
|
detects them and handles them internally by printing the panic information
|
||||||
|
inline with the output. Since spew is intended to provide deep pretty printing
|
||||||
|
capabilities on structures, it intentionally does not return any errors.
|
||||||
|
*/
|
||||||
|
package spew
|
||||||
509
vendor/github.com/davecgh/go-spew/spew/dump.go
generated
vendored
Normal file
509
vendor/github.com/davecgh/go-spew/spew/dump.go
generated
vendored
Normal file
@@ -0,0 +1,509 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package spew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// uint8Type is a reflect.Type representing a uint8. It is used to
|
||||||
|
// convert cgo types to uint8 slices for hexdumping.
|
||||||
|
uint8Type = reflect.TypeOf(uint8(0))
|
||||||
|
|
||||||
|
// cCharRE is a regular expression that matches a cgo char.
|
||||||
|
// It is used to detect character arrays to hexdump them.
|
||||||
|
cCharRE = regexp.MustCompile(`^.*\._Ctype_char$`)
|
||||||
|
|
||||||
|
// cUnsignedCharRE is a regular expression that matches a cgo unsigned
|
||||||
|
// char. It is used to detect unsigned character arrays to hexdump
|
||||||
|
// them.
|
||||||
|
cUnsignedCharRE = regexp.MustCompile(`^.*\._Ctype_unsignedchar$`)
|
||||||
|
|
||||||
|
// cUint8tCharRE is a regular expression that matches a cgo uint8_t.
|
||||||
|
// It is used to detect uint8_t arrays to hexdump them.
|
||||||
|
cUint8tCharRE = regexp.MustCompile(`^.*\._Ctype_uint8_t$`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// dumpState contains information about the state of a dump operation.
|
||||||
|
type dumpState struct {
|
||||||
|
w io.Writer
|
||||||
|
depth int
|
||||||
|
pointers map[uintptr]int
|
||||||
|
ignoreNextType bool
|
||||||
|
ignoreNextIndent bool
|
||||||
|
cs *ConfigState
|
||||||
|
}
|
||||||
|
|
||||||
|
// indent performs indentation according to the depth level and cs.Indent
|
||||||
|
// option.
|
||||||
|
func (d *dumpState) indent() {
|
||||||
|
if d.ignoreNextIndent {
|
||||||
|
d.ignoreNextIndent = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth))
|
||||||
|
}
|
||||||
|
|
||||||
|
// unpackValue returns values inside of non-nil interfaces when possible.
|
||||||
|
// This is useful for data types like structs, arrays, slices, and maps which
|
||||||
|
// can contain varying types packed inside an interface.
|
||||||
|
func (d *dumpState) unpackValue(v reflect.Value) reflect.Value {
|
||||||
|
if v.Kind() == reflect.Interface && !v.IsNil() {
|
||||||
|
v = v.Elem()
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// dumpPtr handles formatting of pointers by indirecting them as necessary.
|
||||||
|
func (d *dumpState) dumpPtr(v reflect.Value) {
|
||||||
|
// Remove pointers at or below the current depth from map used to detect
|
||||||
|
// circular refs.
|
||||||
|
for k, depth := range d.pointers {
|
||||||
|
if depth >= d.depth {
|
||||||
|
delete(d.pointers, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep list of all dereferenced pointers to show later.
|
||||||
|
pointerChain := make([]uintptr, 0)
|
||||||
|
|
||||||
|
// Figure out how many levels of indirection there are by dereferencing
|
||||||
|
// pointers and unpacking interfaces down the chain while detecting circular
|
||||||
|
// references.
|
||||||
|
nilFound := false
|
||||||
|
cycleFound := false
|
||||||
|
indirects := 0
|
||||||
|
ve := v
|
||||||
|
for ve.Kind() == reflect.Ptr {
|
||||||
|
if ve.IsNil() {
|
||||||
|
nilFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
indirects++
|
||||||
|
addr := ve.Pointer()
|
||||||
|
pointerChain = append(pointerChain, addr)
|
||||||
|
if pd, ok := d.pointers[addr]; ok && pd < d.depth {
|
||||||
|
cycleFound = true
|
||||||
|
indirects--
|
||||||
|
break
|
||||||
|
}
|
||||||
|
d.pointers[addr] = d.depth
|
||||||
|
|
||||||
|
ve = ve.Elem()
|
||||||
|
if ve.Kind() == reflect.Interface {
|
||||||
|
if ve.IsNil() {
|
||||||
|
nilFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
ve = ve.Elem()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display type information.
|
||||||
|
d.w.Write(openParenBytes)
|
||||||
|
d.w.Write(bytes.Repeat(asteriskBytes, indirects))
|
||||||
|
d.w.Write([]byte(ve.Type().String()))
|
||||||
|
d.w.Write(closeParenBytes)
|
||||||
|
|
||||||
|
// Display pointer information.
|
||||||
|
if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 {
|
||||||
|
d.w.Write(openParenBytes)
|
||||||
|
for i, addr := range pointerChain {
|
||||||
|
if i > 0 {
|
||||||
|
d.w.Write(pointerChainBytes)
|
||||||
|
}
|
||||||
|
printHexPtr(d.w, addr)
|
||||||
|
}
|
||||||
|
d.w.Write(closeParenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display dereferenced value.
|
||||||
|
d.w.Write(openParenBytes)
|
||||||
|
switch {
|
||||||
|
case nilFound:
|
||||||
|
d.w.Write(nilAngleBytes)
|
||||||
|
|
||||||
|
case cycleFound:
|
||||||
|
d.w.Write(circularBytes)
|
||||||
|
|
||||||
|
default:
|
||||||
|
d.ignoreNextType = true
|
||||||
|
d.dump(ve)
|
||||||
|
}
|
||||||
|
d.w.Write(closeParenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// dumpSlice handles formatting of arrays and slices. Byte (uint8 under
|
||||||
|
// reflection) arrays and slices are dumped in hexdump -C fashion.
|
||||||
|
func (d *dumpState) dumpSlice(v reflect.Value) {
|
||||||
|
// Determine whether this type should be hex dumped or not. Also,
|
||||||
|
// for types which should be hexdumped, try to use the underlying data
|
||||||
|
// first, then fall back to trying to convert them to a uint8 slice.
|
||||||
|
var buf []uint8
|
||||||
|
doConvert := false
|
||||||
|
doHexDump := false
|
||||||
|
numEntries := v.Len()
|
||||||
|
if numEntries > 0 {
|
||||||
|
vt := v.Index(0).Type()
|
||||||
|
vts := vt.String()
|
||||||
|
switch {
|
||||||
|
// C types that need to be converted.
|
||||||
|
case cCharRE.MatchString(vts):
|
||||||
|
fallthrough
|
||||||
|
case cUnsignedCharRE.MatchString(vts):
|
||||||
|
fallthrough
|
||||||
|
case cUint8tCharRE.MatchString(vts):
|
||||||
|
doConvert = true
|
||||||
|
|
||||||
|
// Try to use existing uint8 slices and fall back to converting
|
||||||
|
// and copying if that fails.
|
||||||
|
case vt.Kind() == reflect.Uint8:
|
||||||
|
// We need an addressable interface to convert the type
|
||||||
|
// to a byte slice. However, the reflect package won't
|
||||||
|
// give us an interface on certain things like
|
||||||
|
// unexported struct fields in order to enforce
|
||||||
|
// visibility rules. We use unsafe, when available, to
|
||||||
|
// bypass these restrictions since this package does not
|
||||||
|
// mutate the values.
|
||||||
|
vs := v
|
||||||
|
if !vs.CanInterface() || !vs.CanAddr() {
|
||||||
|
vs = unsafeReflectValue(vs)
|
||||||
|
}
|
||||||
|
if !UnsafeDisabled {
|
||||||
|
vs = vs.Slice(0, numEntries)
|
||||||
|
|
||||||
|
// Use the existing uint8 slice if it can be
|
||||||
|
// type asserted.
|
||||||
|
iface := vs.Interface()
|
||||||
|
if slice, ok := iface.([]uint8); ok {
|
||||||
|
buf = slice
|
||||||
|
doHexDump = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The underlying data needs to be converted if it can't
|
||||||
|
// be type asserted to a uint8 slice.
|
||||||
|
doConvert = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy and convert the underlying type if needed.
|
||||||
|
if doConvert && vt.ConvertibleTo(uint8Type) {
|
||||||
|
// Convert and copy each element into a uint8 byte
|
||||||
|
// slice.
|
||||||
|
buf = make([]uint8, numEntries)
|
||||||
|
for i := 0; i < numEntries; i++ {
|
||||||
|
vv := v.Index(i)
|
||||||
|
buf[i] = uint8(vv.Convert(uint8Type).Uint())
|
||||||
|
}
|
||||||
|
doHexDump = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hexdump the entire slice as needed.
|
||||||
|
if doHexDump {
|
||||||
|
indent := strings.Repeat(d.cs.Indent, d.depth)
|
||||||
|
str := indent + hex.Dump(buf)
|
||||||
|
str = strings.Replace(str, "\n", "\n"+indent, -1)
|
||||||
|
str = strings.TrimRight(str, d.cs.Indent)
|
||||||
|
d.w.Write([]byte(str))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursively call dump for each item.
|
||||||
|
for i := 0; i < numEntries; i++ {
|
||||||
|
d.dump(d.unpackValue(v.Index(i)))
|
||||||
|
if i < (numEntries - 1) {
|
||||||
|
d.w.Write(commaNewlineBytes)
|
||||||
|
} else {
|
||||||
|
d.w.Write(newlineBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// dump is the main workhorse for dumping a value. It uses the passed reflect
|
||||||
|
// value to figure out what kind of object we are dealing with and formats it
|
||||||
|
// appropriately. It is a recursive function, however circular data structures
|
||||||
|
// are detected and handled properly.
|
||||||
|
func (d *dumpState) dump(v reflect.Value) {
|
||||||
|
// Handle invalid reflect values immediately.
|
||||||
|
kind := v.Kind()
|
||||||
|
if kind == reflect.Invalid {
|
||||||
|
d.w.Write(invalidAngleBytes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle pointers specially.
|
||||||
|
if kind == reflect.Ptr {
|
||||||
|
d.indent()
|
||||||
|
d.dumpPtr(v)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print type information unless already handled elsewhere.
|
||||||
|
if !d.ignoreNextType {
|
||||||
|
d.indent()
|
||||||
|
d.w.Write(openParenBytes)
|
||||||
|
d.w.Write([]byte(v.Type().String()))
|
||||||
|
d.w.Write(closeParenBytes)
|
||||||
|
d.w.Write(spaceBytes)
|
||||||
|
}
|
||||||
|
d.ignoreNextType = false
|
||||||
|
|
||||||
|
// Display length and capacity if the built-in len and cap functions
|
||||||
|
// work with the value's kind and the len/cap itself is non-zero.
|
||||||
|
valueLen, valueCap := 0, 0
|
||||||
|
switch v.Kind() {
|
||||||
|
case reflect.Array, reflect.Slice, reflect.Chan:
|
||||||
|
valueLen, valueCap = v.Len(), v.Cap()
|
||||||
|
case reflect.Map, reflect.String:
|
||||||
|
valueLen = v.Len()
|
||||||
|
}
|
||||||
|
if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 {
|
||||||
|
d.w.Write(openParenBytes)
|
||||||
|
if valueLen != 0 {
|
||||||
|
d.w.Write(lenEqualsBytes)
|
||||||
|
printInt(d.w, int64(valueLen), 10)
|
||||||
|
}
|
||||||
|
if !d.cs.DisableCapacities && valueCap != 0 {
|
||||||
|
if valueLen != 0 {
|
||||||
|
d.w.Write(spaceBytes)
|
||||||
|
}
|
||||||
|
d.w.Write(capEqualsBytes)
|
||||||
|
printInt(d.w, int64(valueCap), 10)
|
||||||
|
}
|
||||||
|
d.w.Write(closeParenBytes)
|
||||||
|
d.w.Write(spaceBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call Stringer/error interfaces if they exist and the handle methods flag
|
||||||
|
// is enabled
|
||||||
|
if !d.cs.DisableMethods {
|
||||||
|
if (kind != reflect.Invalid) && (kind != reflect.Interface) {
|
||||||
|
if handled := handleMethods(d.cs, d.w, v); handled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch kind {
|
||||||
|
case reflect.Invalid:
|
||||||
|
// Do nothing. We should never get here since invalid has already
|
||||||
|
// been handled above.
|
||||||
|
|
||||||
|
case reflect.Bool:
|
||||||
|
printBool(d.w, v.Bool())
|
||||||
|
|
||||||
|
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
|
||||||
|
printInt(d.w, v.Int(), 10)
|
||||||
|
|
||||||
|
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
|
||||||
|
printUint(d.w, v.Uint(), 10)
|
||||||
|
|
||||||
|
case reflect.Float32:
|
||||||
|
printFloat(d.w, v.Float(), 32)
|
||||||
|
|
||||||
|
case reflect.Float64:
|
||||||
|
printFloat(d.w, v.Float(), 64)
|
||||||
|
|
||||||
|
case reflect.Complex64:
|
||||||
|
printComplex(d.w, v.Complex(), 32)
|
||||||
|
|
||||||
|
case reflect.Complex128:
|
||||||
|
printComplex(d.w, v.Complex(), 64)
|
||||||
|
|
||||||
|
case reflect.Slice:
|
||||||
|
if v.IsNil() {
|
||||||
|
d.w.Write(nilAngleBytes)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
|
||||||
|
case reflect.Array:
|
||||||
|
d.w.Write(openBraceNewlineBytes)
|
||||||
|
d.depth++
|
||||||
|
if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
|
||||||
|
d.indent()
|
||||||
|
d.w.Write(maxNewlineBytes)
|
||||||
|
} else {
|
||||||
|
d.dumpSlice(v)
|
||||||
|
}
|
||||||
|
d.depth--
|
||||||
|
d.indent()
|
||||||
|
d.w.Write(closeBraceBytes)
|
||||||
|
|
||||||
|
case reflect.String:
|
||||||
|
d.w.Write([]byte(strconv.Quote(v.String())))
|
||||||
|
|
||||||
|
case reflect.Interface:
|
||||||
|
// The only time we should get here is for nil interfaces due to
|
||||||
|
// unpackValue calls.
|
||||||
|
if v.IsNil() {
|
||||||
|
d.w.Write(nilAngleBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
case reflect.Ptr:
|
||||||
|
// Do nothing. We should never get here since pointers have already
|
||||||
|
// been handled above.
|
||||||
|
|
||||||
|
case reflect.Map:
|
||||||
|
// nil maps should be indicated as different than empty maps
|
||||||
|
if v.IsNil() {
|
||||||
|
d.w.Write(nilAngleBytes)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
d.w.Write(openBraceNewlineBytes)
|
||||||
|
d.depth++
|
||||||
|
if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
|
||||||
|
d.indent()
|
||||||
|
d.w.Write(maxNewlineBytes)
|
||||||
|
} else {
|
||||||
|
numEntries := v.Len()
|
||||||
|
keys := v.MapKeys()
|
||||||
|
if d.cs.SortKeys {
|
||||||
|
sortValues(keys, d.cs)
|
||||||
|
}
|
||||||
|
for i, key := range keys {
|
||||||
|
d.dump(d.unpackValue(key))
|
||||||
|
d.w.Write(colonSpaceBytes)
|
||||||
|
d.ignoreNextIndent = true
|
||||||
|
d.dump(d.unpackValue(v.MapIndex(key)))
|
||||||
|
if i < (numEntries - 1) {
|
||||||
|
d.w.Write(commaNewlineBytes)
|
||||||
|
} else {
|
||||||
|
d.w.Write(newlineBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.depth--
|
||||||
|
d.indent()
|
||||||
|
d.w.Write(closeBraceBytes)
|
||||||
|
|
||||||
|
case reflect.Struct:
|
||||||
|
d.w.Write(openBraceNewlineBytes)
|
||||||
|
d.depth++
|
||||||
|
if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) {
|
||||||
|
d.indent()
|
||||||
|
d.w.Write(maxNewlineBytes)
|
||||||
|
} else {
|
||||||
|
vt := v.Type()
|
||||||
|
numFields := v.NumField()
|
||||||
|
for i := 0; i < numFields; i++ {
|
||||||
|
d.indent()
|
||||||
|
vtf := vt.Field(i)
|
||||||
|
d.w.Write([]byte(vtf.Name))
|
||||||
|
d.w.Write(colonSpaceBytes)
|
||||||
|
d.ignoreNextIndent = true
|
||||||
|
d.dump(d.unpackValue(v.Field(i)))
|
||||||
|
if i < (numFields - 1) {
|
||||||
|
d.w.Write(commaNewlineBytes)
|
||||||
|
} else {
|
||||||
|
d.w.Write(newlineBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.depth--
|
||||||
|
d.indent()
|
||||||
|
d.w.Write(closeBraceBytes)
|
||||||
|
|
||||||
|
case reflect.Uintptr:
|
||||||
|
printHexPtr(d.w, uintptr(v.Uint()))
|
||||||
|
|
||||||
|
case reflect.UnsafePointer, reflect.Chan, reflect.Func:
|
||||||
|
printHexPtr(d.w, v.Pointer())
|
||||||
|
|
||||||
|
// There were not any other types at the time this code was written, but
|
||||||
|
// fall back to letting the default fmt package handle it in case any new
|
||||||
|
// types are added.
|
||||||
|
default:
|
||||||
|
if v.CanInterface() {
|
||||||
|
fmt.Fprintf(d.w, "%v", v.Interface())
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(d.w, "%v", v.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fdump is a helper function to consolidate the logic from the various public
|
||||||
|
// methods which take varying writers and config states.
|
||||||
|
func fdump(cs *ConfigState, w io.Writer, a ...interface{}) {
|
||||||
|
for _, arg := range a {
|
||||||
|
if arg == nil {
|
||||||
|
w.Write(interfaceBytes)
|
||||||
|
w.Write(spaceBytes)
|
||||||
|
w.Write(nilAngleBytes)
|
||||||
|
w.Write(newlineBytes)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
d := dumpState{w: w, cs: cs}
|
||||||
|
d.pointers = make(map[uintptr]int)
|
||||||
|
d.dump(reflect.ValueOf(arg))
|
||||||
|
d.w.Write(newlineBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fdump formats and displays the passed arguments to io.Writer w. It formats
|
||||||
|
// exactly the same as Dump.
|
||||||
|
func Fdump(w io.Writer, a ...interface{}) {
|
||||||
|
fdump(&Config, w, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sdump returns a string with the passed arguments formatted exactly the same
|
||||||
|
// as Dump.
|
||||||
|
func Sdump(a ...interface{}) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fdump(&Config, &buf, a...)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Dump displays the passed parameters to standard out with newlines, customizable
|
||||||
|
indentation, and additional debug information such as complete types and all
|
||||||
|
pointer addresses used to indirect to the final value. It provides the
|
||||||
|
following features over the built-in printing facilities provided by the fmt
|
||||||
|
package:
|
||||||
|
|
||||||
|
* Pointers are dereferenced and followed
|
||||||
|
* Circular data structures are detected and handled properly
|
||||||
|
* Custom Stringer/error interfaces are optionally invoked, including
|
||||||
|
on unexported types
|
||||||
|
* Custom types which only implement the Stringer/error interfaces via
|
||||||
|
a pointer receiver are optionally invoked when passing non-pointer
|
||||||
|
variables
|
||||||
|
* Byte arrays and slices are dumped like the hexdump -C command which
|
||||||
|
includes offsets, byte values in hex, and ASCII output
|
||||||
|
|
||||||
|
The configuration options are controlled by an exported package global,
|
||||||
|
spew.Config. See ConfigState for options documentation.
|
||||||
|
|
||||||
|
See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to
|
||||||
|
get the formatted result as a string.
|
||||||
|
*/
|
||||||
|
func Dump(a ...interface{}) {
|
||||||
|
fdump(&Config, os.Stdout, a...)
|
||||||
|
}
|
||||||
419
vendor/github.com/davecgh/go-spew/spew/format.go
generated
vendored
Normal file
419
vendor/github.com/davecgh/go-spew/spew/format.go
generated
vendored
Normal file
@@ -0,0 +1,419 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package spew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// supportedFlags is a list of all the character flags supported by fmt package.
|
||||||
|
const supportedFlags = "0-+# "
|
||||||
|
|
||||||
|
// formatState implements the fmt.Formatter interface and contains information
|
||||||
|
// about the state of a formatting operation. The NewFormatter function can
|
||||||
|
// be used to get a new Formatter which can be used directly as arguments
|
||||||
|
// in standard fmt package printing calls.
|
||||||
|
type formatState struct {
|
||||||
|
value interface{}
|
||||||
|
fs fmt.State
|
||||||
|
depth int
|
||||||
|
pointers map[uintptr]int
|
||||||
|
ignoreNextType bool
|
||||||
|
cs *ConfigState
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildDefaultFormat recreates the original format string without precision
|
||||||
|
// and width information to pass in to fmt.Sprintf in the case of an
|
||||||
|
// unrecognized type. Unless new types are added to the language, this
|
||||||
|
// function won't ever be called.
|
||||||
|
func (f *formatState) buildDefaultFormat() (format string) {
|
||||||
|
buf := bytes.NewBuffer(percentBytes)
|
||||||
|
|
||||||
|
for _, flag := range supportedFlags {
|
||||||
|
if f.fs.Flag(int(flag)) {
|
||||||
|
buf.WriteRune(flag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.WriteRune('v')
|
||||||
|
|
||||||
|
format = buf.String()
|
||||||
|
return format
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructOrigFormat recreates the original format string including precision
|
||||||
|
// and width information to pass along to the standard fmt package. This allows
|
||||||
|
// automatic deferral of all format strings this package doesn't support.
|
||||||
|
func (f *formatState) constructOrigFormat(verb rune) (format string) {
|
||||||
|
buf := bytes.NewBuffer(percentBytes)
|
||||||
|
|
||||||
|
for _, flag := range supportedFlags {
|
||||||
|
if f.fs.Flag(int(flag)) {
|
||||||
|
buf.WriteRune(flag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if width, ok := f.fs.Width(); ok {
|
||||||
|
buf.WriteString(strconv.Itoa(width))
|
||||||
|
}
|
||||||
|
|
||||||
|
if precision, ok := f.fs.Precision(); ok {
|
||||||
|
buf.Write(precisionBytes)
|
||||||
|
buf.WriteString(strconv.Itoa(precision))
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.WriteRune(verb)
|
||||||
|
|
||||||
|
format = buf.String()
|
||||||
|
return format
|
||||||
|
}
|
||||||
|
|
||||||
|
// unpackValue returns values inside of non-nil interfaces when possible and
|
||||||
|
// ensures that types for values which have been unpacked from an interface
|
||||||
|
// are displayed when the show types flag is also set.
|
||||||
|
// This is useful for data types like structs, arrays, slices, and maps which
|
||||||
|
// can contain varying types packed inside an interface.
|
||||||
|
func (f *formatState) unpackValue(v reflect.Value) reflect.Value {
|
||||||
|
if v.Kind() == reflect.Interface {
|
||||||
|
f.ignoreNextType = false
|
||||||
|
if !v.IsNil() {
|
||||||
|
v = v.Elem()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// formatPtr handles formatting of pointers by indirecting them as necessary.
|
||||||
|
func (f *formatState) formatPtr(v reflect.Value) {
|
||||||
|
// Display nil if top level pointer is nil.
|
||||||
|
showTypes := f.fs.Flag('#')
|
||||||
|
if v.IsNil() && (!showTypes || f.ignoreNextType) {
|
||||||
|
f.fs.Write(nilAngleBytes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove pointers at or below the current depth from map used to detect
|
||||||
|
// circular refs.
|
||||||
|
for k, depth := range f.pointers {
|
||||||
|
if depth >= f.depth {
|
||||||
|
delete(f.pointers, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep list of all dereferenced pointers to possibly show later.
|
||||||
|
pointerChain := make([]uintptr, 0)
|
||||||
|
|
||||||
|
// Figure out how many levels of indirection there are by derferencing
|
||||||
|
// pointers and unpacking interfaces down the chain while detecting circular
|
||||||
|
// references.
|
||||||
|
nilFound := false
|
||||||
|
cycleFound := false
|
||||||
|
indirects := 0
|
||||||
|
ve := v
|
||||||
|
for ve.Kind() == reflect.Ptr {
|
||||||
|
if ve.IsNil() {
|
||||||
|
nilFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
indirects++
|
||||||
|
addr := ve.Pointer()
|
||||||
|
pointerChain = append(pointerChain, addr)
|
||||||
|
if pd, ok := f.pointers[addr]; ok && pd < f.depth {
|
||||||
|
cycleFound = true
|
||||||
|
indirects--
|
||||||
|
break
|
||||||
|
}
|
||||||
|
f.pointers[addr] = f.depth
|
||||||
|
|
||||||
|
ve = ve.Elem()
|
||||||
|
if ve.Kind() == reflect.Interface {
|
||||||
|
if ve.IsNil() {
|
||||||
|
nilFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
ve = ve.Elem()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display type or indirection level depending on flags.
|
||||||
|
if showTypes && !f.ignoreNextType {
|
||||||
|
f.fs.Write(openParenBytes)
|
||||||
|
f.fs.Write(bytes.Repeat(asteriskBytes, indirects))
|
||||||
|
f.fs.Write([]byte(ve.Type().String()))
|
||||||
|
f.fs.Write(closeParenBytes)
|
||||||
|
} else {
|
||||||
|
if nilFound || cycleFound {
|
||||||
|
indirects += strings.Count(ve.Type().String(), "*")
|
||||||
|
}
|
||||||
|
f.fs.Write(openAngleBytes)
|
||||||
|
f.fs.Write([]byte(strings.Repeat("*", indirects)))
|
||||||
|
f.fs.Write(closeAngleBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display pointer information depending on flags.
|
||||||
|
if f.fs.Flag('+') && (len(pointerChain) > 0) {
|
||||||
|
f.fs.Write(openParenBytes)
|
||||||
|
for i, addr := range pointerChain {
|
||||||
|
if i > 0 {
|
||||||
|
f.fs.Write(pointerChainBytes)
|
||||||
|
}
|
||||||
|
printHexPtr(f.fs, addr)
|
||||||
|
}
|
||||||
|
f.fs.Write(closeParenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display dereferenced value.
|
||||||
|
switch {
|
||||||
|
case nilFound:
|
||||||
|
f.fs.Write(nilAngleBytes)
|
||||||
|
|
||||||
|
case cycleFound:
|
||||||
|
f.fs.Write(circularShortBytes)
|
||||||
|
|
||||||
|
default:
|
||||||
|
f.ignoreNextType = true
|
||||||
|
f.format(ve)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// format is the main workhorse for providing the Formatter interface. It
|
||||||
|
// uses the passed reflect value to figure out what kind of object we are
|
||||||
|
// dealing with and formats it appropriately. It is a recursive function,
|
||||||
|
// however circular data structures are detected and handled properly.
|
||||||
|
func (f *formatState) format(v reflect.Value) {
|
||||||
|
// Handle invalid reflect values immediately.
|
||||||
|
kind := v.Kind()
|
||||||
|
if kind == reflect.Invalid {
|
||||||
|
f.fs.Write(invalidAngleBytes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle pointers specially.
|
||||||
|
if kind == reflect.Ptr {
|
||||||
|
f.formatPtr(v)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print type information unless already handled elsewhere.
|
||||||
|
if !f.ignoreNextType && f.fs.Flag('#') {
|
||||||
|
f.fs.Write(openParenBytes)
|
||||||
|
f.fs.Write([]byte(v.Type().String()))
|
||||||
|
f.fs.Write(closeParenBytes)
|
||||||
|
}
|
||||||
|
f.ignoreNextType = false
|
||||||
|
|
||||||
|
// Call Stringer/error interfaces if they exist and the handle methods
|
||||||
|
// flag is enabled.
|
||||||
|
if !f.cs.DisableMethods {
|
||||||
|
if (kind != reflect.Invalid) && (kind != reflect.Interface) {
|
||||||
|
if handled := handleMethods(f.cs, f.fs, v); handled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch kind {
|
||||||
|
case reflect.Invalid:
|
||||||
|
// Do nothing. We should never get here since invalid has already
|
||||||
|
// been handled above.
|
||||||
|
|
||||||
|
case reflect.Bool:
|
||||||
|
printBool(f.fs, v.Bool())
|
||||||
|
|
||||||
|
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
|
||||||
|
printInt(f.fs, v.Int(), 10)
|
||||||
|
|
||||||
|
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
|
||||||
|
printUint(f.fs, v.Uint(), 10)
|
||||||
|
|
||||||
|
case reflect.Float32:
|
||||||
|
printFloat(f.fs, v.Float(), 32)
|
||||||
|
|
||||||
|
case reflect.Float64:
|
||||||
|
printFloat(f.fs, v.Float(), 64)
|
||||||
|
|
||||||
|
case reflect.Complex64:
|
||||||
|
printComplex(f.fs, v.Complex(), 32)
|
||||||
|
|
||||||
|
case reflect.Complex128:
|
||||||
|
printComplex(f.fs, v.Complex(), 64)
|
||||||
|
|
||||||
|
case reflect.Slice:
|
||||||
|
if v.IsNil() {
|
||||||
|
f.fs.Write(nilAngleBytes)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
|
||||||
|
case reflect.Array:
|
||||||
|
f.fs.Write(openBracketBytes)
|
||||||
|
f.depth++
|
||||||
|
if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) {
|
||||||
|
f.fs.Write(maxShortBytes)
|
||||||
|
} else {
|
||||||
|
numEntries := v.Len()
|
||||||
|
for i := 0; i < numEntries; i++ {
|
||||||
|
if i > 0 {
|
||||||
|
f.fs.Write(spaceBytes)
|
||||||
|
}
|
||||||
|
f.ignoreNextType = true
|
||||||
|
f.format(f.unpackValue(v.Index(i)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.depth--
|
||||||
|
f.fs.Write(closeBracketBytes)
|
||||||
|
|
||||||
|
case reflect.String:
|
||||||
|
f.fs.Write([]byte(v.String()))
|
||||||
|
|
||||||
|
case reflect.Interface:
|
||||||
|
// The only time we should get here is for nil interfaces due to
|
||||||
|
// unpackValue calls.
|
||||||
|
if v.IsNil() {
|
||||||
|
f.fs.Write(nilAngleBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
case reflect.Ptr:
|
||||||
|
// Do nothing. We should never get here since pointers have already
|
||||||
|
// been handled above.
|
||||||
|
|
||||||
|
case reflect.Map:
|
||||||
|
// nil maps should be indicated as different than empty maps
|
||||||
|
if v.IsNil() {
|
||||||
|
f.fs.Write(nilAngleBytes)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
f.fs.Write(openMapBytes)
|
||||||
|
f.depth++
|
||||||
|
if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) {
|
||||||
|
f.fs.Write(maxShortBytes)
|
||||||
|
} else {
|
||||||
|
keys := v.MapKeys()
|
||||||
|
if f.cs.SortKeys {
|
||||||
|
sortValues(keys, f.cs)
|
||||||
|
}
|
||||||
|
for i, key := range keys {
|
||||||
|
if i > 0 {
|
||||||
|
f.fs.Write(spaceBytes)
|
||||||
|
}
|
||||||
|
f.ignoreNextType = true
|
||||||
|
f.format(f.unpackValue(key))
|
||||||
|
f.fs.Write(colonBytes)
|
||||||
|
f.ignoreNextType = true
|
||||||
|
f.format(f.unpackValue(v.MapIndex(key)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.depth--
|
||||||
|
f.fs.Write(closeMapBytes)
|
||||||
|
|
||||||
|
case reflect.Struct:
|
||||||
|
numFields := v.NumField()
|
||||||
|
f.fs.Write(openBraceBytes)
|
||||||
|
f.depth++
|
||||||
|
if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) {
|
||||||
|
f.fs.Write(maxShortBytes)
|
||||||
|
} else {
|
||||||
|
vt := v.Type()
|
||||||
|
for i := 0; i < numFields; i++ {
|
||||||
|
if i > 0 {
|
||||||
|
f.fs.Write(spaceBytes)
|
||||||
|
}
|
||||||
|
vtf := vt.Field(i)
|
||||||
|
if f.fs.Flag('+') || f.fs.Flag('#') {
|
||||||
|
f.fs.Write([]byte(vtf.Name))
|
||||||
|
f.fs.Write(colonBytes)
|
||||||
|
}
|
||||||
|
f.format(f.unpackValue(v.Field(i)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.depth--
|
||||||
|
f.fs.Write(closeBraceBytes)
|
||||||
|
|
||||||
|
case reflect.Uintptr:
|
||||||
|
printHexPtr(f.fs, uintptr(v.Uint()))
|
||||||
|
|
||||||
|
case reflect.UnsafePointer, reflect.Chan, reflect.Func:
|
||||||
|
printHexPtr(f.fs, v.Pointer())
|
||||||
|
|
||||||
|
// There were not any other types at the time this code was written, but
|
||||||
|
// fall back to letting the default fmt package handle it if any get added.
|
||||||
|
default:
|
||||||
|
format := f.buildDefaultFormat()
|
||||||
|
if v.CanInterface() {
|
||||||
|
fmt.Fprintf(f.fs, format, v.Interface())
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(f.fs, format, v.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format satisfies the fmt.Formatter interface. See NewFormatter for usage
|
||||||
|
// details.
|
||||||
|
func (f *formatState) Format(fs fmt.State, verb rune) {
|
||||||
|
f.fs = fs
|
||||||
|
|
||||||
|
// Use standard formatting for verbs that are not v.
|
||||||
|
if verb != 'v' {
|
||||||
|
format := f.constructOrigFormat(verb)
|
||||||
|
fmt.Fprintf(fs, format, f.value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.value == nil {
|
||||||
|
if fs.Flag('#') {
|
||||||
|
fs.Write(interfaceBytes)
|
||||||
|
}
|
||||||
|
fs.Write(nilAngleBytes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f.format(reflect.ValueOf(f.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
// newFormatter is a helper function to consolidate the logic from the various
|
||||||
|
// public methods which take varying config states.
|
||||||
|
func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter {
|
||||||
|
fs := &formatState{value: v, cs: cs}
|
||||||
|
fs.pointers = make(map[uintptr]int)
|
||||||
|
return fs
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
NewFormatter returns a custom formatter that satisfies the fmt.Formatter
|
||||||
|
interface. As a result, it integrates cleanly with standard fmt package
|
||||||
|
printing functions. The formatter is useful for inline printing of smaller data
|
||||||
|
types similar to the standard %v format specifier.
|
||||||
|
|
||||||
|
The custom formatter only responds to the %v (most compact), %+v (adds pointer
|
||||||
|
addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb
|
||||||
|
combinations. Any other verbs such as %x and %q will be sent to the the
|
||||||
|
standard fmt package for formatting. In addition, the custom formatter ignores
|
||||||
|
the width and precision arguments (however they will still work on the format
|
||||||
|
specifiers not handled by the custom formatter).
|
||||||
|
|
||||||
|
Typically this function shouldn't be called directly. It is much easier to make
|
||||||
|
use of the custom formatter by calling one of the convenience functions such as
|
||||||
|
Printf, Println, or Fprintf.
|
||||||
|
*/
|
||||||
|
func NewFormatter(v interface{}) fmt.Formatter {
|
||||||
|
return newFormatter(&Config, v)
|
||||||
|
}
|
||||||
148
vendor/github.com/davecgh/go-spew/spew/spew.go
generated
vendored
Normal file
148
vendor/github.com/davecgh/go-spew/spew/spew.go
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package spew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the formatted string as a value that satisfies error. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Errorf(format string, a ...interface{}) (err error) {
|
||||||
|
return fmt.Errorf(format, convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprint(w, convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprintf(w, format, convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Fprintln(w, convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print is a wrapper for fmt.Print that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Print(a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Print(convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printf is a wrapper for fmt.Printf that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Printf(format string, a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Printf(format, convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Println is a wrapper for fmt.Println that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the number of bytes written and any write error encountered. See
|
||||||
|
// NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Println(a ...interface{}) (n int, err error) {
|
||||||
|
return fmt.Println(convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the resulting string. See NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Sprint(a ...interface{}) string {
|
||||||
|
return fmt.Sprint(convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were
|
||||||
|
// passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the resulting string. See NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Sprintf(format string, a ...interface{}) string {
|
||||||
|
return fmt.Sprintf(format, convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it
|
||||||
|
// were passed with a default Formatter interface returned by NewFormatter. It
|
||||||
|
// returns the resulting string. See NewFormatter for formatting details.
|
||||||
|
//
|
||||||
|
// This function is shorthand for the following syntax:
|
||||||
|
//
|
||||||
|
// fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b))
|
||||||
|
func Sprintln(a ...interface{}) string {
|
||||||
|
return fmt.Sprintln(convertArgs(a)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertArgs accepts a slice of arguments and returns a slice of the same
|
||||||
|
// length with each argument converted to a default spew Formatter interface.
|
||||||
|
func convertArgs(args []interface{}) (formatters []interface{}) {
|
||||||
|
formatters = make([]interface{}, len(args))
|
||||||
|
for index, arg := range args {
|
||||||
|
formatters[index] = NewFormatter(arg)
|
||||||
|
}
|
||||||
|
return formatters
|
||||||
|
}
|
||||||
36
vendor/github.com/eclipse/paho.mqtt.golang/.gitignore
generated
vendored
Normal file
36
vendor/github.com/eclipse/paho.mqtt.golang/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Folders
|
||||||
|
_obj
|
||||||
|
_test
|
||||||
|
|
||||||
|
# Architecture specific extensions/prefixes
|
||||||
|
*.[568vq]
|
||||||
|
[568vq].out
|
||||||
|
|
||||||
|
*.cgo1.go
|
||||||
|
*.cgo2.c
|
||||||
|
_cgo_defun.c
|
||||||
|
_cgo_gotypes.go
|
||||||
|
_cgo_export.*
|
||||||
|
|
||||||
|
_testmain.go
|
||||||
|
|
||||||
|
*.exe
|
||||||
|
|
||||||
|
*.msg
|
||||||
|
*.lok
|
||||||
|
|
||||||
|
samples/trivial
|
||||||
|
samples/trivial2
|
||||||
|
samples/sample
|
||||||
|
samples/reconnect
|
||||||
|
samples/ssl
|
||||||
|
samples/custom_store
|
||||||
|
samples/simple
|
||||||
|
samples/stdinpub
|
||||||
|
samples/stdoutsub
|
||||||
|
samples/routing
|
||||||
56
vendor/github.com/eclipse/paho.mqtt.golang/CONTRIBUTING.md
generated
vendored
Normal file
56
vendor/github.com/eclipse/paho.mqtt.golang/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
Contributing to Paho
|
||||||
|
====================
|
||||||
|
|
||||||
|
Thanks for your interest in this project.
|
||||||
|
|
||||||
|
Project description:
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
The Paho project has been created to provide scalable open-source implementations of open and standard messaging protocols aimed at new, existing, and emerging applications for Machine-to-Machine (M2M) and Internet of Things (IoT).
|
||||||
|
Paho reflects the inherent physical and cost constraints of device connectivity. Its objectives include effective levels of decoupling between devices and applications, designed to keep markets open and encourage the rapid growth of scalable Web and Enterprise middleware and applications. Paho is being kicked off with MQTT publish/subscribe client implementations for use on embedded platforms, along with corresponding server support as determined by the community.
|
||||||
|
|
||||||
|
- https://projects.eclipse.org/projects/technology.paho
|
||||||
|
|
||||||
|
Developer resources:
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Information regarding source code management, builds, coding standards, and more.
|
||||||
|
|
||||||
|
- https://projects.eclipse.org/projects/technology.paho/developer
|
||||||
|
|
||||||
|
Contributor License Agreement:
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
Before your contribution can be accepted by the project, you need to create and electronically sign the Eclipse Foundation Contributor License Agreement (CLA).
|
||||||
|
|
||||||
|
- http://www.eclipse.org/legal/CLA.php
|
||||||
|
|
||||||
|
Contributing Code:
|
||||||
|
------------------
|
||||||
|
|
||||||
|
The Go client is developed in Github, see their documentation on the process of forking and pull requests; https://help.github.com/categories/collaborating-on-projects-using-pull-requests/
|
||||||
|
|
||||||
|
Git commit messages should follow the style described here;
|
||||||
|
|
||||||
|
http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
||||||
|
|
||||||
|
Contact:
|
||||||
|
--------
|
||||||
|
|
||||||
|
Contact the project developers via the project's "dev" list.
|
||||||
|
|
||||||
|
- https://dev.eclipse.org/mailman/listinfo/paho-dev
|
||||||
|
|
||||||
|
Search for bugs:
|
||||||
|
----------------
|
||||||
|
|
||||||
|
This project uses Github issues to track ongoing development and issues.
|
||||||
|
|
||||||
|
- https://github.com/eclipse/paho.mqtt.golang/issues
|
||||||
|
|
||||||
|
Create a new bug:
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Be sure to search for existing bugs before you create another one. Remember that contributions are always welcome!
|
||||||
|
|
||||||
|
- https://github.com/eclipse/paho.mqtt.golang/issues
|
||||||
15
vendor/github.com/eclipse/paho.mqtt.golang/DISTRIBUTION
generated
vendored
Normal file
15
vendor/github.com/eclipse/paho.mqtt.golang/DISTRIBUTION
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
Eclipse Distribution License - v 1.0
|
||||||
|
|
||||||
|
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
20
vendor/github.com/eclipse/paho.mqtt.golang/LICENSE
generated
vendored
Normal file
20
vendor/github.com/eclipse/paho.mqtt.golang/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
This project is dual licensed under the Eclipse Public License 1.0 and the
|
||||||
|
Eclipse Distribution License 1.0 as described in the epl-v10 and edl-v10 files.
|
||||||
|
|
||||||
|
The EDL is copied below in order to pass the pkg.go.dev license check (https://pkg.go.dev/license-policy).
|
||||||
|
|
||||||
|
****
|
||||||
|
Eclipse Distribution License - v 1.0
|
||||||
|
|
||||||
|
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
177
vendor/github.com/eclipse/paho.mqtt.golang/README.md
generated
vendored
Normal file
177
vendor/github.com/eclipse/paho.mqtt.golang/README.md
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
|
||||||
|
[](https://pkg.go.dev/github.com/eclipse/paho.mqtt.golang)
|
||||||
|
[](https://goreportcard.com/report/github.com/eclipse/paho.mqtt.golang)
|
||||||
|
|
||||||
|
Eclipse Paho MQTT Go client
|
||||||
|
===========================
|
||||||
|
|
||||||
|
|
||||||
|
This repository contains the source code for the [Eclipse Paho](https://eclipse.org/paho) MQTT 3.1/3.11 Go client library.
|
||||||
|
|
||||||
|
This code builds a library which enable applications to connect to an [MQTT](https://mqtt.org) broker to publish
|
||||||
|
messages, and to subscribe to topics and receive published messages.
|
||||||
|
|
||||||
|
This library supports a fully asynchronous mode of operation.
|
||||||
|
|
||||||
|
A client supporting MQTT V5 is [also available](https://github.com/eclipse/paho.golang).
|
||||||
|
|
||||||
|
Installation and Build
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
The process depends upon whether you are using [modules](https://golang.org/ref/mod) (recommended) or `GOPATH`.
|
||||||
|
|
||||||
|
#### Modules
|
||||||
|
|
||||||
|
If you are using [modules](https://blog.golang.org/using-go-modules) then `import "github.com/eclipse/paho.mqtt.golang"`
|
||||||
|
and start using it. The necessary packages will be download automatically when you run `go build`.
|
||||||
|
|
||||||
|
Note that the latest release will be downloaded and changes may have been made since the release. If you have
|
||||||
|
encountered an issue, or wish to try the latest code for another reason, then run
|
||||||
|
`go get github.com/eclipse/paho.mqtt.golang@master` to get the latest commit.
|
||||||
|
|
||||||
|
#### GOPATH
|
||||||
|
|
||||||
|
Installation is as easy as:
|
||||||
|
|
||||||
|
```
|
||||||
|
go get github.com/eclipse/paho.mqtt.golang
|
||||||
|
```
|
||||||
|
|
||||||
|
The client depends on Google's [proxy](https://godoc.org/golang.org/x/net/proxy) package and the
|
||||||
|
[websockets](https://godoc.org/github.com/gorilla/websocket) package, also easily installed with the commands:
|
||||||
|
|
||||||
|
```
|
||||||
|
go get github.com/gorilla/websocket
|
||||||
|
go get golang.org/x/net/proxy
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Usage and API
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Detailed API documentation is available by using to godoc tool, or can be browsed online
|
||||||
|
using the [pkg.go.dev](https://pkg.go.dev/github.com/eclipse/paho.mqtt.golang) service.
|
||||||
|
|
||||||
|
Samples are available in the `cmd` directory for reference.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
|
||||||
|
The library also supports using MQTT over websockets by using the `ws://` (unsecure) or `wss://` (secure) prefix in the
|
||||||
|
URI. If the client is running behind a corporate http/https proxy then the following environment variables `HTTP_PROXY`,
|
||||||
|
`HTTPS_PROXY` and `NO_PROXY` are taken into account when establishing the connection.
|
||||||
|
|
||||||
|
Troubleshooting
|
||||||
|
---------------
|
||||||
|
|
||||||
|
If you are new to MQTT and your application is not working as expected reviewing the
|
||||||
|
[MQTT specification](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html), which this library implements,
|
||||||
|
is a good first step. [MQTT.org](https://mqtt.org) has some [good resources](https://mqtt.org/getting-started/) that answer many
|
||||||
|
common questions.
|
||||||
|
|
||||||
|
### Error Handling
|
||||||
|
|
||||||
|
The asynchronous nature of this library makes it easy to forget to check for errors. Consider using a go routine to
|
||||||
|
log these:
|
||||||
|
|
||||||
|
```go
|
||||||
|
t := client.Publish("topic", qos, retained, msg)
|
||||||
|
go func() {
|
||||||
|
_ = t.Wait() // Can also use '<-t.Done()' in releases > 1.2.0
|
||||||
|
if t.Error() != nil {
|
||||||
|
log.Error(t.Error()) // Use your preferred logging technique (or just fmt.Printf)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Logging
|
||||||
|
|
||||||
|
If you are encountering issues then enabling logging, both within this library and on your broker, is a good way to
|
||||||
|
begin troubleshooting. This library can produce various levels of log by assigning the logging endpoints, ERROR,
|
||||||
|
CRITICAL, WARN and DEBUG. For example:
|
||||||
|
|
||||||
|
```go
|
||||||
|
func main() {
|
||||||
|
mqtt.ERROR = log.New(os.Stdout, "[ERROR] ", 0)
|
||||||
|
mqtt.CRITICAL = log.New(os.Stdout, "[CRIT] ", 0)
|
||||||
|
mqtt.WARN = log.New(os.Stdout, "[WARN] ", 0)
|
||||||
|
mqtt.DEBUG = log.New(os.Stdout, "[DEBUG] ", 0)
|
||||||
|
|
||||||
|
// Connect, Subscribe, Publish etc..
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common Problems
|
||||||
|
|
||||||
|
* Seemingly random disconnections may be caused by another client connecting to the broker with the same client
|
||||||
|
identifier; this is as per the [spec](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc384800405).
|
||||||
|
* Unless ordered delivery of messages is essential (and you have configured your broker to support this e.g.
|
||||||
|
`max_inflight_messages=1` in mosquitto) then set `ClientOptions.SetOrderMatters(false)`. Doing so will avoid the
|
||||||
|
below issue (deadlocks due to blocking message handlers).
|
||||||
|
* A `MessageHandler` (called when a new message is received) must not block (unless
|
||||||
|
`ClientOptions.SetOrderMatters(false)` set). If you wish to perform a long-running task, or publish a message, then
|
||||||
|
please use a go routine (blocking in the handler is a common cause of unexpected `pingresp
|
||||||
|
not received, disconnecting` errors).
|
||||||
|
* When QOS1+ subscriptions have been created previously and you connect with `CleanSession` set to false it is possible that the broker will deliver retained
|
||||||
|
messages before `Subscribe` can be called. To process these messages either configure a handler with `AddRoute` or
|
||||||
|
set a `DefaultPublishHandler`.
|
||||||
|
* Loss of network connectivity may not be detected immediately. If this is an issue then consider setting
|
||||||
|
`ClientOptions.KeepAlive` (sends regular messages to check the link is active).
|
||||||
|
* Brokers offer many configuration options; some settings may lead to unexpected results. If using Mosquitto check
|
||||||
|
`max_inflight_messages`, `max_queued_messages`, `persistence` (the defaults may not be what you expect).
|
||||||
|
|
||||||
|
Reporting bugs
|
||||||
|
--------------
|
||||||
|
|
||||||
|
Please report bugs by raising issues for this project in github https://github.com/eclipse/paho.mqtt.golang/issues
|
||||||
|
|
||||||
|
*A limited number of contributors monitor the issues section so if you have a general question please consider the
|
||||||
|
resources in the [more information](#more-information) section (your question will be seen by more people, and you are
|
||||||
|
likely to receive an answer more quickly).*
|
||||||
|
|
||||||
|
We welcome bug reports, but it is important they are actionable. A significant percentage of issues reported are not
|
||||||
|
resolved due to a lack of information. If we cannot replicate the problem then it is unlikely we will be able to fix it.
|
||||||
|
The information required will vary from issue to issue but consider including:
|
||||||
|
|
||||||
|
* Which version of the package you are using (tag or commit - this should be in your go.mod file)
|
||||||
|
* A [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Providing an example
|
||||||
|
is the best way to demonstrate the issue you are facing; it is important this includes all relevant information
|
||||||
|
(including broker configuration). Docker (see `cmd/docker`) makes it relatively simple to provide a working end-to-end
|
||||||
|
example.
|
||||||
|
* A full, clear, description of the problem (detail what you are expecting vs what actually happens).
|
||||||
|
* Details of your attempts to resolve the issue (what have you tried, what worked, what did not).
|
||||||
|
* [Application Logs](#logging) covering the period the issue occurred. Unless you have isolated the root cause of the issue please include a link to a full log (including data from well before the problem arose).
|
||||||
|
* Broker Logs covering the period the issue occurred.
|
||||||
|
|
||||||
|
It is important to remember that this library does not stand alone; it communicates with a broker and any issues you are
|
||||||
|
seeing may be due to:
|
||||||
|
|
||||||
|
* Bugs in your code.
|
||||||
|
* Bugs in this library.
|
||||||
|
* The broker configuration.
|
||||||
|
* Bugs in the broker.
|
||||||
|
* Issues with whatever you are communicating with.
|
||||||
|
|
||||||
|
When submitting an issue, please ensure that you provide sufficient details to enable us to eliminate causes outside of
|
||||||
|
this library.
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
------------
|
||||||
|
|
||||||
|
We welcome pull requests but before your contribution can be accepted by the project, you need to create and
|
||||||
|
electronically sign the Eclipse Contributor Agreement (ECA) and sign off on the Eclipse Foundation Certificate of Origin.
|
||||||
|
|
||||||
|
More information is available in the
|
||||||
|
[Eclipse Development Resources](http://wiki.eclipse.org/Development_Resources/Contributing_via_Git); please take special
|
||||||
|
note of the requirement that the commit record contain a "Signed-off-by" entry.
|
||||||
|
|
||||||
|
More information
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Discussion of the Paho clients takes place on the [Eclipse paho-dev mailing list](https://dev.eclipse.org/mailman/listinfo/paho-dev).
|
||||||
|
|
||||||
|
General questions about the MQTT protocol are discussed in the [MQTT Google Group](https://groups.google.com/forum/?hl=en-US&fromgroups#!forum/mqtt).
|
||||||
|
|
||||||
|
There is much more information available via the [MQTT community site](http://mqtt.org).
|
||||||
|
|
||||||
|
[Stack Overflow](https://stackoverflow.com/questions/tagged/mqtt+go) has a range questions covering a range of common
|
||||||
|
issues (both relating to use of this library and MQTT in general).
|
||||||
41
vendor/github.com/eclipse/paho.mqtt.golang/about.html
generated
vendored
Normal file
41
vendor/github.com/eclipse/paho.mqtt.golang/about.html
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
|
<title>About</title>
|
||||||
|
</head>
|
||||||
|
<body lang="EN-US">
|
||||||
|
<h2>About This Content</h2>
|
||||||
|
|
||||||
|
<p><em>December 9, 2013</em></p>
|
||||||
|
<h3>License</h3>
|
||||||
|
|
||||||
|
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
|
||||||
|
indicated below, the Content is provided to you under the terms and conditions of the
|
||||||
|
Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL").
|
||||||
|
A copy of the EPL is available at
|
||||||
|
<a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>
|
||||||
|
and a copy of the EDL is available at
|
||||||
|
<a href="http://www.eclipse.org/org/documents/edl-v10.php">http://www.eclipse.org/org/documents/edl-v10.php</a>.
|
||||||
|
For purposes of the EPL, "Program" will mean the Content.</p>
|
||||||
|
|
||||||
|
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
|
||||||
|
being redistributed by another party ("Redistributor") and different terms and conditions may
|
||||||
|
apply to your use of any object code in the Content. Check the Redistributor's license that was
|
||||||
|
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
|
||||||
|
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
|
||||||
|
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Third Party Content</h3>
|
||||||
|
<p>The Content includes items that have been sourced from third parties as set out below. If you
|
||||||
|
did not receive this Content directly from the Eclipse Foundation, the following is provided
|
||||||
|
for informational purposes only, and you should look to the Redistributor's license for
|
||||||
|
terms and conditions of use.</p>
|
||||||
|
<p><em>
|
||||||
|
<strong>None</strong> <br><br>
|
||||||
|
<br><br>
|
||||||
|
</em></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body></html>
|
||||||
1097
vendor/github.com/eclipse/paho.mqtt.golang/client.go
generated
vendored
Normal file
1097
vendor/github.com/eclipse/paho.mqtt.golang/client.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
32
vendor/github.com/eclipse/paho.mqtt.golang/components.go
generated
vendored
Normal file
32
vendor/github.com/eclipse/paho.mqtt.golang/components.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
type component string
|
||||||
|
|
||||||
|
// Component names for debug output
|
||||||
|
const (
|
||||||
|
NET component = "[net] "
|
||||||
|
PNG component = "[pinger] "
|
||||||
|
CLI component = "[client] "
|
||||||
|
DEC component = "[decode] "
|
||||||
|
MES component = "[message] "
|
||||||
|
STR component = "[store] "
|
||||||
|
MID component = "[msgids] "
|
||||||
|
TST component = "[test] "
|
||||||
|
STA component = "[state] "
|
||||||
|
ERR component = "[error] "
|
||||||
|
ROU component = "[router] "
|
||||||
|
)
|
||||||
15
vendor/github.com/eclipse/paho.mqtt.golang/edl-v10
generated
vendored
Normal file
15
vendor/github.com/eclipse/paho.mqtt.golang/edl-v10
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
Eclipse Distribution License - v 1.0
|
||||||
|
|
||||||
|
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
70
vendor/github.com/eclipse/paho.mqtt.golang/epl-v10
generated
vendored
Normal file
70
vendor/github.com/eclipse/paho.mqtt.golang/epl-v10
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
Eclipse Public License - v 1.0
|
||||||
|
|
||||||
|
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
||||||
|
|
||||||
|
1. DEFINITIONS
|
||||||
|
|
||||||
|
"Contribution" means:
|
||||||
|
|
||||||
|
a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
|
||||||
|
b) in the case of each subsequent Contributor:
|
||||||
|
i) changes to the Program, and
|
||||||
|
ii) additions to the Program;
|
||||||
|
where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
|
||||||
|
"Contributor" means any person or entity that distributes the Program.
|
||||||
|
|
||||||
|
"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
|
||||||
|
|
||||||
|
"Program" means the Contributions distributed in accordance with this Agreement.
|
||||||
|
|
||||||
|
"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
|
||||||
|
|
||||||
|
2. GRANT OF RIGHTS
|
||||||
|
|
||||||
|
a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
|
||||||
|
b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
|
||||||
|
c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
|
||||||
|
d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
|
||||||
|
3. REQUIREMENTS
|
||||||
|
|
||||||
|
A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
|
||||||
|
|
||||||
|
a) it complies with the terms and conditions of this Agreement; and
|
||||||
|
b) its license agreement:
|
||||||
|
i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
|
||||||
|
ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
|
||||||
|
iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
|
||||||
|
iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
|
||||||
|
When the Program is made available in source code form:
|
||||||
|
|
||||||
|
a) it must be made available under this Agreement; and
|
||||||
|
b) a copy of this Agreement must be included with each copy of the Program.
|
||||||
|
Contributors may not remove or alter any copyright notices contained within the Program.
|
||||||
|
|
||||||
|
Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
|
||||||
|
|
||||||
|
4. COMMERCIAL DISTRIBUTION
|
||||||
|
|
||||||
|
Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
|
||||||
|
|
||||||
|
For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
|
||||||
|
|
||||||
|
5. NO WARRANTY
|
||||||
|
|
||||||
|
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
|
||||||
|
|
||||||
|
6. DISCLAIMER OF LIABILITY
|
||||||
|
|
||||||
|
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
7. GENERAL
|
||||||
|
|
||||||
|
If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
|
||||||
|
|
||||||
|
If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
|
||||||
|
|
||||||
|
All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
|
||||||
|
|
||||||
|
This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
|
||||||
257
vendor/github.com/eclipse/paho.mqtt.golang/filestore.go
generated
vendored
Normal file
257
vendor/github.com/eclipse/paho.mqtt.golang/filestore.go
generated
vendored
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"sort"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
msgExt = ".msg"
|
||||||
|
tmpExt = ".tmp"
|
||||||
|
corruptExt = ".CORRUPT"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileStore implements the store interface using the filesystem to provide
|
||||||
|
// true persistence, even across client failure. This is designed to use a
|
||||||
|
// single directory per running client. If you are running multiple clients
|
||||||
|
// on the same filesystem, you will need to be careful to specify unique
|
||||||
|
// store directories for each.
|
||||||
|
type FileStore struct {
|
||||||
|
sync.RWMutex
|
||||||
|
directory string
|
||||||
|
opened bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFileStore will create a new FileStore which stores its messages in the
|
||||||
|
// directory provided.
|
||||||
|
func NewFileStore(directory string) *FileStore {
|
||||||
|
store := &FileStore{
|
||||||
|
directory: directory,
|
||||||
|
opened: false,
|
||||||
|
}
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open will allow the FileStore to be used.
|
||||||
|
func (store *FileStore) Open() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
// if no store directory was specified in ClientOpts, by default use the
|
||||||
|
// current working directory
|
||||||
|
if store.directory == "" {
|
||||||
|
store.directory, _ = os.Getwd()
|
||||||
|
}
|
||||||
|
|
||||||
|
// if store dir exists, great, otherwise, create it
|
||||||
|
if !exists(store.directory) {
|
||||||
|
perms := os.FileMode(0770)
|
||||||
|
merr := os.MkdirAll(store.directory, perms)
|
||||||
|
chkerr(merr)
|
||||||
|
}
|
||||||
|
store.opened = true
|
||||||
|
DEBUG.Println(STR, "store is opened at", store.directory)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close will disallow the FileStore from being used.
|
||||||
|
func (store *FileStore) Close() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
store.opened = false
|
||||||
|
DEBUG.Println(STR, "store is closed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put will put a message into the store, associated with the provided
|
||||||
|
// key value.
|
||||||
|
func (store *FileStore) Put(key string, m packets.ControlPacket) {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use file store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
full := fullpath(store.directory, key)
|
||||||
|
write(store.directory, key, m)
|
||||||
|
if !exists(full) {
|
||||||
|
ERROR.Println(STR, "file not created:", full)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get will retrieve a message from the store, the one associated with
|
||||||
|
// the provided key value.
|
||||||
|
func (store *FileStore) Get(key string) packets.ControlPacket {
|
||||||
|
store.RLock()
|
||||||
|
defer store.RUnlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "trying to use file store, but not open")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
filepath := fullpath(store.directory, key)
|
||||||
|
if !exists(filepath) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
mfile, oerr := os.Open(filepath)
|
||||||
|
chkerr(oerr)
|
||||||
|
msg, rerr := packets.ReadPacket(mfile)
|
||||||
|
chkerr(mfile.Close())
|
||||||
|
|
||||||
|
// Message was unreadable, return nil
|
||||||
|
if rerr != nil {
|
||||||
|
newpath := corruptpath(store.directory, key)
|
||||||
|
WARN.Println(STR, "corrupted file detected:", rerr.Error(), "archived at:", newpath)
|
||||||
|
if err := os.Rename(filepath, newpath); err != nil {
|
||||||
|
ERROR.Println(STR, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// All will provide a list of all of the keys associated with messages
|
||||||
|
// currently residing in the FileStore.
|
||||||
|
func (store *FileStore) All() []string {
|
||||||
|
store.RLock()
|
||||||
|
defer store.RUnlock()
|
||||||
|
return store.all()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Del will remove the persisted message associated with the provided
|
||||||
|
// key from the FileStore.
|
||||||
|
func (store *FileStore) Del(key string) {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
store.del(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset will remove all persisted messages from the FileStore.
|
||||||
|
func (store *FileStore) Reset() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
WARN.Println(STR, "FileStore Reset")
|
||||||
|
for _, key := range store.all() {
|
||||||
|
store.del(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// lockless
|
||||||
|
func (store *FileStore) all() []string {
|
||||||
|
var err error
|
||||||
|
var keys []string
|
||||||
|
var files fileInfos
|
||||||
|
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "trying to use file store, but not open")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err = ioutil.ReadDir(store.directory)
|
||||||
|
chkerr(err)
|
||||||
|
sort.Sort(files)
|
||||||
|
for _, f := range files {
|
||||||
|
DEBUG.Println(STR, "file in All():", f.Name())
|
||||||
|
name := f.Name()
|
||||||
|
if name[len(name)-4:] != msgExt {
|
||||||
|
DEBUG.Println(STR, "skipping file, doesn't have right extension: ", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key := name[0 : len(name)-4] // remove file extension
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
// lockless
|
||||||
|
func (store *FileStore) del(key string) {
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "trying to use file store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
DEBUG.Println(STR, "store del filepath:", store.directory)
|
||||||
|
DEBUG.Println(STR, "store delete key:", key)
|
||||||
|
filepath := fullpath(store.directory, key)
|
||||||
|
DEBUG.Println(STR, "path of deletion:", filepath)
|
||||||
|
if !exists(filepath) {
|
||||||
|
WARN.Println(STR, "store could not delete key:", key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rerr := os.Remove(filepath)
|
||||||
|
chkerr(rerr)
|
||||||
|
DEBUG.Println(STR, "del msg:", key)
|
||||||
|
if exists(filepath) {
|
||||||
|
ERROR.Println(STR, "file not deleted:", filepath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fullpath(store string, key string) string {
|
||||||
|
p := path.Join(store, key+msgExt)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func tmppath(store string, key string) string {
|
||||||
|
p := path.Join(store, key+tmpExt)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func corruptpath(store string, key string) string {
|
||||||
|
p := path.Join(store, key+corruptExt)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// create file called "X.[messageid].tmp" located in the store
|
||||||
|
// the contents of the file is the bytes of the message, then
|
||||||
|
// rename it to "X.[messageid].msg", overwriting any existing
|
||||||
|
// message with the same id
|
||||||
|
// X will be 'i' for inbound messages, and O for outbound messages
|
||||||
|
func write(store, key string, m packets.ControlPacket) {
|
||||||
|
temppath := tmppath(store, key)
|
||||||
|
f, err := os.Create(temppath)
|
||||||
|
chkerr(err)
|
||||||
|
werr := m.Write(f)
|
||||||
|
chkerr(werr)
|
||||||
|
cerr := f.Close()
|
||||||
|
chkerr(cerr)
|
||||||
|
rerr := os.Rename(temppath, fullpath(store, key))
|
||||||
|
chkerr(rerr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func exists(file string) bool {
|
||||||
|
if _, err := os.Stat(file); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
chkerr(err)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
type fileInfos []os.FileInfo
|
||||||
|
|
||||||
|
func (f fileInfos) Len() int {
|
||||||
|
return len(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f fileInfos) Swap(i, j int) {
|
||||||
|
f[i], f[j] = f[j], f[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f fileInfos) Less(i, j int) bool {
|
||||||
|
return f[i].ModTime().Before(f[j].ModTime())
|
||||||
|
}
|
||||||
8
vendor/github.com/eclipse/paho.mqtt.golang/go.mod
generated
vendored
Normal file
8
vendor/github.com/eclipse/paho.mqtt.golang/go.mod
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module github.com/eclipse/paho.mqtt.golang
|
||||||
|
|
||||||
|
go 1.14
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gorilla/websocket v1.4.2
|
||||||
|
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0
|
||||||
|
)
|
||||||
8
vendor/github.com/eclipse/paho.mqtt.golang/go.sum
generated
vendored
Normal file
8
vendor/github.com/eclipse/paho.mqtt.golang/go.sum
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U=
|
||||||
|
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
138
vendor/github.com/eclipse/paho.mqtt.golang/memstore.go
generated
vendored
Normal file
138
vendor/github.com/eclipse/paho.mqtt.golang/memstore.go
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MemoryStore implements the store interface to provide a "persistence"
|
||||||
|
// mechanism wholly stored in memory. This is only useful for
|
||||||
|
// as long as the client instance exists.
|
||||||
|
type MemoryStore struct {
|
||||||
|
sync.RWMutex
|
||||||
|
messages map[string]packets.ControlPacket
|
||||||
|
opened bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMemoryStore returns a pointer to a new instance of
|
||||||
|
// MemoryStore, the instance is not initialized and ready to
|
||||||
|
// use until Open() has been called on it.
|
||||||
|
func NewMemoryStore() *MemoryStore {
|
||||||
|
store := &MemoryStore{
|
||||||
|
messages: make(map[string]packets.ControlPacket),
|
||||||
|
opened: false,
|
||||||
|
}
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open initializes a MemoryStore instance.
|
||||||
|
func (store *MemoryStore) Open() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
store.opened = true
|
||||||
|
DEBUG.Println(STR, "memorystore initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put takes a key and a pointer to a Message and stores the
|
||||||
|
// message.
|
||||||
|
func (store *MemoryStore) Put(key string, message packets.ControlPacket) {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
store.messages[key] = message
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get takes a key and looks in the store for a matching Message
|
||||||
|
// returning either the Message pointer or nil.
|
||||||
|
func (store *MemoryStore) Get(key string) packets.ControlPacket {
|
||||||
|
store.RLock()
|
||||||
|
defer store.RUnlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
mid := mIDFromKey(key)
|
||||||
|
m := store.messages[key]
|
||||||
|
if m == nil {
|
||||||
|
CRITICAL.Println(STR, "memorystore get: message", mid, "not found")
|
||||||
|
} else {
|
||||||
|
DEBUG.Println(STR, "memorystore get: message", mid, "found")
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// All returns a slice of strings containing all the keys currently
|
||||||
|
// in the MemoryStore.
|
||||||
|
func (store *MemoryStore) All() []string {
|
||||||
|
store.RLock()
|
||||||
|
defer store.RUnlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var keys []string
|
||||||
|
for k := range store.messages {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
// Del takes a key, searches the MemoryStore and if the key is found
|
||||||
|
// deletes the Message pointer associated with it.
|
||||||
|
func (store *MemoryStore) Del(key string) {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mid := mIDFromKey(key)
|
||||||
|
m := store.messages[key]
|
||||||
|
if m == nil {
|
||||||
|
WARN.Println(STR, "memorystore del: message", mid, "not found")
|
||||||
|
} else {
|
||||||
|
delete(store.messages, key)
|
||||||
|
DEBUG.Println(STR, "memorystore del: message", mid, "was deleted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close will disallow modifications to the state of the store.
|
||||||
|
func (store *MemoryStore) Close() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to close memory store, but not open")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
store.opened = false
|
||||||
|
DEBUG.Println(STR, "memorystore closed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset eliminates all persisted message data in the store.
|
||||||
|
func (store *MemoryStore) Reset() {
|
||||||
|
store.Lock()
|
||||||
|
defer store.Unlock()
|
||||||
|
if !store.opened {
|
||||||
|
ERROR.Println(STR, "Trying to reset memory store, but not open")
|
||||||
|
}
|
||||||
|
store.messages = make(map[string]packets.ControlPacket)
|
||||||
|
WARN.Println(STR, "memorystore wiped")
|
||||||
|
}
|
||||||
127
vendor/github.com/eclipse/paho.mqtt.golang/message.go
generated
vendored
Normal file
127
vendor/github.com/eclipse/paho.mqtt.golang/message.go
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/url"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Message defines the externals that a message implementation must support
|
||||||
|
// these are received messages that are passed to the callbacks, not internal
|
||||||
|
// messages
|
||||||
|
type Message interface {
|
||||||
|
Duplicate() bool
|
||||||
|
Qos() byte
|
||||||
|
Retained() bool
|
||||||
|
Topic() string
|
||||||
|
MessageID() uint16
|
||||||
|
Payload() []byte
|
||||||
|
Ack()
|
||||||
|
}
|
||||||
|
|
||||||
|
type message struct {
|
||||||
|
duplicate bool
|
||||||
|
qos byte
|
||||||
|
retained bool
|
||||||
|
topic string
|
||||||
|
messageID uint16
|
||||||
|
payload []byte
|
||||||
|
once sync.Once
|
||||||
|
ack func()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *message) Duplicate() bool {
|
||||||
|
return m.duplicate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *message) Qos() byte {
|
||||||
|
return m.qos
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *message) Retained() bool {
|
||||||
|
return m.retained
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *message) Topic() string {
|
||||||
|
return m.topic
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *message) MessageID() uint16 {
|
||||||
|
return m.messageID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *message) Payload() []byte {
|
||||||
|
return m.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *message) Ack() {
|
||||||
|
m.once.Do(m.ack)
|
||||||
|
}
|
||||||
|
|
||||||
|
func messageFromPublish(p *packets.PublishPacket, ack func()) Message {
|
||||||
|
return &message{
|
||||||
|
duplicate: p.Dup,
|
||||||
|
qos: p.Qos,
|
||||||
|
retained: p.Retain,
|
||||||
|
topic: p.TopicName,
|
||||||
|
messageID: p.MessageID,
|
||||||
|
payload: p.Payload,
|
||||||
|
ack: ack,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConnectMsgFromOptions(options *ClientOptions, broker *url.URL) *packets.ConnectPacket {
|
||||||
|
m := packets.NewControlPacket(packets.Connect).(*packets.ConnectPacket)
|
||||||
|
|
||||||
|
m.CleanSession = options.CleanSession
|
||||||
|
m.WillFlag = options.WillEnabled
|
||||||
|
m.WillRetain = options.WillRetained
|
||||||
|
m.ClientIdentifier = options.ClientID
|
||||||
|
|
||||||
|
if options.WillEnabled {
|
||||||
|
m.WillQos = options.WillQos
|
||||||
|
m.WillTopic = options.WillTopic
|
||||||
|
m.WillMessage = options.WillPayload
|
||||||
|
}
|
||||||
|
|
||||||
|
username := options.Username
|
||||||
|
password := options.Password
|
||||||
|
if broker.User != nil {
|
||||||
|
username = broker.User.Username()
|
||||||
|
if pwd, ok := broker.User.Password(); ok {
|
||||||
|
password = pwd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if options.CredentialsProvider != nil {
|
||||||
|
username, password = options.CredentialsProvider()
|
||||||
|
}
|
||||||
|
|
||||||
|
if username != "" {
|
||||||
|
m.UsernameFlag = true
|
||||||
|
m.Username = username
|
||||||
|
// mustn't have password without user as well
|
||||||
|
if password != "" {
|
||||||
|
m.PasswordFlag = true
|
||||||
|
m.Password = []byte(password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Keepalive = uint16(options.KeepAlive)
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
176
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
Normal file
176
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MId is 16 bit message id as specified by the MQTT spec.
|
||||||
|
// In general, these values should not be depended upon by
|
||||||
|
// the client application.
|
||||||
|
type MId uint16
|
||||||
|
|
||||||
|
type messageIds struct {
|
||||||
|
sync.RWMutex
|
||||||
|
index map[uint16]tokenCompletor
|
||||||
|
|
||||||
|
lastIssuedID uint16 // The most recently issued ID. Used so we cycle through ids rather than immediately reusing them (can make debugging easier)
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
midMin uint16 = 1
|
||||||
|
midMax uint16 = 65535
|
||||||
|
)
|
||||||
|
|
||||||
|
func (mids *messageIds) cleanUp() {
|
||||||
|
mids.Lock()
|
||||||
|
for _, token := range mids.index {
|
||||||
|
switch token.(type) {
|
||||||
|
case *PublishToken:
|
||||||
|
token.setError(fmt.Errorf("connection lost before Publish completed"))
|
||||||
|
case *SubscribeToken:
|
||||||
|
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
|
||||||
|
case *UnsubscribeToken:
|
||||||
|
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
|
||||||
|
case nil:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
token.flowComplete()
|
||||||
|
}
|
||||||
|
mids.index = make(map[uint16]tokenCompletor)
|
||||||
|
mids.Unlock()
|
||||||
|
DEBUG.Println(MID, "cleaned up")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mids *messageIds) freeID(id uint16) {
|
||||||
|
mids.Lock()
|
||||||
|
delete(mids.index, id)
|
||||||
|
mids.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mids *messageIds) claimID(token tokenCompletor, id uint16) {
|
||||||
|
mids.Lock()
|
||||||
|
defer mids.Unlock()
|
||||||
|
if _, ok := mids.index[id]; !ok {
|
||||||
|
mids.index[id] = token
|
||||||
|
} else {
|
||||||
|
old := mids.index[id]
|
||||||
|
old.flowComplete()
|
||||||
|
mids.index[id] = token
|
||||||
|
}
|
||||||
|
if id > mids.lastIssuedID {
|
||||||
|
mids.lastIssuedID = id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getID will return an available id or 0 if none available
|
||||||
|
// The id will generally be the previous id + 1 (because this makes tracing messages a bit simpler)
|
||||||
|
func (mids *messageIds) getID(t tokenCompletor) uint16 {
|
||||||
|
mids.Lock()
|
||||||
|
defer mids.Unlock()
|
||||||
|
i := mids.lastIssuedID // note: the only situation where lastIssuedID is 0 the map will be empty
|
||||||
|
looped := false // uint16 will loop from 65535->0
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
if i == 0 { // skip 0 because its not a valid id (Control Packets MUST contain a non-zero 16-bit Packet Identifier [MQTT-2.3.1-1])
|
||||||
|
i++
|
||||||
|
looped = true
|
||||||
|
}
|
||||||
|
if _, ok := mids.index[i]; !ok {
|
||||||
|
mids.index[i] = t
|
||||||
|
mids.lastIssuedID = i
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
if (looped && i == mids.lastIssuedID) || (mids.lastIssuedID == 0 && i == midMax) { // lastIssuedID will be 0 at startup
|
||||||
|
return 0 // no free ids
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mids *messageIds) getToken(id uint16) tokenCompletor {
|
||||||
|
mids.RLock()
|
||||||
|
defer mids.RUnlock()
|
||||||
|
if token, ok := mids.index[id]; ok {
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
return &DummyToken{id: id}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DummyToken struct {
|
||||||
|
id uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait implements the Token Wait method.
|
||||||
|
func (d *DummyToken) Wait() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaitTimeout implements the Token WaitTimeout method.
|
||||||
|
func (d *DummyToken) WaitTimeout(t time.Duration) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done implements the Token Done method.
|
||||||
|
func (d *DummyToken) Done() <-chan struct{} {
|
||||||
|
ch := make(chan struct{})
|
||||||
|
close(ch)
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DummyToken) flowComplete() {
|
||||||
|
ERROR.Printf("A lookup for token %d returned nil\n", d.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DummyToken) Error() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DummyToken) setError(e error) {}
|
||||||
|
|
||||||
|
// PlaceHolderToken does nothing and was implemented to allow a messageid to be reserved
|
||||||
|
// it differs from DummyToken in that calling flowComplete does not generate an error (it
|
||||||
|
// is expected that flowComplete will be called when the token is overwritten with a real token)
|
||||||
|
type PlaceHolderToken struct {
|
||||||
|
id uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait implements the Token Wait method.
|
||||||
|
func (p *PlaceHolderToken) Wait() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaitTimeout implements the Token WaitTimeout method.
|
||||||
|
func (p *PlaceHolderToken) WaitTimeout(t time.Duration) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done implements the Token Done method.
|
||||||
|
func (p *PlaceHolderToken) Done() <-chan struct{} {
|
||||||
|
ch := make(chan struct{})
|
||||||
|
close(ch)
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PlaceHolderToken) flowComplete() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PlaceHolderToken) Error() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PlaceHolderToken) setError(e error) {}
|
||||||
464
vendor/github.com/eclipse/paho.mqtt.golang/net.go
generated
vendored
Normal file
464
vendor/github.com/eclipse/paho.mqtt.golang/net.go
generated
vendored
Normal file
@@ -0,0 +1,464 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
const closedNetConnErrorText = "use of closed network connection" // error string for closed conn (https://golang.org/src/net/error_test.go)
|
||||||
|
|
||||||
|
// ConnectMQTT takes a connected net.Conn and performs the initial MQTT handshake. Parameters are:
|
||||||
|
// conn - Connected net.Conn
|
||||||
|
// cm - Connect Packet with everything other than the protocol name/version populated (historical reasons)
|
||||||
|
// protocolVersion - The protocol version to attempt to connect with
|
||||||
|
//
|
||||||
|
// Note that, for backward compatibility, ConnectMQTT() suppresses the actual connection error (compare to connectMQTT()).
|
||||||
|
func ConnectMQTT(conn net.Conn, cm *packets.ConnectPacket, protocolVersion uint) (byte, bool) {
|
||||||
|
rc, sessionPresent, _ := connectMQTT(conn, cm, protocolVersion)
|
||||||
|
return rc, sessionPresent
|
||||||
|
}
|
||||||
|
|
||||||
|
func connectMQTT(conn io.ReadWriter, cm *packets.ConnectPacket, protocolVersion uint) (byte, bool, error) {
|
||||||
|
switch protocolVersion {
|
||||||
|
case 3:
|
||||||
|
DEBUG.Println(CLI, "Using MQTT 3.1 protocol")
|
||||||
|
cm.ProtocolName = "MQIsdp"
|
||||||
|
cm.ProtocolVersion = 3
|
||||||
|
case 0x83:
|
||||||
|
DEBUG.Println(CLI, "Using MQTT 3.1b protocol")
|
||||||
|
cm.ProtocolName = "MQIsdp"
|
||||||
|
cm.ProtocolVersion = 0x83
|
||||||
|
case 0x84:
|
||||||
|
DEBUG.Println(CLI, "Using MQTT 3.1.1b protocol")
|
||||||
|
cm.ProtocolName = "MQTT"
|
||||||
|
cm.ProtocolVersion = 0x84
|
||||||
|
default:
|
||||||
|
DEBUG.Println(CLI, "Using MQTT 3.1.1 protocol")
|
||||||
|
cm.ProtocolName = "MQTT"
|
||||||
|
cm.ProtocolVersion = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cm.Write(conn); err != nil {
|
||||||
|
ERROR.Println(CLI, err)
|
||||||
|
return packets.ErrNetworkError, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rc, sessionPresent, err := verifyCONNACK(conn)
|
||||||
|
return rc, sessionPresent, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is only used for receiving a connack
|
||||||
|
// when the connection is first started.
|
||||||
|
// This prevents receiving incoming data while resume
|
||||||
|
// is in progress if clean session is false.
|
||||||
|
func verifyCONNACK(conn io.Reader) (byte, bool, error) {
|
||||||
|
DEBUG.Println(NET, "connect started")
|
||||||
|
|
||||||
|
ca, err := packets.ReadPacket(conn)
|
||||||
|
if err != nil {
|
||||||
|
ERROR.Println(NET, "connect got error", err)
|
||||||
|
return packets.ErrNetworkError, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if ca == nil {
|
||||||
|
ERROR.Println(NET, "received nil packet")
|
||||||
|
return packets.ErrNetworkError, false, errors.New("nil CONNACK packet")
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, ok := ca.(*packets.ConnackPacket)
|
||||||
|
if !ok {
|
||||||
|
ERROR.Println(NET, "received msg that was not CONNACK")
|
||||||
|
return packets.ErrNetworkError, false, errors.New("non-CONNACK first packet received")
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG.Println(NET, "received connack")
|
||||||
|
return msg.ReturnCode, msg.SessionPresent, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// inbound encapsulates the output from startIncoming.
|
||||||
|
// err - If != nil then an error has occurred
|
||||||
|
// cp - A control packet received over the network link
|
||||||
|
type inbound struct {
|
||||||
|
err error
|
||||||
|
cp packets.ControlPacket
|
||||||
|
}
|
||||||
|
|
||||||
|
// startIncoming initiates a goroutine that reads incoming messages off the wire and sends them to the channel (returned).
|
||||||
|
// If there are any issues with the network connection then the returned channel will be closed and the goroutine will exit
|
||||||
|
// (so closing the connection will terminate the goroutine)
|
||||||
|
func startIncoming(conn io.Reader) <-chan inbound {
|
||||||
|
var err error
|
||||||
|
var cp packets.ControlPacket
|
||||||
|
ibound := make(chan inbound)
|
||||||
|
|
||||||
|
DEBUG.Println(NET, "incoming started")
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if cp, err = packets.ReadPacket(conn); err != nil {
|
||||||
|
// We do not want to log the error if it is due to the network connection having been closed
|
||||||
|
// elsewhere (i.e. after sending DisconnectPacket). Detecting this situation is the subject of
|
||||||
|
// https://github.com/golang/go/issues/4373
|
||||||
|
if !strings.Contains(err.Error(), closedNetConnErrorText) {
|
||||||
|
ibound <- inbound{err: err}
|
||||||
|
}
|
||||||
|
close(ibound)
|
||||||
|
DEBUG.Println(NET, "incoming complete")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
DEBUG.Println(NET, "startIncoming Received Message")
|
||||||
|
ibound <- inbound{cp: cp}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ibound
|
||||||
|
}
|
||||||
|
|
||||||
|
// incomingComms encapsulates the possible output of the incomingComms routine. If err != nil then an error has occurred and
|
||||||
|
// the routine will have terminated; otherwise one of the other members should be non-nil
|
||||||
|
type incomingComms struct {
|
||||||
|
err error // If non-nil then there has been an error (ignore everything else)
|
||||||
|
outbound *PacketAndToken // Packet (with token) than needs to be sent out (e.g. an acknowledgement)
|
||||||
|
incomingPub *packets.PublishPacket // A new publish has been received; this will need to be passed on to our user
|
||||||
|
}
|
||||||
|
|
||||||
|
// startIncomingComms initiates incoming communications; this includes starting a goroutine to process incoming
|
||||||
|
// messages.
|
||||||
|
// Accepts a channel of inbound messages from the store (persisted messages); note this must be closed as soon as the
|
||||||
|
// everything in the store has been sent.
|
||||||
|
// Returns a channel that will be passed any received packets; this will be closed on a network error (and inboundFromStore closed)
|
||||||
|
func startIncomingComms(conn io.Reader,
|
||||||
|
c commsFns,
|
||||||
|
inboundFromStore <-chan packets.ControlPacket,
|
||||||
|
) <-chan incomingComms {
|
||||||
|
ibound := startIncoming(conn) // Start goroutine that reads from network connection
|
||||||
|
output := make(chan incomingComms)
|
||||||
|
|
||||||
|
DEBUG.Println(NET, "startIncomingComms started")
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if inboundFromStore == nil && ibound == nil {
|
||||||
|
close(output)
|
||||||
|
DEBUG.Println(NET, "startIncomingComms goroutine complete")
|
||||||
|
return // As soon as ibound is closed we can exit (should have already processed an error)
|
||||||
|
}
|
||||||
|
DEBUG.Println(NET, "logic waiting for msg on ibound")
|
||||||
|
|
||||||
|
var msg packets.ControlPacket
|
||||||
|
var ok bool
|
||||||
|
select {
|
||||||
|
case msg, ok = <-inboundFromStore:
|
||||||
|
if !ok {
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: inboundFromStore complete")
|
||||||
|
inboundFromStore = nil // should happen quickly as this is only for persisted messages
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: got msg from store")
|
||||||
|
case ibMsg, ok := <-ibound:
|
||||||
|
if !ok {
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: ibound complete")
|
||||||
|
ibound = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: got msg on ibound")
|
||||||
|
// If the inbound comms routine encounters any issues it will send us an error.
|
||||||
|
if ibMsg.err != nil {
|
||||||
|
output <- incomingComms{err: ibMsg.err}
|
||||||
|
continue // Usually the channel will be closed immediately after sending an error but safer that we do not assume this
|
||||||
|
}
|
||||||
|
msg = ibMsg.cp
|
||||||
|
|
||||||
|
c.persistInbound(msg)
|
||||||
|
c.UpdateLastReceived() // Notify keepalive logic that we recently received a packet
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m := msg.(type) {
|
||||||
|
case *packets.PingrespPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received pingresp")
|
||||||
|
c.pingRespReceived()
|
||||||
|
case *packets.SubackPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received suback, id:", m.MessageID)
|
||||||
|
token := c.getToken(m.MessageID)
|
||||||
|
|
||||||
|
if t, ok := token.(*SubscribeToken); ok {
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: granted qoss", m.ReturnCodes)
|
||||||
|
for i, qos := range m.ReturnCodes {
|
||||||
|
t.subResult[t.subs[i]] = qos
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
token.flowComplete()
|
||||||
|
c.freeID(m.MessageID)
|
||||||
|
case *packets.UnsubackPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received unsuback, id:", m.MessageID)
|
||||||
|
c.getToken(m.MessageID).flowComplete()
|
||||||
|
c.freeID(m.MessageID)
|
||||||
|
case *packets.PublishPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received publish, msgId:", m.MessageID)
|
||||||
|
output <- incomingComms{incomingPub: m}
|
||||||
|
case *packets.PubackPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received puback, id:", m.MessageID)
|
||||||
|
c.getToken(m.MessageID).flowComplete()
|
||||||
|
c.freeID(m.MessageID)
|
||||||
|
case *packets.PubrecPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received pubrec, id:", m.MessageID)
|
||||||
|
prel := packets.NewControlPacket(packets.Pubrel).(*packets.PubrelPacket)
|
||||||
|
prel.MessageID = m.MessageID
|
||||||
|
output <- incomingComms{outbound: &PacketAndToken{p: prel, t: nil}}
|
||||||
|
case *packets.PubrelPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received pubrel, id:", m.MessageID)
|
||||||
|
pc := packets.NewControlPacket(packets.Pubcomp).(*packets.PubcompPacket)
|
||||||
|
pc.MessageID = m.MessageID
|
||||||
|
c.persistOutbound(pc)
|
||||||
|
output <- incomingComms{outbound: &PacketAndToken{p: pc, t: nil}}
|
||||||
|
case *packets.PubcompPacket:
|
||||||
|
DEBUG.Println(NET, "startIncomingComms: received pubcomp, id:", m.MessageID)
|
||||||
|
c.getToken(m.MessageID).flowComplete()
|
||||||
|
c.freeID(m.MessageID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
// startOutgoingComms initiates a go routine to transmit outgoing packets.
|
||||||
|
// Pass in an open network connection and channels for outbound messages (including those triggered
|
||||||
|
// directly from incoming comms).
|
||||||
|
// Returns a channel that will receive details of any errors (closed when the goroutine exits)
|
||||||
|
// This function wil only terminate when all input channels are closed
|
||||||
|
func startOutgoingComms(conn net.Conn,
|
||||||
|
c commsFns,
|
||||||
|
oboundp <-chan *PacketAndToken,
|
||||||
|
obound <-chan *PacketAndToken,
|
||||||
|
oboundFromIncoming <-chan *PacketAndToken,
|
||||||
|
) <-chan error {
|
||||||
|
errChan := make(chan error)
|
||||||
|
DEBUG.Println(NET, "outgoing started")
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
DEBUG.Println(NET, "outgoing waiting for an outbound message")
|
||||||
|
|
||||||
|
// This goroutine will only exits when all of the input channels we receive on have been closed. This approach is taken to avoid any
|
||||||
|
// deadlocks (if the connection goes down there are limited options as to what we can do with anything waiting on us and
|
||||||
|
// throwing away the packets seems the best option)
|
||||||
|
if oboundp == nil && obound == nil && oboundFromIncoming == nil {
|
||||||
|
DEBUG.Println(NET, "outgoing comms stopping")
|
||||||
|
close(errChan)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case pub, ok := <-obound:
|
||||||
|
if !ok {
|
||||||
|
obound = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
msg := pub.p.(*packets.PublishPacket)
|
||||||
|
DEBUG.Println(NET, "obound msg to write", msg.MessageID)
|
||||||
|
|
||||||
|
writeTimeout := c.getWriteTimeOut()
|
||||||
|
if writeTimeout > 0 {
|
||||||
|
if err := conn.SetWriteDeadline(time.Now().Add(writeTimeout)); err != nil {
|
||||||
|
ERROR.Println(NET, "SetWriteDeadline ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := msg.Write(conn); err != nil {
|
||||||
|
ERROR.Println(NET, "outgoing obound reporting error ", err)
|
||||||
|
pub.t.setError(err)
|
||||||
|
// report error if it's not due to the connection being closed elsewhere
|
||||||
|
if !strings.Contains(err.Error(), closedNetConnErrorText) {
|
||||||
|
errChan <- err
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if writeTimeout > 0 {
|
||||||
|
// If we successfully wrote, we don't want the timeout to happen during an idle period
|
||||||
|
// so we reset it to infinite.
|
||||||
|
if err := conn.SetWriteDeadline(time.Time{}); err != nil {
|
||||||
|
ERROR.Println(NET, "SetWriteDeadline to 0 ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.Qos == 0 {
|
||||||
|
pub.t.flowComplete()
|
||||||
|
}
|
||||||
|
DEBUG.Println(NET, "obound wrote msg, id:", msg.MessageID)
|
||||||
|
case msg, ok := <-oboundp:
|
||||||
|
if !ok {
|
||||||
|
oboundp = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
DEBUG.Println(NET, "obound priority msg to write, type", reflect.TypeOf(msg.p))
|
||||||
|
if err := msg.p.Write(conn); err != nil {
|
||||||
|
ERROR.Println(NET, "outgoing oboundp reporting error ", err)
|
||||||
|
if msg.t != nil {
|
||||||
|
msg.t.setError(err)
|
||||||
|
}
|
||||||
|
errChan <- err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := msg.p.(*packets.DisconnectPacket); ok {
|
||||||
|
msg.t.(*DisconnectToken).flowComplete()
|
||||||
|
DEBUG.Println(NET, "outbound wrote disconnect, closing connection")
|
||||||
|
// As per the MQTT spec "After sending a DISCONNECT Packet the Client MUST close the Network Connection"
|
||||||
|
// Closing the connection will cause the goroutines to end in sequence (starting with incoming comms)
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
case msg, ok := <-oboundFromIncoming: // message triggered by an inbound message (PubrecPacket or PubrelPacket)
|
||||||
|
if !ok {
|
||||||
|
oboundFromIncoming = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
DEBUG.Println(NET, "obound from incoming msg to write, type", reflect.TypeOf(msg.p), " ID ", msg.p.Details().MessageID)
|
||||||
|
if err := msg.p.Write(conn); err != nil {
|
||||||
|
ERROR.Println(NET, "outgoing oboundFromIncoming reporting error", err)
|
||||||
|
if msg.t != nil {
|
||||||
|
msg.t.setError(err)
|
||||||
|
}
|
||||||
|
errChan <- err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.UpdateLastSent() // Record that a packet has been received (for keepalive routine)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return errChan
|
||||||
|
}
|
||||||
|
|
||||||
|
// commsFns provide access to the client state (messageids, requesting disconnection and updating timing)
|
||||||
|
type commsFns interface {
|
||||||
|
getToken(id uint16) tokenCompletor // Retrieve the token for the specified messageid (if none then a dummy token must be returned)
|
||||||
|
freeID(id uint16) // Release the specified messageid (clearing out of any persistent store)
|
||||||
|
UpdateLastReceived() // Must be called whenever a packet is received
|
||||||
|
UpdateLastSent() // Must be called whenever a packet is successfully sent
|
||||||
|
getWriteTimeOut() time.Duration // Return the writetimeout (or 0 if none)
|
||||||
|
persistOutbound(m packets.ControlPacket) // add the packet to the outbound store
|
||||||
|
persistInbound(m packets.ControlPacket) // add the packet to the inbound store
|
||||||
|
pingRespReceived() // Called when a ping response is received
|
||||||
|
}
|
||||||
|
|
||||||
|
// startComms initiates goroutines that handles communications over the network connection
|
||||||
|
// Messages will be stored (via commsFns) and deleted from the store as necessary
|
||||||
|
// It returns two channels:
|
||||||
|
// packets.PublishPacket - Will receive publish packets received over the network.
|
||||||
|
// Closed when incoming comms routines exit (on shutdown or if network link closed)
|
||||||
|
// error - Any errors will be sent on this channel. The channel is closed when all comms routines have shut down
|
||||||
|
//
|
||||||
|
// Note: The comms routines monitoring oboundp and obound will not shutdown until those channels are both closed. Any messages received between the
|
||||||
|
// connection being closed and those channels being closed will generate errors (and nothing will be sent). That way the chance of a deadlock is
|
||||||
|
// minimised.
|
||||||
|
func startComms(conn net.Conn, // Network connection (must be active)
|
||||||
|
c commsFns, // getters and setters to enable us to cleanly interact with client
|
||||||
|
inboundFromStore <-chan packets.ControlPacket, // Inbound packets from the persistence store (should be closed relatively soon after startup)
|
||||||
|
oboundp <-chan *PacketAndToken,
|
||||||
|
obound <-chan *PacketAndToken) (
|
||||||
|
<-chan *packets.PublishPacket, // Publishpackages received over the network
|
||||||
|
<-chan error, // Any errors (should generally trigger a disconnect)
|
||||||
|
) {
|
||||||
|
// Start inbound comms handler; this needs to be able to transmit messages so we start a go routine to add these to the priority outbound channel
|
||||||
|
ibound := startIncomingComms(conn, c, inboundFromStore)
|
||||||
|
outboundFromIncoming := make(chan *PacketAndToken) // Will accept outgoing messages triggered by startIncomingComms (e.g. acknowledgements)
|
||||||
|
|
||||||
|
// Start the outgoing handler. It is important to note that output from startIncomingComms is fed into startOutgoingComms (for ACK's)
|
||||||
|
oboundErr := startOutgoingComms(conn, c, oboundp, obound, outboundFromIncoming)
|
||||||
|
DEBUG.Println(NET, "startComms started")
|
||||||
|
|
||||||
|
// Run up go routines to handle the output from the above comms functions - these are handled in separate
|
||||||
|
// go routines because they can interact (e.g. ibound triggers an ACK to obound which triggers an error)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
|
outPublish := make(chan *packets.PublishPacket)
|
||||||
|
outError := make(chan error)
|
||||||
|
|
||||||
|
// Any messages received get passed to the appropriate channel
|
||||||
|
go func() {
|
||||||
|
for ic := range ibound {
|
||||||
|
if ic.err != nil {
|
||||||
|
outError <- ic.err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ic.outbound != nil {
|
||||||
|
outboundFromIncoming <- ic.outbound
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ic.incomingPub != nil {
|
||||||
|
outPublish <- ic.incomingPub
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ERROR.Println(STR, "startComms received empty incomingComms msg")
|
||||||
|
}
|
||||||
|
// Close channels that will not be written to again (allowing other routines to exit)
|
||||||
|
close(outboundFromIncoming)
|
||||||
|
close(outPublish)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Any errors will be passed out to our caller
|
||||||
|
go func() {
|
||||||
|
for err := range oboundErr {
|
||||||
|
outError <- err
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// outError is used by both routines so can only be closed when they are both complete
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(outError)
|
||||||
|
DEBUG.Println(NET, "startComms closing outError")
|
||||||
|
}()
|
||||||
|
|
||||||
|
return outPublish, outError
|
||||||
|
}
|
||||||
|
|
||||||
|
// ackFunc acknowledges a packet
|
||||||
|
// WARNING the function returned must not be called if the comms routine is shutting down or not running
|
||||||
|
// (it needs outgoing comms in order to send the acknowledgement). Currently this is only called from
|
||||||
|
// matchAndDispatch which will be shutdown before the comms are
|
||||||
|
func ackFunc(oboundP chan *PacketAndToken, persist Store, packet *packets.PublishPacket) func() {
|
||||||
|
return func() {
|
||||||
|
switch packet.Qos {
|
||||||
|
case 2:
|
||||||
|
pr := packets.NewControlPacket(packets.Pubrec).(*packets.PubrecPacket)
|
||||||
|
pr.MessageID = packet.MessageID
|
||||||
|
DEBUG.Println(NET, "putting pubrec msg on obound")
|
||||||
|
oboundP <- &PacketAndToken{p: pr, t: nil}
|
||||||
|
DEBUG.Println(NET, "done putting pubrec msg on obound")
|
||||||
|
case 1:
|
||||||
|
pa := packets.NewControlPacket(packets.Puback).(*packets.PubackPacket)
|
||||||
|
pa.MessageID = packet.MessageID
|
||||||
|
DEBUG.Println(NET, "putting puback msg on obound")
|
||||||
|
persistOutbound(persist, pa)
|
||||||
|
oboundP <- &PacketAndToken{p: pa, t: nil}
|
||||||
|
DEBUG.Println(NET, "done putting puback msg on obound")
|
||||||
|
case 0:
|
||||||
|
// do nothing, since there is no need to send an ack packet back
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
91
vendor/github.com/eclipse/paho.mqtt.golang/netconn.go
generated
vendored
Normal file
91
vendor/github.com/eclipse/paho.mqtt.golang/netconn.go
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
// This just establishes the network connection; once established the type of connection should be irrelevant
|
||||||
|
//
|
||||||
|
|
||||||
|
// openConnection opens a network connection using the protocol indicated in the URL. Does not carry out any MQTT specific handshakes
|
||||||
|
func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, headers http.Header, websocketOptions *WebsocketOptions) (net.Conn, error) {
|
||||||
|
switch uri.Scheme {
|
||||||
|
case "ws":
|
||||||
|
conn, err := NewWebsocket(uri.String(), nil, timeout, headers, websocketOptions)
|
||||||
|
return conn, err
|
||||||
|
case "wss":
|
||||||
|
conn, err := NewWebsocket(uri.String(), tlsc, timeout, headers, websocketOptions)
|
||||||
|
return conn, err
|
||||||
|
case "mqtt", "tcp":
|
||||||
|
allProxy := os.Getenv("all_proxy")
|
||||||
|
if len(allProxy) == 0 {
|
||||||
|
conn, err := net.DialTimeout("tcp", uri.Host, timeout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, nil
|
||||||
|
}
|
||||||
|
proxyDialer := proxy.FromEnvironment()
|
||||||
|
|
||||||
|
conn, err := proxyDialer.Dial("tcp", uri.Host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, nil
|
||||||
|
case "unix":
|
||||||
|
conn, err := net.DialTimeout("unix", uri.Host, timeout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, nil
|
||||||
|
case "ssl", "tls", "mqtts", "mqtt+ssl", "tcps":
|
||||||
|
allProxy := os.Getenv("all_proxy")
|
||||||
|
if len(allProxy) == 0 {
|
||||||
|
conn, err := tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", uri.Host, tlsc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, nil
|
||||||
|
}
|
||||||
|
proxyDialer := proxy.FromEnvironment()
|
||||||
|
|
||||||
|
conn, err := proxyDialer.Dial("tcp", uri.Host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tlsConn := tls.Client(conn, tlsc)
|
||||||
|
|
||||||
|
err = tlsConn.Handshake()
|
||||||
|
if err != nil {
|
||||||
|
conn.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tlsConn, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("unknown protocol")
|
||||||
|
}
|
||||||
108
vendor/github.com/eclipse/paho.mqtt.golang/notice.html
generated
vendored
Normal file
108
vendor/github.com/eclipse/paho.mqtt.golang/notice.html
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
||||||
|
<title>Eclipse Foundation Software User Agreement</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body lang="EN-US">
|
||||||
|
<h2>Eclipse Foundation Software User Agreement</h2>
|
||||||
|
<p>February 1, 2011</p>
|
||||||
|
|
||||||
|
<h3>Usage Of Content</h3>
|
||||||
|
|
||||||
|
<p>THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS
|
||||||
|
(COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND
|
||||||
|
CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE
|
||||||
|
OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR
|
||||||
|
NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND
|
||||||
|
CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.</p>
|
||||||
|
|
||||||
|
<h3>Applicable Licenses</h3>
|
||||||
|
|
||||||
|
<p>Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0
|
||||||
|
("EPL"). A copy of the EPL is provided with this Content and is also available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
|
||||||
|
For purposes of the EPL, "Program" will mean the Content.</p>
|
||||||
|
|
||||||
|
<p>Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code
|
||||||
|
repository ("Repository") in software modules ("Modules") and made available as downloadable archives ("Downloads").</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"), plug-in fragments ("Fragments"), and features ("Features").</li>
|
||||||
|
<li>Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".</li>
|
||||||
|
<li>A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named "features". Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of the Plug-ins
|
||||||
|
and/or Fragments associated with that Feature.</li>
|
||||||
|
<li>Features may also include other Features ("Included Features"). Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of Included Features.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>The terms and conditions governing Plug-ins and Fragments should be contained in files named "about.html" ("Abouts"). The terms and conditions governing Features and
|
||||||
|
Included Features should be contained in files named "license.html" ("Feature Licenses"). Abouts and Feature Licenses may be located in any directory of a Download or Module
|
||||||
|
including, but not limited to the following locations:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>The top-level (root) directory</li>
|
||||||
|
<li>Plug-in and Fragment directories</li>
|
||||||
|
<li>Inside Plug-ins and Fragments packaged as JARs</li>
|
||||||
|
<li>Sub-directories of the directory named "src" of certain Plug-ins</li>
|
||||||
|
<li>Feature directories</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license ("Feature Update License") during the
|
||||||
|
installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or
|
||||||
|
inform you where you can locate them. Feature Update Licenses may be found in the "license" property of files named "feature.properties" found within a Feature.
|
||||||
|
Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in
|
||||||
|
that directory.</p>
|
||||||
|
|
||||||
|
<p>THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE
|
||||||
|
OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Eclipse Distribution License Version 1.0 (available at <a href="http://www.eclipse.org/licenses/edl-v10.html">http://www.eclipse.org/licenses/edl-v1.0.html</a>)</li>
|
||||||
|
<li>Common Public License Version 1.0 (available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>)</li>
|
||||||
|
<li>Apache Software License 1.1 (available at <a href="http://www.apache.org/licenses/LICENSE">http://www.apache.org/licenses/LICENSE</a>)</li>
|
||||||
|
<li>Apache Software License 2.0 (available at <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)</li>
|
||||||
|
<li>Metro Link Public License 1.00 (available at <a href="http://www.opengroup.org/openmotif/supporters/metrolink/license.html">http://www.opengroup.org/openmotif/supporters/metrolink/license.html</a>)</li>
|
||||||
|
<li>Mozilla Public License Version 1.1 (available at <a href="http://www.mozilla.org/MPL/MPL-1.1.html">http://www.mozilla.org/MPL/MPL-1.1.html</a>)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please
|
||||||
|
contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Use of Provisioning Technology</h3>
|
||||||
|
|
||||||
|
<p>The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse
|
||||||
|
Update Manager ("Provisioning Technology") for the purpose of allowing users to install software, documentation, information and/or
|
||||||
|
other materials (collectively "Installable Software"). This capability is provided with the intent of allowing such users to
|
||||||
|
install, extend and update Eclipse-based products. Information about packaging Installable Software is available at <a
|
||||||
|
href="http://eclipse.org/equinox/p2/repository_packaging.html">http://eclipse.org/equinox/p2/repository_packaging.html</a>
|
||||||
|
("Specification").</p>
|
||||||
|
|
||||||
|
<p>You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the
|
||||||
|
applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology
|
||||||
|
in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the
|
||||||
|
Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>A series of actions may occur ("Provisioning Process") in which a user may execute the Provisioning Technology
|
||||||
|
on a machine ("Target Machine") with the intent of installing, extending or updating the functionality of an Eclipse-based
|
||||||
|
product.</li>
|
||||||
|
<li>During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be
|
||||||
|
accessed and copied to the Target Machine.</li>
|
||||||
|
<li>Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable
|
||||||
|
Software ("Installable Software Agreement") and such Installable Software Agreement shall be accessed from the Target
|
||||||
|
Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern
|
||||||
|
the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such
|
||||||
|
indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<h3>Cryptography</h3>
|
||||||
|
|
||||||
|
<p>Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to
|
||||||
|
another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import,
|
||||||
|
possession, or use, and re-export of encryption software, to see if this is permitted.</p>
|
||||||
|
|
||||||
|
<p><small>Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.</small></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
21
vendor/github.com/eclipse/paho.mqtt.golang/oops.go
generated
vendored
Normal file
21
vendor/github.com/eclipse/paho.mqtt.golang/oops.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
func chkerr(e error) {
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
389
vendor/github.com/eclipse/paho.mqtt.golang/options.go
generated
vendored
Normal file
389
vendor/github.com/eclipse/paho.mqtt.golang/options.go
generated
vendored
Normal file
@@ -0,0 +1,389 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
* Måns Ansgariusson
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Portions copyright © 2018 TIBCO Software Inc.
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CredentialsProvider allows the username and password to be updated
|
||||||
|
// before reconnecting. It should return the current username and password.
|
||||||
|
type CredentialsProvider func() (username string, password string)
|
||||||
|
|
||||||
|
// MessageHandler is a callback type which can be set to be
|
||||||
|
// executed upon the arrival of messages published to topics
|
||||||
|
// to which the client is subscribed.
|
||||||
|
type MessageHandler func(Client, Message)
|
||||||
|
|
||||||
|
// ConnectionLostHandler is a callback type which can be set to be
|
||||||
|
// executed upon an unintended disconnection from the MQTT broker.
|
||||||
|
// Disconnects caused by calling Disconnect or ForceDisconnect will
|
||||||
|
// not cause an OnConnectionLost callback to execute.
|
||||||
|
type ConnectionLostHandler func(Client, error)
|
||||||
|
|
||||||
|
// OnConnectHandler is a callback that is called when the client
|
||||||
|
// state changes from unconnected/disconnected to connected. Both
|
||||||
|
// at initial connection and on reconnection
|
||||||
|
type OnConnectHandler func(Client)
|
||||||
|
|
||||||
|
// ReconnectHandler is invoked prior to reconnecting after
|
||||||
|
// the initial connection is lost
|
||||||
|
type ReconnectHandler func(Client, *ClientOptions)
|
||||||
|
|
||||||
|
// ClientOptions contains configurable options for an Client. Note that these should be set using the
|
||||||
|
// relevant methods (e.g. AddBroker) rather than directly. See those functions for information on usage.
|
||||||
|
type ClientOptions struct {
|
||||||
|
Servers []*url.URL
|
||||||
|
ClientID string
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
CredentialsProvider CredentialsProvider
|
||||||
|
CleanSession bool
|
||||||
|
Order bool
|
||||||
|
WillEnabled bool
|
||||||
|
WillTopic string
|
||||||
|
WillPayload []byte
|
||||||
|
WillQos byte
|
||||||
|
WillRetained bool
|
||||||
|
ProtocolVersion uint
|
||||||
|
protocolVersionExplicit bool
|
||||||
|
TLSConfig *tls.Config
|
||||||
|
KeepAlive int64
|
||||||
|
PingTimeout time.Duration
|
||||||
|
ConnectTimeout time.Duration
|
||||||
|
MaxReconnectInterval time.Duration
|
||||||
|
AutoReconnect bool
|
||||||
|
ConnectRetryInterval time.Duration
|
||||||
|
ConnectRetry bool
|
||||||
|
Store Store
|
||||||
|
DefaultPublishHandler MessageHandler
|
||||||
|
OnConnect OnConnectHandler
|
||||||
|
OnConnectionLost ConnectionLostHandler
|
||||||
|
OnReconnecting ReconnectHandler
|
||||||
|
WriteTimeout time.Duration
|
||||||
|
MessageChannelDepth uint
|
||||||
|
ResumeSubs bool
|
||||||
|
HTTPHeaders http.Header
|
||||||
|
WebsocketOptions *WebsocketOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientOptions will create a new ClientClientOptions type with some
|
||||||
|
// default values.
|
||||||
|
// Port: 1883
|
||||||
|
// CleanSession: True
|
||||||
|
// Order: True (note: it is recommended that this be set to FALSE unless order is important)
|
||||||
|
// KeepAlive: 30 (seconds)
|
||||||
|
// ConnectTimeout: 30 (seconds)
|
||||||
|
// MaxReconnectInterval 10 (minutes)
|
||||||
|
// AutoReconnect: True
|
||||||
|
func NewClientOptions() *ClientOptions {
|
||||||
|
o := &ClientOptions{
|
||||||
|
Servers: nil,
|
||||||
|
ClientID: "",
|
||||||
|
Username: "",
|
||||||
|
Password: "",
|
||||||
|
CleanSession: true,
|
||||||
|
Order: true,
|
||||||
|
WillEnabled: false,
|
||||||
|
WillTopic: "",
|
||||||
|
WillPayload: nil,
|
||||||
|
WillQos: 0,
|
||||||
|
WillRetained: false,
|
||||||
|
ProtocolVersion: 0,
|
||||||
|
protocolVersionExplicit: false,
|
||||||
|
KeepAlive: 30,
|
||||||
|
PingTimeout: 10 * time.Second,
|
||||||
|
ConnectTimeout: 30 * time.Second,
|
||||||
|
MaxReconnectInterval: 10 * time.Minute,
|
||||||
|
AutoReconnect: true,
|
||||||
|
ConnectRetryInterval: 30 * time.Second,
|
||||||
|
ConnectRetry: false,
|
||||||
|
Store: nil,
|
||||||
|
OnConnect: nil,
|
||||||
|
OnConnectionLost: DefaultConnectionLostHandler,
|
||||||
|
WriteTimeout: 0, // 0 represents timeout disabled
|
||||||
|
ResumeSubs: false,
|
||||||
|
HTTPHeaders: make(map[string][]string),
|
||||||
|
WebsocketOptions: &WebsocketOptions{},
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBroker adds a broker URI to the list of brokers to be used. The format should be
|
||||||
|
// scheme://host:port
|
||||||
|
// Where "scheme" is one of "tcp", "ssl", or "ws", "host" is the ip-address (or hostname)
|
||||||
|
// and "port" is the port on which the broker is accepting connections.
|
||||||
|
//
|
||||||
|
// Default values for hostname is "127.0.0.1", for schema is "tcp://".
|
||||||
|
//
|
||||||
|
// An example broker URI would look like: tcp://foobar.com:1883
|
||||||
|
func (o *ClientOptions) AddBroker(server string) *ClientOptions {
|
||||||
|
if len(server) > 0 && server[0] == ':' {
|
||||||
|
server = "127.0.0.1" + server
|
||||||
|
}
|
||||||
|
if !strings.Contains(server, "://") {
|
||||||
|
server = "tcp://" + server
|
||||||
|
}
|
||||||
|
brokerURI, err := url.Parse(server)
|
||||||
|
if err != nil {
|
||||||
|
ERROR.Println(CLI, "Failed to parse %q broker address: %s", server, err)
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
o.Servers = append(o.Servers, brokerURI)
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetResumeSubs will enable resuming of stored (un)subscribe messages when connecting
|
||||||
|
// but not reconnecting if CleanSession is false. Otherwise these messages are discarded.
|
||||||
|
func (o *ClientOptions) SetResumeSubs(resume bool) *ClientOptions {
|
||||||
|
o.ResumeSubs = resume
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetClientID will set the client id to be used by this client when
|
||||||
|
// connecting to the MQTT broker. According to the MQTT v3.1 specification,
|
||||||
|
// a client id must be no longer than 23 characters.
|
||||||
|
func (o *ClientOptions) SetClientID(id string) *ClientOptions {
|
||||||
|
o.ClientID = id
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUsername will set the username to be used by this client when connecting
|
||||||
|
// to the MQTT broker. Note: without the use of SSL/TLS, this information will
|
||||||
|
// be sent in plaintext across the wire.
|
||||||
|
func (o *ClientOptions) SetUsername(u string) *ClientOptions {
|
||||||
|
o.Username = u
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPassword will set the password to be used by this client when connecting
|
||||||
|
// to the MQTT broker. Note: without the use of SSL/TLS, this information will
|
||||||
|
// be sent in plaintext across the wire.
|
||||||
|
func (o *ClientOptions) SetPassword(p string) *ClientOptions {
|
||||||
|
o.Password = p
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCredentialsProvider will set a method to be called by this client when
|
||||||
|
// connecting to the MQTT broker that provide the current username and password.
|
||||||
|
// Note: without the use of SSL/TLS, this information will be sent
|
||||||
|
// in plaintext across the wire.
|
||||||
|
func (o *ClientOptions) SetCredentialsProvider(p CredentialsProvider) *ClientOptions {
|
||||||
|
o.CredentialsProvider = p
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCleanSession will set the "clean session" flag in the connect message
|
||||||
|
// when this client connects to an MQTT broker. By setting this flag, you are
|
||||||
|
// indicating that no messages saved by the broker for this client should be
|
||||||
|
// delivered. Any messages that were going to be sent by this client before
|
||||||
|
// disconnecting previously but didn't will not be sent upon connecting to the
|
||||||
|
// broker.
|
||||||
|
func (o *ClientOptions) SetCleanSession(clean bool) *ClientOptions {
|
||||||
|
o.CleanSession = clean
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOrderMatters will set the message routing to guarantee order within
|
||||||
|
// each QoS level. By default, this value is true. If set to false (recommended),
|
||||||
|
// this flag indicates that messages can be delivered asynchronously
|
||||||
|
// from the client to the application and possibly arrive out of order.
|
||||||
|
// Specifically, the message handler is called in its own go routine.
|
||||||
|
// Note that setting this to true does not guarantee in-order delivery
|
||||||
|
// (this is subject to broker settings like "max_inflight_messages=1" in mosquitto)
|
||||||
|
// and if true then handlers must not block.
|
||||||
|
func (o *ClientOptions) SetOrderMatters(order bool) *ClientOptions {
|
||||||
|
o.Order = order
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTLSConfig will set an SSL/TLS configuration to be used when connecting
|
||||||
|
// to an MQTT broker. Please read the official Go documentation for more
|
||||||
|
// information.
|
||||||
|
func (o *ClientOptions) SetTLSConfig(t *tls.Config) *ClientOptions {
|
||||||
|
o.TLSConfig = t
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStore will set the implementation of the Store interface
|
||||||
|
// used to provide message persistence in cases where QoS levels
|
||||||
|
// QoS_ONE or QoS_TWO are used. If no store is provided, then the
|
||||||
|
// client will use MemoryStore by default.
|
||||||
|
func (o *ClientOptions) SetStore(s Store) *ClientOptions {
|
||||||
|
o.Store = s
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKeepAlive will set the amount of time (in seconds) that the client
|
||||||
|
// should wait before sending a PING request to the broker. This will
|
||||||
|
// allow the client to know that a connection has not been lost with the
|
||||||
|
// server.
|
||||||
|
func (o *ClientOptions) SetKeepAlive(k time.Duration) *ClientOptions {
|
||||||
|
o.KeepAlive = int64(k / time.Second)
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPingTimeout will set the amount of time (in seconds) that the client
|
||||||
|
// will wait after sending a PING request to the broker, before deciding
|
||||||
|
// that the connection has been lost. Default is 10 seconds.
|
||||||
|
func (o *ClientOptions) SetPingTimeout(k time.Duration) *ClientOptions {
|
||||||
|
o.PingTimeout = k
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProtocolVersion sets the MQTT version to be used to connect to the
|
||||||
|
// broker. Legitimate values are currently 3 - MQTT 3.1 or 4 - MQTT 3.1.1
|
||||||
|
func (o *ClientOptions) SetProtocolVersion(pv uint) *ClientOptions {
|
||||||
|
if (pv >= 3 && pv <= 4) || (pv > 0x80) {
|
||||||
|
o.ProtocolVersion = pv
|
||||||
|
o.protocolVersionExplicit = true
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnsetWill will cause any set will message to be disregarded.
|
||||||
|
func (o *ClientOptions) UnsetWill() *ClientOptions {
|
||||||
|
o.WillEnabled = false
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWill accepts a string will message to be set. When the client connects,
|
||||||
|
// it will give this will message to the broker, which will then publish the
|
||||||
|
// provided payload (the will) to any clients that are subscribed to the provided
|
||||||
|
// topic.
|
||||||
|
func (o *ClientOptions) SetWill(topic string, payload string, qos byte, retained bool) *ClientOptions {
|
||||||
|
o.SetBinaryWill(topic, []byte(payload), qos, retained)
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBinaryWill accepts a []byte will message to be set. When the client connects,
|
||||||
|
// it will give this will message to the broker, which will then publish the
|
||||||
|
// provided payload (the will) to any clients that are subscribed to the provided
|
||||||
|
// topic.
|
||||||
|
func (o *ClientOptions) SetBinaryWill(topic string, payload []byte, qos byte, retained bool) *ClientOptions {
|
||||||
|
o.WillEnabled = true
|
||||||
|
o.WillTopic = topic
|
||||||
|
o.WillPayload = payload
|
||||||
|
o.WillQos = qos
|
||||||
|
o.WillRetained = retained
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDefaultPublishHandler sets the MessageHandler that will be called when a message
|
||||||
|
// is received that does not match any known subscriptions.
|
||||||
|
//
|
||||||
|
// If OrderMatters is true (the defaultHandler) then callback must not block or
|
||||||
|
// call functions within this package that may block (e.g. Publish) other than in
|
||||||
|
// a new go routine.
|
||||||
|
// defaultHandler must be safe for concurrent use by multiple goroutines.
|
||||||
|
func (o *ClientOptions) SetDefaultPublishHandler(defaultHandler MessageHandler) *ClientOptions {
|
||||||
|
o.DefaultPublishHandler = defaultHandler
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOnConnectHandler sets the function to be called when the client is connected. Both
|
||||||
|
// at initial connection time and upon automatic reconnect.
|
||||||
|
func (o *ClientOptions) SetOnConnectHandler(onConn OnConnectHandler) *ClientOptions {
|
||||||
|
o.OnConnect = onConn
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConnectionLostHandler will set the OnConnectionLost callback to be executed
|
||||||
|
// in the case where the client unexpectedly loses connection with the MQTT broker.
|
||||||
|
func (o *ClientOptions) SetConnectionLostHandler(onLost ConnectionLostHandler) *ClientOptions {
|
||||||
|
o.OnConnectionLost = onLost
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReconnectingHandler sets the OnReconnecting callback to be executed prior
|
||||||
|
// to the client attempting a reconnect to the MQTT broker.
|
||||||
|
func (o *ClientOptions) SetReconnectingHandler(cb ReconnectHandler) *ClientOptions {
|
||||||
|
o.OnReconnecting = cb
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWriteTimeout puts a limit on how long a mqtt publish should block until it unblocks with a
|
||||||
|
// timeout error. A duration of 0 never times out. Default never times out
|
||||||
|
func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions {
|
||||||
|
o.WriteTimeout = t
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConnectTimeout limits how long the client will wait when trying to open a connection
|
||||||
|
// to an MQTT server before timing out. A duration of 0 never times out.
|
||||||
|
// Default 30 seconds. Currently only operational on TCP/TLS connections.
|
||||||
|
func (o *ClientOptions) SetConnectTimeout(t time.Duration) *ClientOptions {
|
||||||
|
o.ConnectTimeout = t
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts
|
||||||
|
// when connection is lost
|
||||||
|
func (o *ClientOptions) SetMaxReconnectInterval(t time.Duration) *ClientOptions {
|
||||||
|
o.MaxReconnectInterval = t
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAutoReconnect sets whether the automatic reconnection logic should be used
|
||||||
|
// when the connection is lost, even if disabled the ConnectionLostHandler is still
|
||||||
|
// called
|
||||||
|
func (o *ClientOptions) SetAutoReconnect(a bool) *ClientOptions {
|
||||||
|
o.AutoReconnect = a
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConnectRetryInterval sets the time that will be waited between connection attempts
|
||||||
|
// when initially connecting if ConnectRetry is TRUE
|
||||||
|
func (o *ClientOptions) SetConnectRetryInterval(t time.Duration) *ClientOptions {
|
||||||
|
o.ConnectRetryInterval = t
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConnectRetry sets whether the connect function will automatically retry the connection
|
||||||
|
// in the event of a failure (when true the token returned by the Connect function will
|
||||||
|
// not complete until the connection is up or it is cancelled)
|
||||||
|
// If ConnectRetry is true then subscriptions should be requested in OnConnect handler
|
||||||
|
// Setting this to TRUE permits messages to be published before the connection is established
|
||||||
|
func (o *ClientOptions) SetConnectRetry(a bool) *ClientOptions {
|
||||||
|
o.ConnectRetry = a
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMessageChannelDepth DEPRECATED The value set here no longer has any effect, this function
|
||||||
|
// remains so the API is not altered.
|
||||||
|
func (o *ClientOptions) SetMessageChannelDepth(s uint) *ClientOptions {
|
||||||
|
o.MessageChannelDepth = s
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHTTPHeaders sets the additional HTTP headers that will be sent in the WebSocket
|
||||||
|
// opening handshake.
|
||||||
|
func (o *ClientOptions) SetHTTPHeaders(h http.Header) *ClientOptions {
|
||||||
|
o.HTTPHeaders = h
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWebsocketOptions sets the additional websocket options used in a WebSocket connection
|
||||||
|
func (o *ClientOptions) SetWebsocketOptions(w *WebsocketOptions) *ClientOptions {
|
||||||
|
o.WebsocketOptions = w
|
||||||
|
return o
|
||||||
|
}
|
||||||
167
vendor/github.com/eclipse/paho.mqtt.golang/options_reader.go
generated
vendored
Normal file
167
vendor/github.com/eclipse/paho.mqtt.golang/options_reader.go
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClientOptionsReader provides an interface for reading ClientOptions after the client has been initialized.
|
||||||
|
type ClientOptionsReader struct {
|
||||||
|
options *ClientOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// Servers returns a slice of the servers defined in the clientoptions
|
||||||
|
func (r *ClientOptionsReader) Servers() []*url.URL {
|
||||||
|
s := make([]*url.URL, len(r.options.Servers))
|
||||||
|
|
||||||
|
for i, u := range r.options.Servers {
|
||||||
|
nu := *u
|
||||||
|
s[i] = &nu
|
||||||
|
}
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResumeSubs returns true if resuming stored (un)sub is enabled
|
||||||
|
func (r *ClientOptionsReader) ResumeSubs() bool {
|
||||||
|
s := r.options.ResumeSubs
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientID returns the set client id
|
||||||
|
func (r *ClientOptionsReader) ClientID() string {
|
||||||
|
s := r.options.ClientID
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Username returns the set username
|
||||||
|
func (r *ClientOptionsReader) Username() string {
|
||||||
|
s := r.options.Username
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password returns the set password
|
||||||
|
func (r *ClientOptionsReader) Password() string {
|
||||||
|
s := r.options.Password
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// CleanSession returns whether Cleansession is set
|
||||||
|
func (r *ClientOptionsReader) CleanSession() bool {
|
||||||
|
s := r.options.CleanSession
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) Order() bool {
|
||||||
|
s := r.options.Order
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) WillEnabled() bool {
|
||||||
|
s := r.options.WillEnabled
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) WillTopic() string {
|
||||||
|
s := r.options.WillTopic
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) WillPayload() []byte {
|
||||||
|
s := r.options.WillPayload
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) WillQos() byte {
|
||||||
|
s := r.options.WillQos
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) WillRetained() bool {
|
||||||
|
s := r.options.WillRetained
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) ProtocolVersion() uint {
|
||||||
|
s := r.options.ProtocolVersion
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) TLSConfig() *tls.Config {
|
||||||
|
s := r.options.TLSConfig
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) KeepAlive() time.Duration {
|
||||||
|
s := time.Duration(r.options.KeepAlive * int64(time.Second))
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) PingTimeout() time.Duration {
|
||||||
|
s := r.options.PingTimeout
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) ConnectTimeout() time.Duration {
|
||||||
|
s := r.options.ConnectTimeout
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) MaxReconnectInterval() time.Duration {
|
||||||
|
s := r.options.MaxReconnectInterval
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) AutoReconnect() bool {
|
||||||
|
s := r.options.AutoReconnect
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConnectRetryInterval returns the delay between retries on the initial connection (if ConnectRetry true)
|
||||||
|
func (r *ClientOptionsReader) ConnectRetryInterval() time.Duration {
|
||||||
|
s := r.options.ConnectRetryInterval
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConnectRetry returns whether the initial connection request will be retried until connection established
|
||||||
|
func (r *ClientOptionsReader) ConnectRetry() bool {
|
||||||
|
s := r.options.ConnectRetry
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) WriteTimeout() time.Duration {
|
||||||
|
s := r.options.WriteTimeout
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) MessageChannelDepth() uint {
|
||||||
|
s := r.options.MessageChannelDepth
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientOptionsReader) HTTPHeaders() http.Header {
|
||||||
|
h := r.options.HTTPHeaders
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
// WebsocketOptions returns the currently configured WebSocket options
|
||||||
|
func (r *ClientOptionsReader) WebsocketOptions() *WebsocketOptions {
|
||||||
|
s := r.options.WebsocketOptions
|
||||||
|
return s
|
||||||
|
}
|
||||||
52
vendor/github.com/eclipse/paho.mqtt.golang/packets/connack.go
generated
vendored
Normal file
52
vendor/github.com/eclipse/paho.mqtt.golang/packets/connack.go
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConnackPacket is an internal representation of the fields of the
|
||||||
|
// Connack MQTT packet
|
||||||
|
type ConnackPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
SessionPresent bool
|
||||||
|
ReturnCode byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ca *ConnackPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s sessionpresent: %t returncode: %d", ca.FixedHeader, ca.SessionPresent, ca.ReturnCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ca *ConnackPacket) Write(w io.Writer) error {
|
||||||
|
var body bytes.Buffer
|
||||||
|
var err error
|
||||||
|
|
||||||
|
body.WriteByte(boolToByte(ca.SessionPresent))
|
||||||
|
body.WriteByte(ca.ReturnCode)
|
||||||
|
ca.FixedHeader.RemainingLength = 2
|
||||||
|
packet := ca.FixedHeader.pack()
|
||||||
|
packet.Write(body.Bytes())
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (ca *ConnackPacket) Unpack(b io.Reader) error {
|
||||||
|
flags, err := decodeByte(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ca.SessionPresent = 1&flags > 0
|
||||||
|
ca.ReturnCode, err = decodeByte(b)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (ca *ConnackPacket) Details() Details {
|
||||||
|
return Details{Qos: 0, MessageID: 0}
|
||||||
|
}
|
||||||
151
vendor/github.com/eclipse/paho.mqtt.golang/packets/connect.go
generated
vendored
Normal file
151
vendor/github.com/eclipse/paho.mqtt.golang/packets/connect.go
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConnectPacket is an internal representation of the fields of the
|
||||||
|
// Connect MQTT packet
|
||||||
|
type ConnectPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
ProtocolName string
|
||||||
|
ProtocolVersion byte
|
||||||
|
CleanSession bool
|
||||||
|
WillFlag bool
|
||||||
|
WillQos byte
|
||||||
|
WillRetain bool
|
||||||
|
UsernameFlag bool
|
||||||
|
PasswordFlag bool
|
||||||
|
ReservedBit byte
|
||||||
|
Keepalive uint16
|
||||||
|
|
||||||
|
ClientIdentifier string
|
||||||
|
WillTopic string
|
||||||
|
WillMessage []byte
|
||||||
|
Username string
|
||||||
|
Password []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnectPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s protocolversion: %d protocolname: %s cleansession: %t willflag: %t WillQos: %d WillRetain: %t Usernameflag: %t Passwordflag: %t keepalive: %d clientId: %s willtopic: %s willmessage: %s Username: %s Password: %s", c.FixedHeader, c.ProtocolVersion, c.ProtocolName, c.CleanSession, c.WillFlag, c.WillQos, c.WillRetain, c.UsernameFlag, c.PasswordFlag, c.Keepalive, c.ClientIdentifier, c.WillTopic, c.WillMessage, c.Username, c.Password)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnectPacket) Write(w io.Writer) error {
|
||||||
|
var body bytes.Buffer
|
||||||
|
var err error
|
||||||
|
|
||||||
|
body.Write(encodeString(c.ProtocolName))
|
||||||
|
body.WriteByte(c.ProtocolVersion)
|
||||||
|
body.WriteByte(boolToByte(c.CleanSession)<<1 | boolToByte(c.WillFlag)<<2 | c.WillQos<<3 | boolToByte(c.WillRetain)<<5 | boolToByte(c.PasswordFlag)<<6 | boolToByte(c.UsernameFlag)<<7)
|
||||||
|
body.Write(encodeUint16(c.Keepalive))
|
||||||
|
body.Write(encodeString(c.ClientIdentifier))
|
||||||
|
if c.WillFlag {
|
||||||
|
body.Write(encodeString(c.WillTopic))
|
||||||
|
body.Write(encodeBytes(c.WillMessage))
|
||||||
|
}
|
||||||
|
if c.UsernameFlag {
|
||||||
|
body.Write(encodeString(c.Username))
|
||||||
|
}
|
||||||
|
if c.PasswordFlag {
|
||||||
|
body.Write(encodeBytes(c.Password))
|
||||||
|
}
|
||||||
|
c.FixedHeader.RemainingLength = body.Len()
|
||||||
|
packet := c.FixedHeader.pack()
|
||||||
|
packet.Write(body.Bytes())
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (c *ConnectPacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
c.ProtocolName, err = decodeString(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.ProtocolVersion, err = decodeByte(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
options, err := decodeByte(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.ReservedBit = 1 & options
|
||||||
|
c.CleanSession = 1&(options>>1) > 0
|
||||||
|
c.WillFlag = 1&(options>>2) > 0
|
||||||
|
c.WillQos = 3 & (options >> 3)
|
||||||
|
c.WillRetain = 1&(options>>5) > 0
|
||||||
|
c.PasswordFlag = 1&(options>>6) > 0
|
||||||
|
c.UsernameFlag = 1&(options>>7) > 0
|
||||||
|
c.Keepalive, err = decodeUint16(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.ClientIdentifier, err = decodeString(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if c.WillFlag {
|
||||||
|
c.WillTopic, err = decodeString(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.WillMessage, err = decodeBytes(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c.UsernameFlag {
|
||||||
|
c.Username, err = decodeString(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c.PasswordFlag {
|
||||||
|
c.Password, err = decodeBytes(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate performs validation of the fields of a Connect packet
|
||||||
|
func (c *ConnectPacket) Validate() byte {
|
||||||
|
if c.PasswordFlag && !c.UsernameFlag {
|
||||||
|
return ErrRefusedBadUsernameOrPassword
|
||||||
|
}
|
||||||
|
if c.ReservedBit != 0 {
|
||||||
|
// Bad reserved bit
|
||||||
|
return ErrProtocolViolation
|
||||||
|
}
|
||||||
|
if (c.ProtocolName == "MQIsdp" && c.ProtocolVersion != 3) || (c.ProtocolName == "MQTT" && c.ProtocolVersion != 4) {
|
||||||
|
// Mismatched or unsupported protocol version
|
||||||
|
return ErrRefusedBadProtocolVersion
|
||||||
|
}
|
||||||
|
if c.ProtocolName != "MQIsdp" && c.ProtocolName != "MQTT" {
|
||||||
|
// Bad protocol name
|
||||||
|
return ErrProtocolViolation
|
||||||
|
}
|
||||||
|
if len(c.ClientIdentifier) > 65535 || len(c.Username) > 65535 || len(c.Password) > 65535 {
|
||||||
|
// Bad size field
|
||||||
|
return ErrProtocolViolation
|
||||||
|
}
|
||||||
|
if len(c.ClientIdentifier) == 0 && !c.CleanSession {
|
||||||
|
// Bad client identifier
|
||||||
|
return ErrRefusedIDRejected
|
||||||
|
}
|
||||||
|
return Accepted
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (c *ConnectPacket) Details() Details {
|
||||||
|
return Details{Qos: 0, MessageID: 0}
|
||||||
|
}
|
||||||
34
vendor/github.com/eclipse/paho.mqtt.golang/packets/disconnect.go
generated
vendored
Normal file
34
vendor/github.com/eclipse/paho.mqtt.golang/packets/disconnect.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DisconnectPacket is an internal representation of the fields of the
|
||||||
|
// Disconnect MQTT packet
|
||||||
|
type DisconnectPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DisconnectPacket) String() string {
|
||||||
|
return d.FixedHeader.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DisconnectPacket) Write(w io.Writer) error {
|
||||||
|
packet := d.FixedHeader.pack()
|
||||||
|
_, err := packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (d *DisconnectPacket) Unpack(b io.Reader) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (d *DisconnectPacket) Details() Details {
|
||||||
|
return Details{Qos: 0, MessageID: 0}
|
||||||
|
}
|
||||||
356
vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go
generated
vendored
Normal file
356
vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go
generated
vendored
Normal file
@@ -0,0 +1,356 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ControlPacket defines the interface for structs intended to hold
|
||||||
|
// decoded MQTT packets, either from being read or before being
|
||||||
|
// written
|
||||||
|
type ControlPacket interface {
|
||||||
|
Write(io.Writer) error
|
||||||
|
Unpack(io.Reader) error
|
||||||
|
String() string
|
||||||
|
Details() Details
|
||||||
|
}
|
||||||
|
|
||||||
|
// PacketNames maps the constants for each of the MQTT packet types
|
||||||
|
// to a string representation of their name.
|
||||||
|
var PacketNames = map[uint8]string{
|
||||||
|
1: "CONNECT",
|
||||||
|
2: "CONNACK",
|
||||||
|
3: "PUBLISH",
|
||||||
|
4: "PUBACK",
|
||||||
|
5: "PUBREC",
|
||||||
|
6: "PUBREL",
|
||||||
|
7: "PUBCOMP",
|
||||||
|
8: "SUBSCRIBE",
|
||||||
|
9: "SUBACK",
|
||||||
|
10: "UNSUBSCRIBE",
|
||||||
|
11: "UNSUBACK",
|
||||||
|
12: "PINGREQ",
|
||||||
|
13: "PINGRESP",
|
||||||
|
14: "DISCONNECT",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Below are the constants assigned to each of the MQTT packet types
|
||||||
|
const (
|
||||||
|
Connect = 1
|
||||||
|
Connack = 2
|
||||||
|
Publish = 3
|
||||||
|
Puback = 4
|
||||||
|
Pubrec = 5
|
||||||
|
Pubrel = 6
|
||||||
|
Pubcomp = 7
|
||||||
|
Subscribe = 8
|
||||||
|
Suback = 9
|
||||||
|
Unsubscribe = 10
|
||||||
|
Unsuback = 11
|
||||||
|
Pingreq = 12
|
||||||
|
Pingresp = 13
|
||||||
|
Disconnect = 14
|
||||||
|
)
|
||||||
|
|
||||||
|
// Below are the const definitions for error codes returned by
|
||||||
|
// Connect()
|
||||||
|
const (
|
||||||
|
Accepted = 0x00
|
||||||
|
ErrRefusedBadProtocolVersion = 0x01
|
||||||
|
ErrRefusedIDRejected = 0x02
|
||||||
|
ErrRefusedServerUnavailable = 0x03
|
||||||
|
ErrRefusedBadUsernameOrPassword = 0x04
|
||||||
|
ErrRefusedNotAuthorised = 0x05
|
||||||
|
ErrNetworkError = 0xFE
|
||||||
|
ErrProtocolViolation = 0xFF
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConnackReturnCodes is a map of the error codes constants for Connect()
|
||||||
|
// to a string representation of the error
|
||||||
|
var ConnackReturnCodes = map[uint8]string{
|
||||||
|
0: "Connection Accepted",
|
||||||
|
1: "Connection Refused: Bad Protocol Version",
|
||||||
|
2: "Connection Refused: Client Identifier Rejected",
|
||||||
|
3: "Connection Refused: Server Unavailable",
|
||||||
|
4: "Connection Refused: Username or Password in unknown format",
|
||||||
|
5: "Connection Refused: Not Authorised",
|
||||||
|
254: "Connection Error",
|
||||||
|
255: "Connection Refused: Protocol Violation",
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrorRefusedBadProtocolVersion = errors.New("unacceptable protocol version")
|
||||||
|
ErrorRefusedIDRejected = errors.New("identifier rejected")
|
||||||
|
ErrorRefusedServerUnavailable = errors.New("server Unavailable")
|
||||||
|
ErrorRefusedBadUsernameOrPassword = errors.New("bad user name or password")
|
||||||
|
ErrorRefusedNotAuthorised = errors.New("not Authorized")
|
||||||
|
ErrorNetworkError = errors.New("network Error")
|
||||||
|
ErrorProtocolViolation = errors.New("protocol Violation")
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConnErrors is a map of the errors codes constants for Connect()
|
||||||
|
// to a Go error
|
||||||
|
var ConnErrors = map[byte]error{
|
||||||
|
Accepted: nil,
|
||||||
|
ErrRefusedBadProtocolVersion: ErrorRefusedBadProtocolVersion,
|
||||||
|
ErrRefusedIDRejected: ErrorRefusedIDRejected,
|
||||||
|
ErrRefusedServerUnavailable: ErrorRefusedServerUnavailable,
|
||||||
|
ErrRefusedBadUsernameOrPassword: ErrorRefusedBadUsernameOrPassword,
|
||||||
|
ErrRefusedNotAuthorised: ErrorRefusedNotAuthorised,
|
||||||
|
ErrNetworkError: ErrorNetworkError,
|
||||||
|
ErrProtocolViolation: ErrorProtocolViolation,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadPacket takes an instance of an io.Reader (such as net.Conn) and attempts
|
||||||
|
// to read an MQTT packet from the stream. It returns a ControlPacket
|
||||||
|
// representing the decoded MQTT packet and an error. One of these returns will
|
||||||
|
// always be nil, a nil ControlPacket indicating an error occurred.
|
||||||
|
func ReadPacket(r io.Reader) (ControlPacket, error) {
|
||||||
|
var fh FixedHeader
|
||||||
|
b := make([]byte, 1)
|
||||||
|
|
||||||
|
_, err := io.ReadFull(r, b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = fh.unpack(b[0], r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cp, err := NewControlPacketWithHeader(fh)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
packetBytes := make([]byte, fh.RemainingLength)
|
||||||
|
n, err := io.ReadFull(r, packetBytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if n != fh.RemainingLength {
|
||||||
|
return nil, errors.New("failed to read expected data")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cp.Unpack(bytes.NewBuffer(packetBytes))
|
||||||
|
return cp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewControlPacket is used to create a new ControlPacket of the type specified
|
||||||
|
// by packetType, this is usually done by reference to the packet type constants
|
||||||
|
// defined in packets.go. The newly created ControlPacket is empty and a pointer
|
||||||
|
// is returned.
|
||||||
|
func NewControlPacket(packetType byte) ControlPacket {
|
||||||
|
switch packetType {
|
||||||
|
case Connect:
|
||||||
|
return &ConnectPacket{FixedHeader: FixedHeader{MessageType: Connect}}
|
||||||
|
case Connack:
|
||||||
|
return &ConnackPacket{FixedHeader: FixedHeader{MessageType: Connack}}
|
||||||
|
case Disconnect:
|
||||||
|
return &DisconnectPacket{FixedHeader: FixedHeader{MessageType: Disconnect}}
|
||||||
|
case Publish:
|
||||||
|
return &PublishPacket{FixedHeader: FixedHeader{MessageType: Publish}}
|
||||||
|
case Puback:
|
||||||
|
return &PubackPacket{FixedHeader: FixedHeader{MessageType: Puback}}
|
||||||
|
case Pubrec:
|
||||||
|
return &PubrecPacket{FixedHeader: FixedHeader{MessageType: Pubrec}}
|
||||||
|
case Pubrel:
|
||||||
|
return &PubrelPacket{FixedHeader: FixedHeader{MessageType: Pubrel, Qos: 1}}
|
||||||
|
case Pubcomp:
|
||||||
|
return &PubcompPacket{FixedHeader: FixedHeader{MessageType: Pubcomp}}
|
||||||
|
case Subscribe:
|
||||||
|
return &SubscribePacket{FixedHeader: FixedHeader{MessageType: Subscribe, Qos: 1}}
|
||||||
|
case Suback:
|
||||||
|
return &SubackPacket{FixedHeader: FixedHeader{MessageType: Suback}}
|
||||||
|
case Unsubscribe:
|
||||||
|
return &UnsubscribePacket{FixedHeader: FixedHeader{MessageType: Unsubscribe, Qos: 1}}
|
||||||
|
case Unsuback:
|
||||||
|
return &UnsubackPacket{FixedHeader: FixedHeader{MessageType: Unsuback}}
|
||||||
|
case Pingreq:
|
||||||
|
return &PingreqPacket{FixedHeader: FixedHeader{MessageType: Pingreq}}
|
||||||
|
case Pingresp:
|
||||||
|
return &PingrespPacket{FixedHeader: FixedHeader{MessageType: Pingresp}}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewControlPacketWithHeader is used to create a new ControlPacket of the type
|
||||||
|
// specified within the FixedHeader that is passed to the function.
|
||||||
|
// The newly created ControlPacket is empty and a pointer is returned.
|
||||||
|
func NewControlPacketWithHeader(fh FixedHeader) (ControlPacket, error) {
|
||||||
|
switch fh.MessageType {
|
||||||
|
case Connect:
|
||||||
|
return &ConnectPacket{FixedHeader: fh}, nil
|
||||||
|
case Connack:
|
||||||
|
return &ConnackPacket{FixedHeader: fh}, nil
|
||||||
|
case Disconnect:
|
||||||
|
return &DisconnectPacket{FixedHeader: fh}, nil
|
||||||
|
case Publish:
|
||||||
|
return &PublishPacket{FixedHeader: fh}, nil
|
||||||
|
case Puback:
|
||||||
|
return &PubackPacket{FixedHeader: fh}, nil
|
||||||
|
case Pubrec:
|
||||||
|
return &PubrecPacket{FixedHeader: fh}, nil
|
||||||
|
case Pubrel:
|
||||||
|
return &PubrelPacket{FixedHeader: fh}, nil
|
||||||
|
case Pubcomp:
|
||||||
|
return &PubcompPacket{FixedHeader: fh}, nil
|
||||||
|
case Subscribe:
|
||||||
|
return &SubscribePacket{FixedHeader: fh}, nil
|
||||||
|
case Suback:
|
||||||
|
return &SubackPacket{FixedHeader: fh}, nil
|
||||||
|
case Unsubscribe:
|
||||||
|
return &UnsubscribePacket{FixedHeader: fh}, nil
|
||||||
|
case Unsuback:
|
||||||
|
return &UnsubackPacket{FixedHeader: fh}, nil
|
||||||
|
case Pingreq:
|
||||||
|
return &PingreqPacket{FixedHeader: fh}, nil
|
||||||
|
case Pingresp:
|
||||||
|
return &PingrespPacket{FixedHeader: fh}, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unsupported packet type 0x%x", fh.MessageType)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details struct returned by the Details() function called on
|
||||||
|
// ControlPackets to present details of the Qos and MessageID
|
||||||
|
// of the ControlPacket
|
||||||
|
type Details struct {
|
||||||
|
Qos byte
|
||||||
|
MessageID uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedHeader is a struct to hold the decoded information from
|
||||||
|
// the fixed header of an MQTT ControlPacket
|
||||||
|
type FixedHeader struct {
|
||||||
|
MessageType byte
|
||||||
|
Dup bool
|
||||||
|
Qos byte
|
||||||
|
Retain bool
|
||||||
|
RemainingLength int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fh FixedHeader) String() string {
|
||||||
|
return fmt.Sprintf("%s: dup: %t qos: %d retain: %t rLength: %d", PacketNames[fh.MessageType], fh.Dup, fh.Qos, fh.Retain, fh.RemainingLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
func boolToByte(b bool) byte {
|
||||||
|
switch b {
|
||||||
|
case true:
|
||||||
|
return 1
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fh *FixedHeader) pack() bytes.Buffer {
|
||||||
|
var header bytes.Buffer
|
||||||
|
header.WriteByte(fh.MessageType<<4 | boolToByte(fh.Dup)<<3 | fh.Qos<<1 | boolToByte(fh.Retain))
|
||||||
|
header.Write(encodeLength(fh.RemainingLength))
|
||||||
|
return header
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fh *FixedHeader) unpack(typeAndFlags byte, r io.Reader) error {
|
||||||
|
fh.MessageType = typeAndFlags >> 4
|
||||||
|
fh.Dup = (typeAndFlags>>3)&0x01 > 0
|
||||||
|
fh.Qos = (typeAndFlags >> 1) & 0x03
|
||||||
|
fh.Retain = typeAndFlags&0x01 > 0
|
||||||
|
|
||||||
|
var err error
|
||||||
|
fh.RemainingLength, err = decodeLength(r)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeByte(b io.Reader) (byte, error) {
|
||||||
|
num := make([]byte, 1)
|
||||||
|
_, err := b.Read(num)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return num[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeUint16(b io.Reader) (uint16, error) {
|
||||||
|
num := make([]byte, 2)
|
||||||
|
_, err := b.Read(num)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return binary.BigEndian.Uint16(num), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeUint16(num uint16) []byte {
|
||||||
|
bytesResult := make([]byte, 2)
|
||||||
|
binary.BigEndian.PutUint16(bytesResult, num)
|
||||||
|
return bytesResult
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeString(field string) []byte {
|
||||||
|
return encodeBytes([]byte(field))
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeString(b io.Reader) (string, error) {
|
||||||
|
buf, err := decodeBytes(b)
|
||||||
|
return string(buf), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeBytes(b io.Reader) ([]byte, error) {
|
||||||
|
fieldLength, err := decodeUint16(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
field := make([]byte, fieldLength)
|
||||||
|
_, err = b.Read(field)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return field, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeBytes(field []byte) []byte {
|
||||||
|
fieldLength := make([]byte, 2)
|
||||||
|
binary.BigEndian.PutUint16(fieldLength, uint16(len(field)))
|
||||||
|
return append(fieldLength, field...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeLength(length int) []byte {
|
||||||
|
var encLength []byte
|
||||||
|
for {
|
||||||
|
digit := byte(length % 128)
|
||||||
|
length /= 128
|
||||||
|
if length > 0 {
|
||||||
|
digit |= 0x80
|
||||||
|
}
|
||||||
|
encLength = append(encLength, digit)
|
||||||
|
if length == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return encLength
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeLength(r io.Reader) (int, error) {
|
||||||
|
var rLength uint32
|
||||||
|
var multiplier uint32
|
||||||
|
b := make([]byte, 1)
|
||||||
|
for multiplier < 27 { // fix: Infinite '(digit & 128) == 1' will cause the dead loop
|
||||||
|
_, err := io.ReadFull(r, b)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
digit := b[0]
|
||||||
|
rLength |= uint32(digit&127) << multiplier
|
||||||
|
if (digit & 128) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
multiplier += 7
|
||||||
|
}
|
||||||
|
return int(rLength), nil
|
||||||
|
}
|
||||||
34
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingreq.go
generated
vendored
Normal file
34
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingreq.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PingreqPacket is an internal representation of the fields of the
|
||||||
|
// Pingreq MQTT packet
|
||||||
|
type PingreqPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PingreqPacket) String() string {
|
||||||
|
return pr.FixedHeader.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PingreqPacket) Write(w io.Writer) error {
|
||||||
|
packet := pr.FixedHeader.pack()
|
||||||
|
_, err := packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (pr *PingreqPacket) Unpack(b io.Reader) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (pr *PingreqPacket) Details() Details {
|
||||||
|
return Details{Qos: 0, MessageID: 0}
|
||||||
|
}
|
||||||
34
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingresp.go
generated
vendored
Normal file
34
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingresp.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PingrespPacket is an internal representation of the fields of the
|
||||||
|
// Pingresp MQTT packet
|
||||||
|
type PingrespPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PingrespPacket) String() string {
|
||||||
|
return pr.FixedHeader.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PingrespPacket) Write(w io.Writer) error {
|
||||||
|
packet := pr.FixedHeader.pack()
|
||||||
|
_, err := packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (pr *PingrespPacket) Unpack(b io.Reader) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (pr *PingrespPacket) Details() Details {
|
||||||
|
return Details{Qos: 0, MessageID: 0}
|
||||||
|
}
|
||||||
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/puback.go
generated
vendored
Normal file
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/puback.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PubackPacket is an internal representation of the fields of the
|
||||||
|
// Puback MQTT packet
|
||||||
|
type PubackPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pa *PubackPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d", pa.FixedHeader, pa.MessageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pa *PubackPacket) Write(w io.Writer) error {
|
||||||
|
var err error
|
||||||
|
pa.FixedHeader.RemainingLength = 2
|
||||||
|
packet := pa.FixedHeader.pack()
|
||||||
|
packet.Write(encodeUint16(pa.MessageID))
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (pa *PubackPacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
pa.MessageID, err = decodeUint16(b)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (pa *PubackPacket) Details() Details {
|
||||||
|
return Details{Qos: pa.Qos, MessageID: pa.MessageID}
|
||||||
|
}
|
||||||
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubcomp.go
generated
vendored
Normal file
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubcomp.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PubcompPacket is an internal representation of the fields of the
|
||||||
|
// Pubcomp MQTT packet
|
||||||
|
type PubcompPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *PubcompPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d", pc.FixedHeader, pc.MessageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *PubcompPacket) Write(w io.Writer) error {
|
||||||
|
var err error
|
||||||
|
pc.FixedHeader.RemainingLength = 2
|
||||||
|
packet := pc.FixedHeader.pack()
|
||||||
|
packet.Write(encodeUint16(pc.MessageID))
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (pc *PubcompPacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
pc.MessageID, err = decodeUint16(b)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (pc *PubcompPacket) Details() Details {
|
||||||
|
return Details{Qos: pc.Qos, MessageID: pc.MessageID}
|
||||||
|
}
|
||||||
83
vendor/github.com/eclipse/paho.mqtt.golang/packets/publish.go
generated
vendored
Normal file
83
vendor/github.com/eclipse/paho.mqtt.golang/packets/publish.go
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PublishPacket is an internal representation of the fields of the
|
||||||
|
// Publish MQTT packet
|
||||||
|
type PublishPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
TopicName string
|
||||||
|
MessageID uint16
|
||||||
|
Payload []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PublishPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s topicName: %s MessageID: %d payload: %s", p.FixedHeader, p.TopicName, p.MessageID, string(p.Payload))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PublishPacket) Write(w io.Writer) error {
|
||||||
|
var body bytes.Buffer
|
||||||
|
var err error
|
||||||
|
|
||||||
|
body.Write(encodeString(p.TopicName))
|
||||||
|
if p.Qos > 0 {
|
||||||
|
body.Write(encodeUint16(p.MessageID))
|
||||||
|
}
|
||||||
|
p.FixedHeader.RemainingLength = body.Len() + len(p.Payload)
|
||||||
|
packet := p.FixedHeader.pack()
|
||||||
|
packet.Write(body.Bytes())
|
||||||
|
packet.Write(p.Payload)
|
||||||
|
_, err = w.Write(packet.Bytes())
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (p *PublishPacket) Unpack(b io.Reader) error {
|
||||||
|
var payloadLength = p.FixedHeader.RemainingLength
|
||||||
|
var err error
|
||||||
|
p.TopicName, err = decodeString(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Qos > 0 {
|
||||||
|
p.MessageID, err = decodeUint16(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
payloadLength -= len(p.TopicName) + 4
|
||||||
|
} else {
|
||||||
|
payloadLength -= len(p.TopicName) + 2
|
||||||
|
}
|
||||||
|
if payloadLength < 0 {
|
||||||
|
return fmt.Errorf("error unpacking publish, payload length < 0")
|
||||||
|
}
|
||||||
|
p.Payload = make([]byte, payloadLength)
|
||||||
|
_, err = b.Read(p.Payload)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy creates a new PublishPacket with the same topic and payload
|
||||||
|
// but an empty fixed header, useful for when you want to deliver
|
||||||
|
// a message with different properties such as Qos but the same
|
||||||
|
// content
|
||||||
|
func (p *PublishPacket) Copy() *PublishPacket {
|
||||||
|
newP := NewControlPacket(Publish).(*PublishPacket)
|
||||||
|
newP.TopicName = p.TopicName
|
||||||
|
newP.Payload = p.Payload
|
||||||
|
|
||||||
|
return newP
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (p *PublishPacket) Details() Details {
|
||||||
|
return Details{Qos: p.Qos, MessageID: p.MessageID}
|
||||||
|
}
|
||||||
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrec.go
generated
vendored
Normal file
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrec.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PubrecPacket is an internal representation of the fields of the
|
||||||
|
// Pubrec MQTT packet
|
||||||
|
type PubrecPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PubrecPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d", pr.FixedHeader, pr.MessageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PubrecPacket) Write(w io.Writer) error {
|
||||||
|
var err error
|
||||||
|
pr.FixedHeader.RemainingLength = 2
|
||||||
|
packet := pr.FixedHeader.pack()
|
||||||
|
packet.Write(encodeUint16(pr.MessageID))
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (pr *PubrecPacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
pr.MessageID, err = decodeUint16(b)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (pr *PubrecPacket) Details() Details {
|
||||||
|
return Details{Qos: pr.Qos, MessageID: pr.MessageID}
|
||||||
|
}
|
||||||
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrel.go
generated
vendored
Normal file
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrel.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PubrelPacket is an internal representation of the fields of the
|
||||||
|
// Pubrel MQTT packet
|
||||||
|
type PubrelPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PubrelPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d", pr.FixedHeader, pr.MessageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *PubrelPacket) Write(w io.Writer) error {
|
||||||
|
var err error
|
||||||
|
pr.FixedHeader.RemainingLength = 2
|
||||||
|
packet := pr.FixedHeader.pack()
|
||||||
|
packet.Write(encodeUint16(pr.MessageID))
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (pr *PubrelPacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
pr.MessageID, err = decodeUint16(b)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (pr *PubrelPacket) Details() Details {
|
||||||
|
return Details{Qos: pr.Qos, MessageID: pr.MessageID}
|
||||||
|
}
|
||||||
57
vendor/github.com/eclipse/paho.mqtt.golang/packets/suback.go
generated
vendored
Normal file
57
vendor/github.com/eclipse/paho.mqtt.golang/packets/suback.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SubackPacket is an internal representation of the fields of the
|
||||||
|
// Suback MQTT packet
|
||||||
|
type SubackPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
ReturnCodes []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sa *SubackPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d", sa.FixedHeader, sa.MessageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sa *SubackPacket) Write(w io.Writer) error {
|
||||||
|
var body bytes.Buffer
|
||||||
|
var err error
|
||||||
|
body.Write(encodeUint16(sa.MessageID))
|
||||||
|
body.Write(sa.ReturnCodes)
|
||||||
|
sa.FixedHeader.RemainingLength = body.Len()
|
||||||
|
packet := sa.FixedHeader.pack()
|
||||||
|
packet.Write(body.Bytes())
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (sa *SubackPacket) Unpack(b io.Reader) error {
|
||||||
|
var qosBuffer bytes.Buffer
|
||||||
|
var err error
|
||||||
|
sa.MessageID, err = decodeUint16(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = qosBuffer.ReadFrom(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sa.ReturnCodes = qosBuffer.Bytes()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (sa *SubackPacket) Details() Details {
|
||||||
|
return Details{Qos: 0, MessageID: sa.MessageID}
|
||||||
|
}
|
||||||
69
vendor/github.com/eclipse/paho.mqtt.golang/packets/subscribe.go
generated
vendored
Normal file
69
vendor/github.com/eclipse/paho.mqtt.golang/packets/subscribe.go
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SubscribePacket is an internal representation of the fields of the
|
||||||
|
// Subscribe MQTT packet
|
||||||
|
type SubscribePacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
Topics []string
|
||||||
|
Qoss []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SubscribePacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d topics: %s", s.FixedHeader, s.MessageID, s.Topics)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SubscribePacket) Write(w io.Writer) error {
|
||||||
|
var body bytes.Buffer
|
||||||
|
var err error
|
||||||
|
|
||||||
|
body.Write(encodeUint16(s.MessageID))
|
||||||
|
for i, topic := range s.Topics {
|
||||||
|
body.Write(encodeString(topic))
|
||||||
|
body.WriteByte(s.Qoss[i])
|
||||||
|
}
|
||||||
|
s.FixedHeader.RemainingLength = body.Len()
|
||||||
|
packet := s.FixedHeader.pack()
|
||||||
|
packet.Write(body.Bytes())
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (s *SubscribePacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
s.MessageID, err = decodeUint16(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
payloadLength := s.FixedHeader.RemainingLength - 2
|
||||||
|
for payloadLength > 0 {
|
||||||
|
topic, err := decodeString(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.Topics = append(s.Topics, topic)
|
||||||
|
qos, err := decodeByte(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.Qoss = append(s.Qoss, qos)
|
||||||
|
payloadLength -= 2 + len(topic) + 1 // 2 bytes of string length, plus string, plus 1 byte for Qos
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (s *SubscribePacket) Details() Details {
|
||||||
|
return Details{Qos: 1, MessageID: s.MessageID}
|
||||||
|
}
|
||||||
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsuback.go
generated
vendored
Normal file
42
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsuback.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UnsubackPacket is an internal representation of the fields of the
|
||||||
|
// Unsuback MQTT packet
|
||||||
|
type UnsubackPacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ua *UnsubackPacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d", ua.FixedHeader, ua.MessageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ua *UnsubackPacket) Write(w io.Writer) error {
|
||||||
|
var err error
|
||||||
|
ua.FixedHeader.RemainingLength = 2
|
||||||
|
packet := ua.FixedHeader.pack()
|
||||||
|
packet.Write(encodeUint16(ua.MessageID))
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (ua *UnsubackPacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
ua.MessageID, err = decodeUint16(b)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (ua *UnsubackPacket) Details() Details {
|
||||||
|
return Details{Qos: 0, MessageID: ua.MessageID}
|
||||||
|
}
|
||||||
56
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsubscribe.go
generated
vendored
Normal file
56
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsubscribe.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UnsubscribePacket is an internal representation of the fields of the
|
||||||
|
// Unsubscribe MQTT packet
|
||||||
|
type UnsubscribePacket struct {
|
||||||
|
FixedHeader
|
||||||
|
MessageID uint16
|
||||||
|
Topics []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UnsubscribePacket) String() string {
|
||||||
|
return fmt.Sprintf("%s MessageID: %d", u.FixedHeader, u.MessageID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UnsubscribePacket) Write(w io.Writer) error {
|
||||||
|
var body bytes.Buffer
|
||||||
|
var err error
|
||||||
|
body.Write(encodeUint16(u.MessageID))
|
||||||
|
for _, topic := range u.Topics {
|
||||||
|
body.Write(encodeString(topic))
|
||||||
|
}
|
||||||
|
u.FixedHeader.RemainingLength = body.Len()
|
||||||
|
packet := u.FixedHeader.pack()
|
||||||
|
packet.Write(body.Bytes())
|
||||||
|
_, err = packet.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unpack decodes the details of a ControlPacket after the fixed
|
||||||
|
// header has been read
|
||||||
|
func (u *UnsubscribePacket) Unpack(b io.Reader) error {
|
||||||
|
var err error
|
||||||
|
u.MessageID, err = decodeUint16(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for topic, err := decodeString(b); err == nil && topic != ""; topic, err = decodeString(b) {
|
||||||
|
u.Topics = append(u.Topics, topic)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details returns a Details struct containing the Qos and
|
||||||
|
// MessageID of this ControlPacket
|
||||||
|
func (u *UnsubscribePacket) Details() Details {
|
||||||
|
return Details{Qos: 1, MessageID: u.MessageID}
|
||||||
|
}
|
||||||
74
vendor/github.com/eclipse/paho.mqtt.golang/ping.go
generated
vendored
Normal file
74
vendor/github.com/eclipse/paho.mqtt.golang/ping.go
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// keepalive - Send ping when connection unused for set period
|
||||||
|
// connection passed in to avoid race condition on shutdown
|
||||||
|
func keepalive(c *client, conn io.Writer) {
|
||||||
|
defer c.workers.Done()
|
||||||
|
DEBUG.Println(PNG, "keepalive starting")
|
||||||
|
var checkInterval int64
|
||||||
|
var pingSent time.Time
|
||||||
|
|
||||||
|
if c.options.KeepAlive > 10 {
|
||||||
|
checkInterval = 5
|
||||||
|
} else {
|
||||||
|
checkInterval = c.options.KeepAlive / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
intervalTicker := time.NewTicker(time.Duration(checkInterval * int64(time.Second)))
|
||||||
|
defer intervalTicker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-c.stop:
|
||||||
|
DEBUG.Println(PNG, "keepalive stopped")
|
||||||
|
return
|
||||||
|
case <-intervalTicker.C:
|
||||||
|
lastSent := c.lastSent.Load().(time.Time)
|
||||||
|
lastReceived := c.lastReceived.Load().(time.Time)
|
||||||
|
|
||||||
|
DEBUG.Println(PNG, "ping check", time.Since(lastSent).Seconds())
|
||||||
|
if time.Since(lastSent) >= time.Duration(c.options.KeepAlive*int64(time.Second)) || time.Since(lastReceived) >= time.Duration(c.options.KeepAlive*int64(time.Second)) {
|
||||||
|
if atomic.LoadInt32(&c.pingOutstanding) == 0 {
|
||||||
|
DEBUG.Println(PNG, "keepalive sending ping")
|
||||||
|
ping := packets.NewControlPacket(packets.Pingreq).(*packets.PingreqPacket)
|
||||||
|
// We don't want to wait behind large messages being sent, the Write call
|
||||||
|
// will block until it it able to send the packet.
|
||||||
|
atomic.StoreInt32(&c.pingOutstanding, 1)
|
||||||
|
if err := ping.Write(conn); err != nil {
|
||||||
|
ERROR.Println(PNG, err)
|
||||||
|
}
|
||||||
|
c.lastSent.Store(time.Now())
|
||||||
|
pingSent = time.Now()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if atomic.LoadInt32(&c.pingOutstanding) > 0 && time.Since(pingSent) >= c.options.PingTimeout {
|
||||||
|
CRITICAL.Println(PNG, "pingresp not received, disconnecting")
|
||||||
|
c.internalConnLost(errors.New("pingresp not received, disconnecting")) // no harm in calling this if the connection is already down (or shutdown is in progress)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
182
vendor/github.com/eclipse/paho.mqtt.golang/router.go
generated
vendored
Normal file
182
vendor/github.com/eclipse/paho.mqtt.golang/router.go
generated
vendored
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"container/list"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
// route is a type which associates MQTT Topic strings with a
|
||||||
|
// callback to be executed upon the arrival of a message associated
|
||||||
|
// with a subscription to that topic.
|
||||||
|
type route struct {
|
||||||
|
topic string
|
||||||
|
callback MessageHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
// match takes a slice of strings which represent the route being tested having been split on '/'
|
||||||
|
// separators, and a slice of strings representing the topic string in the published message, similarly
|
||||||
|
// split.
|
||||||
|
// The function determines if the topic string matches the route according to the MQTT topic rules
|
||||||
|
// and returns a boolean of the outcome
|
||||||
|
func match(route []string, topic []string) bool {
|
||||||
|
if len(route) == 0 {
|
||||||
|
return len(topic) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(topic) == 0 {
|
||||||
|
return route[0] == "#"
|
||||||
|
}
|
||||||
|
|
||||||
|
if route[0] == "#" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (route[0] == "+") || (route[0] == topic[0]) {
|
||||||
|
return match(route[1:], topic[1:])
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func routeIncludesTopic(route, topic string) bool {
|
||||||
|
return match(routeSplit(route), strings.Split(topic, "/"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// removes $share and sharename when splitting the route to allow
|
||||||
|
// shared subscription routes to correctly match the topic
|
||||||
|
func routeSplit(route string) []string {
|
||||||
|
var result []string
|
||||||
|
if strings.HasPrefix(route, "$share") {
|
||||||
|
result = strings.Split(route, "/")[2:]
|
||||||
|
} else {
|
||||||
|
result = strings.Split(route, "/")
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// match takes the topic string of the published message and does a basic compare to the
|
||||||
|
// string of the current Route, if they match it returns true
|
||||||
|
func (r *route) match(topic string) bool {
|
||||||
|
return r.topic == topic || routeIncludesTopic(r.topic, topic)
|
||||||
|
}
|
||||||
|
|
||||||
|
type router struct {
|
||||||
|
sync.RWMutex
|
||||||
|
routes *list.List
|
||||||
|
defaultHandler MessageHandler
|
||||||
|
messages chan *packets.PublishPacket
|
||||||
|
}
|
||||||
|
|
||||||
|
// newRouter returns a new instance of a Router and channel which can be used to tell the Router
|
||||||
|
// to stop
|
||||||
|
func newRouter() *router {
|
||||||
|
router := &router{routes: list.New(), messages: make(chan *packets.PublishPacket)}
|
||||||
|
return router
|
||||||
|
}
|
||||||
|
|
||||||
|
// addRoute takes a topic string and MessageHandler callback. It looks in the current list of
|
||||||
|
// routes to see if there is already a matching Route. If there is it replaces the current
|
||||||
|
// callback with the new one. If not it add a new entry to the list of Routes.
|
||||||
|
func (r *router) addRoute(topic string, callback MessageHandler) {
|
||||||
|
r.Lock()
|
||||||
|
defer r.Unlock()
|
||||||
|
for e := r.routes.Front(); e != nil; e = e.Next() {
|
||||||
|
if e.Value.(*route).topic == topic {
|
||||||
|
r := e.Value.(*route)
|
||||||
|
r.callback = callback
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.routes.PushBack(&route{topic: topic, callback: callback})
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteRoute takes a route string, looks for a matching Route in the list of Routes. If
|
||||||
|
// found it removes the Route from the list.
|
||||||
|
func (r *router) deleteRoute(topic string) {
|
||||||
|
r.Lock()
|
||||||
|
defer r.Unlock()
|
||||||
|
for e := r.routes.Front(); e != nil; e = e.Next() {
|
||||||
|
if e.Value.(*route).topic == topic {
|
||||||
|
r.routes.Remove(e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setDefaultHandler assigns a default callback that will be called if no matching Route
|
||||||
|
// is found for an incoming Publish.
|
||||||
|
func (r *router) setDefaultHandler(handler MessageHandler) {
|
||||||
|
r.Lock()
|
||||||
|
defer r.Unlock()
|
||||||
|
r.defaultHandler = handler
|
||||||
|
}
|
||||||
|
|
||||||
|
// matchAndDispatch takes a channel of Message pointers as input and starts a go routine that
|
||||||
|
// takes messages off the channel, matches them against the internal route list and calls the
|
||||||
|
// associated callback (or the defaultHandler, if one exists and no other route matched). If
|
||||||
|
// anything is sent down the stop channel the function will end.
|
||||||
|
func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order bool, client *client) <-chan *PacketAndToken {
|
||||||
|
ackChan := make(chan *PacketAndToken)
|
||||||
|
go func() {
|
||||||
|
for message := range messages {
|
||||||
|
// DEBUG.Println(ROU, "matchAndDispatch received message")
|
||||||
|
sent := false
|
||||||
|
r.RLock()
|
||||||
|
m := messageFromPublish(message, ackFunc(ackChan, client.persist, message))
|
||||||
|
var handlers []MessageHandler
|
||||||
|
for e := r.routes.Front(); e != nil; e = e.Next() {
|
||||||
|
if e.Value.(*route).match(message.TopicName) {
|
||||||
|
if order {
|
||||||
|
handlers = append(handlers, e.Value.(*route).callback)
|
||||||
|
} else {
|
||||||
|
hd := e.Value.(*route).callback
|
||||||
|
go func() {
|
||||||
|
hd(client, m)
|
||||||
|
m.Ack()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
sent = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !sent {
|
||||||
|
if r.defaultHandler != nil {
|
||||||
|
if order {
|
||||||
|
handlers = append(handlers, r.defaultHandler)
|
||||||
|
} else {
|
||||||
|
go func() {
|
||||||
|
r.defaultHandler(client, m)
|
||||||
|
m.Ack()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DEBUG.Println(ROU, "matchAndDispatch received message and no handler was available. Message will NOT be acknowledged.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.RUnlock()
|
||||||
|
for _, handler := range handlers {
|
||||||
|
handler(client, m)
|
||||||
|
m.Ack()
|
||||||
|
}
|
||||||
|
// DEBUG.Println(ROU, "matchAndDispatch handled message")
|
||||||
|
}
|
||||||
|
close(ackChan)
|
||||||
|
DEBUG.Println(ROU, "matchAndDispatch exiting")
|
||||||
|
}()
|
||||||
|
return ackChan
|
||||||
|
}
|
||||||
136
vendor/github.com/eclipse/paho.mqtt.golang/store.go
generated
vendored
Normal file
136
vendor/github.com/eclipse/paho.mqtt.golang/store.go
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013 IBM Corp.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Seth Hoenig
|
||||||
|
* Allan Stockdill-Mander
|
||||||
|
* Mike Robertson
|
||||||
|
*/
|
||||||
|
|
||||||
|
package mqtt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
inboundPrefix = "i."
|
||||||
|
outboundPrefix = "o."
|
||||||
|
)
|
||||||
|
|
||||||
|
// Store is an interface which can be used to provide implementations
|
||||||
|
// for message persistence.
|
||||||
|
// Because we may have to store distinct messages with the same
|
||||||
|
// message ID, we need a unique key for each message. This is
|
||||||
|
// possible by prepending "i." or "o." to each message id
|
||||||
|
type Store interface {
|
||||||
|
Open()
|
||||||
|
Put(key string, message packets.ControlPacket)
|
||||||
|
Get(key string) packets.ControlPacket
|
||||||
|
All() []string
|
||||||
|
Del(key string)
|
||||||
|
Close()
|
||||||
|
Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
// A key MUST have the form "X.[messageid]"
|
||||||
|
// where X is 'i' or 'o'
|
||||||
|
func mIDFromKey(key string) uint16 {
|
||||||
|
s := key[2:]
|
||||||
|
i, err := strconv.Atoi(s)
|
||||||
|
chkerr(err)
|
||||||
|
return uint16(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return true if key prefix is outbound
|
||||||
|
func isKeyOutbound(key string) bool {
|
||||||
|
return key[:2] == outboundPrefix
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return true if key prefix is inbound
|
||||||
|
func isKeyInbound(key string) bool {
|
||||||
|
return key[:2] == inboundPrefix
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a string of the form "i.[id]"
|
||||||
|
func inboundKeyFromMID(id uint16) string {
|
||||||
|
return fmt.Sprintf("%s%d", inboundPrefix, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a string of the form "o.[id]"
|
||||||
|
func outboundKeyFromMID(id uint16) string {
|
||||||
|
return fmt.Sprintf("%s%d", outboundPrefix, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// govern which outgoing messages are persisted
|
||||||
|
func persistOutbound(s Store, m packets.ControlPacket) {
|
||||||
|
switch m.Details().Qos {
|
||||||
|
case 0:
|
||||||
|
switch m.(type) {
|
||||||
|
case *packets.PubackPacket, *packets.PubcompPacket:
|
||||||
|
// Sending puback. delete matching publish
|
||||||
|
// from ibound
|
||||||
|
s.Del(inboundKeyFromMID(m.Details().MessageID))
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
switch m.(type) {
|
||||||
|
case *packets.PublishPacket, *packets.PubrelPacket, *packets.SubscribePacket, *packets.UnsubscribePacket:
|
||||||
|
// Sending publish. store in obound
|
||||||
|
// until puback received
|
||||||
|
s.Put(outboundKeyFromMID(m.Details().MessageID), m)
|
||||||
|
default:
|
||||||
|
ERROR.Println(STR, "Asked to persist an invalid message type")
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
switch m.(type) {
|
||||||
|
case *packets.PublishPacket:
|
||||||
|
// Sending publish. store in obound
|
||||||
|
// until pubrel received
|
||||||
|
s.Put(outboundKeyFromMID(m.Details().MessageID), m)
|
||||||
|
default:
|
||||||
|
ERROR.Println(STR, "Asked to persist an invalid message type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// govern which incoming messages are persisted
|
||||||
|
func persistInbound(s Store, m packets.ControlPacket) {
|
||||||
|
switch m.Details().Qos {
|
||||||
|
case 0:
|
||||||
|
switch m.(type) {
|
||||||
|
case *packets.PubackPacket, *packets.SubackPacket, *packets.UnsubackPacket, *packets.PubcompPacket:
|
||||||
|
// Received a puback. delete matching publish
|
||||||
|
// from obound
|
||||||
|
s.Del(outboundKeyFromMID(m.Details().MessageID))
|
||||||
|
case *packets.PublishPacket, *packets.PubrecPacket, *packets.PingrespPacket, *packets.ConnackPacket:
|
||||||
|
default:
|
||||||
|
ERROR.Println(STR, "Asked to persist an invalid messages type")
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
switch m.(type) {
|
||||||
|
case *packets.PublishPacket, *packets.PubrelPacket:
|
||||||
|
// Received a publish. store it in ibound
|
||||||
|
// until puback sent
|
||||||
|
s.Put(inboundKeyFromMID(m.Details().MessageID), m)
|
||||||
|
default:
|
||||||
|
ERROR.Println(STR, "Asked to persist an invalid messages type")
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
switch m.(type) {
|
||||||
|
case *packets.PublishPacket:
|
||||||
|
// Received a publish. store it in ibound
|
||||||
|
// until pubrel received
|
||||||
|
s.Put(inboundKeyFromMID(m.Details().MessageID), m)
|
||||||
|
default:
|
||||||
|
ERROR.Println(STR, "Asked to persist an invalid messages type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user