Compare commits
12 Commits
v0.4.0
...
feat/use_s
Author | SHA1 | Date | |
---|---|---|---|
34c4433836 | |||
d9b0dbb07a | |||
c724c1170a | |||
517e558081 | |||
d35b8db825 | |||
419a1ddd72 | |||
8312e7a3bd | |||
41f99b7f57 | |||
8740f5eaf9 | |||
72e93141d9 | |||
62d7397e05 | |||
53aab84534 |
@ -26,11 +26,12 @@ image_build(){
|
||||
|
||||
|
||||
printf "\n\nBuild go binary %s\n\n" "${BINARY}.${binary_suffix}"
|
||||
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -mod vendor -a ${GOTAGS} -o "${BINARY}.${binary_suffix}" ./cmd/${BINARY}/
|
||||
mkdir -p build
|
||||
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -mod vendor ${GOTAGS} -o "build/${BINARY}.${binary_suffix}" ./cmd/${BINARY}/
|
||||
|
||||
buildah --os "$GOOS" --arch "$GOARCH" $VARIANT --name "$containerName" from gcr.io/distroless/static
|
||||
buildah config --user 1234 "$containerName"
|
||||
buildah copy "$containerName" "${BINARY}.${binary_suffix}" /go/bin/$BINARY
|
||||
buildah copy "$containerName" "build/${BINARY}.${binary_suffix}" /go/bin/$BINARY
|
||||
buildah config --entrypoint '["/go/bin/'$BINARY'"]' "${containerName}"
|
||||
|
||||
buildah commit --rm --manifest $IMAGE_NAME "${containerName}" "${containerName}"
|
||||
|
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"github.com/cyrilix/robocar-base/cli"
|
||||
"github.com/cyrilix/robocar-throttle/pkg/part"
|
||||
"github.com/cyrilix/robocar-throttle/pkg/throttle"
|
||||
"go.uber.org/zap"
|
||||
"log"
|
||||
"os"
|
||||
@ -16,9 +16,9 @@ const (
|
||||
|
||||
func main() {
|
||||
var mqttBroker, username, password, clientId string
|
||||
var throttleTopic, driveModeTopic, rcThrottleTopic string
|
||||
var throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic string
|
||||
var minThrottle, maxThrottle float64
|
||||
var debug bool
|
||||
var publishPilotFrequency int
|
||||
|
||||
err := cli.SetFloat64DefaultValueFromEnv(&minThrottle, "THROTTLE_MIN", DefaultThrottleMin)
|
||||
if err != nil {
|
||||
@ -37,9 +37,13 @@ func main() {
|
||||
flag.StringVar(&throttleTopic, "mqtt-topic-throttle", os.Getenv("MQTT_TOPIC_THROTTLE"), "Mqtt topic to publish throttle result, use MQTT_TOPIC_THROTTLE if args not set")
|
||||
flag.StringVar(&driveModeTopic, "mqtt-topic-drive-mode", os.Getenv("MQTT_TOPIC_DRIVE_MODE"), "Mqtt topic that contains DriveMode value, use MQTT_TOPIC_DRIVE_MODE if args not set")
|
||||
flag.StringVar(&rcThrottleTopic, "mqtt-topic-rc-throttle", os.Getenv("MQTT_TOPIC_RC_THROTTLE"), "Mqtt topic that contains RC Throttle value, use MQTT_TOPIC_RC_THROTTLE if args not set")
|
||||
flag.StringVar(&steeringTopic, "mqtt-topic-steering", os.Getenv("MQTT_TOPIC_STEERING"), "Mqtt topic that contains steering value, use MQTT_TOPIC_STEERING if args not set")
|
||||
|
||||
flag.Float64Var(&minThrottle, "throttle-min", minThrottle, "Minimum throttle value, use THROTTLE_MIN if args not set")
|
||||
flag.Float64Var(&maxThrottle, "throttle-max", maxThrottle, "Minimum throttle value, use THROTTLE_MAX if args not set")
|
||||
flag.BoolVar(&debug, "debug", false, "Display raw value to debug")
|
||||
flag.IntVar(&publishPilotFrequency, "update-pwm-frequency", 2, "Number of throttle event to publish when pilot mode is enabled")
|
||||
|
||||
logLevel := zap.LevelFlag("log", zap.InfoLevel, "log level")
|
||||
|
||||
flag.Parse()
|
||||
if len(os.Args) <= 1 {
|
||||
@ -48,11 +52,7 @@ func main() {
|
||||
}
|
||||
|
||||
config := zap.NewDevelopmentConfig()
|
||||
if debug {
|
||||
config.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
} else {
|
||||
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
|
||||
}
|
||||
config.Level = zap.NewAtomicLevelAt(*logLevel)
|
||||
lgr, err := config.Build()
|
||||
if err != nil {
|
||||
log.Fatalf("unable to init logger: %v", err)
|
||||
@ -70,7 +70,7 @@ func main() {
|
||||
}
|
||||
defer client.Disconnect(50)
|
||||
|
||||
p := part.NewPart(client, throttleTopic, driveModeTopic, rcThrottleTopic, float32(minThrottle), float32(maxThrottle), 2)
|
||||
p := throttle.New(client, throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic, float32(minThrottle), float32(maxThrottle), 2)
|
||||
defer p.Stop()
|
||||
|
||||
cli.HandleExit(p)
|
||||
|
13
go.mod
13
go.mod
@ -1,13 +1,13 @@
|
||||
module github.com/cyrilix/robocar-throttle
|
||||
|
||||
go 1.17
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/cyrilix/robocar-base v0.1.6
|
||||
github.com/cyrilix/robocar-protobuf/go v1.0.4
|
||||
github.com/eclipse/paho.mqtt.golang v1.3.5
|
||||
go.uber.org/zap v1.19.1
|
||||
google.golang.org/protobuf v1.27.1
|
||||
github.com/cyrilix/robocar-base v0.1.7
|
||||
github.com/cyrilix/robocar-protobuf/go v1.1.0
|
||||
github.com/eclipse/paho.mqtt.golang v1.4.1
|
||||
go.uber.org/zap v1.23.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
||||
require (
|
||||
@ -16,4 +16,5 @@ require (
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
)
|
||||
|
141
go.sum
141
go.sum
@ -1,162 +1,51 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
||||
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
|
||||
github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/containerd/containerd v1.4.1/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
|
||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
||||
github.com/cyrilix/robocar-base v0.1.6 h1:VVcSZD8DPsha3XDLxRBMvtcd6uC8CcIjqbxG482dxvo=
|
||||
github.com/cyrilix/robocar-base v0.1.6/go.mod h1:m5ov/7hpRHi0yMp2prKafL6UEsM2O71Uea85WR0/jjI=
|
||||
github.com/cyrilix/robocar-protobuf/go v1.0.4 h1:XTolFYbiKw4gQ2l+z/LMZkLrmAUMzlHcQBzp/czlANo=
|
||||
github.com/cyrilix/robocar-protobuf/go v1.0.4/go.mod h1:1fyGMVm4ZodfYRrbWCEQgtvKyvrhyTBe5zA7/Qeh/H0=
|
||||
github.com/cyrilix/robocar-base v0.1.7 h1:EVzZ0KjigSFpke5f3A/PybEH3WFUEIrYSc3z/dhOZ48=
|
||||
github.com/cyrilix/robocar-base v0.1.7/go.mod h1:4E11HQSNy2NT8e7MW188y6ST9C0RzarKyn7sK/3V/Lk=
|
||||
github.com/cyrilix/robocar-protobuf/go v1.1.0 h1:txIjGnnCF3UzedpsWu+sL7nMA+pNjSnX6HZlAmuReH4=
|
||||
github.com/cyrilix/robocar-protobuf/go v1.1.0/go.mod h1:Y3AE28K5V7EZxMXp/6A8RhkRz15VOfFy4CjST35FbtQ=
|
||||
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/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||
github.com/docker/docker v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
|
||||
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/eclipse/paho.mqtt.golang v1.3.5 h1:sWtmgNxYM9P2sP+xEItMozsR3w0cqZFlqnNN1bdl41Y=
|
||||
github.com/eclipse/paho.mqtt.golang v1.3.5/go.mod h1:eTzb4gxwwyWpqBUHGQZ4ABAV7+Jgm1PklsYT/eo8Hcc=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
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.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/eclipse/paho.mqtt.golang v1.4.1 h1:tUSpviiL5G3P9SZZJPC4ZULZJsxQKXxfENpMvdbAXAI=
|
||||
github.com/eclipse/paho.mqtt.golang v1.4.1/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
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/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
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/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/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
||||
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
|
||||
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
|
||||
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 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
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.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/testcontainers/testcontainers-go v0.9.0/go.mod h1:b22BFXhRbg4PJmeMVWh6ftqjyZHgiIl3w274e9r3C2E=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
|
||||
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
|
||||
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
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-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-20190620200207-3b0461eec859/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-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
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-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-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
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/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180810170437-e96c4e24768d/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-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
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=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
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/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
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.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gotest.tools v0.0.0-20181223230014-1083505acf35/go.mod h1:R//lfYlUuTOTfblYI3lGoAAAebUdzjvbmQsuB7Ykd90=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
123
pkg/part/part.go
123
pkg/part/part.go
@ -1,123 +0,0 @@
|
||||
package part
|
||||
|
||||
import (
|
||||
"github.com/cyrilix/robocar-base/service"
|
||||
"github.com/cyrilix/robocar-protobuf/go/events"
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewPart(client mqtt.Client, throttleTopic, driveModeTopic, rcThrottleTopic string, minValue, maxValue float32, publishPilotFrequency int) *ThrottlePart {
|
||||
return &ThrottlePart{
|
||||
client: client,
|
||||
throttleTopic: throttleTopic,
|
||||
driveModeTopic: driveModeTopic,
|
||||
rcThrottleTopic: rcThrottleTopic,
|
||||
minThrottle: minValue,
|
||||
maxThrottle: maxValue,
|
||||
driveMode: events.DriveMode_USER,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type ThrottlePart struct {
|
||||
client mqtt.Client
|
||||
throttleTopic string
|
||||
minThrottle, maxThrottle float32
|
||||
|
||||
muDriveMode sync.RWMutex
|
||||
driveMode events.DriveMode
|
||||
|
||||
cancel chan interface{}
|
||||
publishPilotFrequency int
|
||||
driveModeTopic, rcThrottleTopic string
|
||||
}
|
||||
|
||||
func (p *ThrottlePart) Start() error {
|
||||
if err := registerCallbacks(p); err != nil {
|
||||
zap.S().Errorf("unable to register callbacks: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
p.cancel = make(chan interface{})
|
||||
ticker := time.NewTicker(1 * time.Second / time.Duration(p.publishPilotFrequency))
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
p.onPublishPilotValue()
|
||||
case <-p.cancel:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ThrottlePart) onPublishPilotValue() {
|
||||
p.muDriveMode.RLock()
|
||||
defer p.muDriveMode.RUnlock()
|
||||
|
||||
if p.driveMode != events.DriveMode_PILOT {
|
||||
return
|
||||
}
|
||||
|
||||
throttleMsg := events.ThrottleMessage{
|
||||
Throttle: p.minThrottle,
|
||||
Confidence: 1.0,
|
||||
}
|
||||
payload, err := proto.Marshal(&throttleMsg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to marshal %T protobuf content: %err", throttleMsg, err)
|
||||
return
|
||||
}
|
||||
|
||||
publish(p.client, p.throttleTopic, &payload)
|
||||
}
|
||||
|
||||
func (p *ThrottlePart) Stop() {
|
||||
close(p.cancel)
|
||||
service.StopService("throttle", p.client, p.driveModeTopic, p.rcThrottleTopic)
|
||||
}
|
||||
|
||||
func (p *ThrottlePart) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
||||
var msg events.DriveModeMessage
|
||||
err := proto.Unmarshal(message.Payload(), &msg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to unmarshal protobuf %T message: %v", msg, err)
|
||||
return
|
||||
}
|
||||
|
||||
p.muDriveMode.Lock()
|
||||
defer p.muDriveMode.Unlock()
|
||||
p.driveMode = msg.GetDriveMode()
|
||||
}
|
||||
|
||||
func (p *ThrottlePart) onRCThrottle(_ mqtt.Client, message mqtt.Message) {
|
||||
p.muDriveMode.RLock()
|
||||
defer p.muDriveMode.RUnlock()
|
||||
if p.driveMode == events.DriveMode_USER {
|
||||
zap.S().Debug("publish new throttle value from rc")
|
||||
// Republish same content
|
||||
payload := message.Payload()
|
||||
publish(p.client, p.throttleTopic, &payload)
|
||||
}
|
||||
}
|
||||
|
||||
var registerCallbacks = func(p *ThrottlePart) error {
|
||||
err := service.RegisterCallback(p.client, p.driveModeTopic, p.onDriveMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = service.RegisterCallback(p.client, p.rcThrottleTopic, p.onRCThrottle)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var publish = func(client mqtt.Client, topic string, payload *[]byte) {
|
||||
client.Publish(topic, 0, false, *payload)
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package part
|
||||
|
||||
import (
|
||||
"github.com/cyrilix/robocar-base/testtools"
|
||||
"github.com/cyrilix/robocar-protobuf/go/events"
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDefaultThrottle(t *testing.T) {
|
||||
oldRegister := registerCallbacks
|
||||
oldPublish := publish
|
||||
defer func() {
|
||||
registerCallbacks = oldRegister
|
||||
publish = oldPublish
|
||||
}()
|
||||
registerCallbacks = func(p *ThrottlePart) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var muEventsPublished sync.Mutex
|
||||
eventsPublished := make(map[string][]byte)
|
||||
publish = func(client mqtt.Client, topic string, payload *[]byte) {
|
||||
muEventsPublished.Lock()
|
||||
defer muEventsPublished.Unlock()
|
||||
eventsPublished[topic] = *payload
|
||||
}
|
||||
|
||||
throttleTopic := "topic/throttle"
|
||||
driveModeTopic := "topic/driveMode"
|
||||
rcThrottleTopic := "topic/rcThrottle"
|
||||
|
||||
minValue := float32(0.56)
|
||||
|
||||
p := NewPart(nil, throttleTopic, driveModeTopic, rcThrottleTopic, minValue, 1., 200)
|
||||
|
||||
cases := []struct {
|
||||
driveMode events.DriveModeMessage
|
||||
rcThrottle events.ThrottleMessage
|
||||
expectedThrottle events.ThrottleMessage
|
||||
}{
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: minValue, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: minValue, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}},
|
||||
}
|
||||
|
||||
go p.Start()
|
||||
defer func() { close(p.cancel) }()
|
||||
|
||||
for _, c := range cases {
|
||||
|
||||
p.onDriveMode(nil, testtools.NewFakeMessageFromProtobuf(driveModeTopic, &c.driveMode))
|
||||
p.onRCThrottle(nil, testtools.NewFakeMessageFromProtobuf(rcThrottleTopic, &c.rcThrottle))
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
for i := 3; i >= 0; i-- {
|
||||
|
||||
var msg events.ThrottleMessage
|
||||
muEventsPublished.Lock()
|
||||
err := proto.Unmarshal(eventsPublished[throttleTopic], &msg)
|
||||
if err != nil {
|
||||
t.Errorf("unable to unmarshall response: %v", err)
|
||||
t.Fail()
|
||||
}
|
||||
muEventsPublished.Unlock()
|
||||
|
||||
if msg.GetThrottle() != c.expectedThrottle.GetThrottle() {
|
||||
t.Errorf("bad msg value for mode %v: %v, wants %v", c.driveMode, msg.GetThrottle(), c.expectedThrottle.GetThrottle())
|
||||
}
|
||||
if msg.GetConfidence() != 1. {
|
||||
t.Errorf("bad throtlle confidence: %v, wants %v", msg.GetConfidence(), 1.)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
170
pkg/throttle/controller.go
Normal file
170
pkg/throttle/controller.go
Normal file
@ -0,0 +1,170 @@
|
||||
package throttle
|
||||
|
||||
import (
|
||||
"github.com/cyrilix/robocar-base/service"
|
||||
"github.com/cyrilix/robocar-protobuf/go/events"
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func New(client mqtt.Client, throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic string, minValue, maxValue float32, publishPilotFrequency int) *Controller {
|
||||
return &Controller{
|
||||
client: client,
|
||||
throttleTopic: throttleTopic,
|
||||
driveModeTopic: driveModeTopic,
|
||||
rcThrottleTopic: rcThrottleTopic,
|
||||
steeringTopic: steeringTopic,
|
||||
maxThrottle: maxValue,
|
||||
driveMode: events.DriveMode_USER,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
steeringProcessor: &SteeringProcessor{minThrottle: minValue, maxThrottle: maxValue},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
client mqtt.Client
|
||||
throttleTopic string
|
||||
maxThrottle float32
|
||||
steeringProcessor *SteeringProcessor
|
||||
|
||||
muDriveMode sync.RWMutex
|
||||
driveMode events.DriveMode
|
||||
|
||||
muSteering sync.RWMutex
|
||||
steering float32
|
||||
|
||||
cancel chan interface{}
|
||||
publishPilotFrequency int
|
||||
driveModeTopic, rcThrottleTopic, steeringTopic string
|
||||
}
|
||||
|
||||
func (c *Controller) Start() error {
|
||||
if err := registerCallbacks(c); err != nil {
|
||||
zap.S().Errorf("unable to register callbacks: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
c.cancel = make(chan interface{})
|
||||
ticker := time.NewTicker(1 * time.Second / time.Duration(c.publishPilotFrequency))
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
c.onPublishPilotValue()
|
||||
case <-c.cancel:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) onPublishPilotValue() {
|
||||
c.muDriveMode.RLock()
|
||||
defer c.muDriveMode.RUnlock()
|
||||
|
||||
if c.driveMode != events.DriveMode_PILOT {
|
||||
return
|
||||
}
|
||||
|
||||
throttleMsg := events.ThrottleMessage{
|
||||
Throttle: c.steeringProcessor.Process(c.readSteering()),
|
||||
Confidence: 1.0,
|
||||
}
|
||||
payload, err := proto.Marshal(&throttleMsg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to marshal %v protobuf content: %v", throttleMsg.String(), err)
|
||||
return
|
||||
}
|
||||
|
||||
publish(c.client, c.throttleTopic, payload)
|
||||
|
||||
}
|
||||
|
||||
func (c *Controller) readSteering() float32 {
|
||||
c.muSteering.RLock()
|
||||
defer c.muSteering.RUnlock()
|
||||
return c.steering
|
||||
}
|
||||
|
||||
func (c *Controller) Stop() {
|
||||
close(c.cancel)
|
||||
service.StopService("throttle", c.client, c.driveModeTopic, c.rcThrottleTopic, c.steeringTopic)
|
||||
}
|
||||
|
||||
func (c *Controller) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
||||
var msg events.DriveModeMessage
|
||||
err := proto.Unmarshal(message.Payload(), &msg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to unmarshal protobuf %T message: %v", msg, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.muDriveMode.Lock()
|
||||
defer c.muDriveMode.Unlock()
|
||||
c.driveMode = msg.GetDriveMode()
|
||||
}
|
||||
|
||||
func (c *Controller) onRCThrottle(_ mqtt.Client, message mqtt.Message) {
|
||||
c.muDriveMode.RLock()
|
||||
defer c.muDriveMode.RUnlock()
|
||||
if c.driveMode == events.DriveMode_USER {
|
||||
// Republish same content
|
||||
payload := message.Payload()
|
||||
var throttleMsg events.ThrottleMessage
|
||||
err := proto.Unmarshal(payload, &throttleMsg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to unmarshall throttle msg to check throttle value: %v", err)
|
||||
return
|
||||
}
|
||||
zap.S().Debugf("publish new throttle value from rc: %v", throttleMsg.GetThrottle())
|
||||
if throttleMsg.GetThrottle() > c.maxThrottle {
|
||||
zap.S().Debugf("throttle upper that max value allowed, patch value from %v to %v", throttleMsg.GetThrottle(), c.maxThrottle)
|
||||
throttleMsg.Throttle = c.maxThrottle
|
||||
payloadPatched, err := proto.Marshal(&throttleMsg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to marshall throttle msg: %v", err)
|
||||
return
|
||||
}
|
||||
publish(c.client, c.throttleTopic, payloadPatched)
|
||||
return
|
||||
}
|
||||
publish(c.client, c.throttleTopic, payload)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) onSteering(_ mqtt.Client, message mqtt.Message) {
|
||||
var steeringMsg events.SteeringMessage
|
||||
payload := message.Payload()
|
||||
err := proto.Unmarshal(payload, &steeringMsg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to unmarshal steering message, skip value: %v", err)
|
||||
return
|
||||
}
|
||||
c.muSteering.Lock()
|
||||
defer c.muSteering.Unlock()
|
||||
c.steering = steeringMsg.GetSteering()
|
||||
}
|
||||
|
||||
var registerCallbacks = func(p *Controller) error {
|
||||
err := service.RegisterCallback(p.client, p.driveModeTopic, p.onDriveMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = service.RegisterCallback(p.client, p.rcThrottleTopic, p.onRCThrottle)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = service.RegisterCallback(p.client, p.steeringTopic, p.onSteering)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var publish = func(client mqtt.Client, topic string, payload []byte) {
|
||||
client.Publish(topic, 0, false, payload)
|
||||
}
|
261
pkg/throttle/controller_test.go
Normal file
261
pkg/throttle/controller_test.go
Normal file
@ -0,0 +1,261 @@
|
||||
package throttle
|
||||
|
||||
import (
|
||||
"github.com/cyrilix/robocar-base/testtools"
|
||||
"github.com/cyrilix/robocar-protobuf/go/events"
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDefaultThrottle(t *testing.T) {
|
||||
oldRegister := registerCallbacks
|
||||
oldPublish := publish
|
||||
defer func() {
|
||||
registerCallbacks = oldRegister
|
||||
publish = oldPublish
|
||||
}()
|
||||
registerCallbacks = func(p *Controller) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var muEventsPublished sync.Mutex
|
||||
eventsPublished := make(map[string][]byte)
|
||||
publish = func(client mqtt.Client, topic string, payload []byte) {
|
||||
muEventsPublished.Lock()
|
||||
defer muEventsPublished.Unlock()
|
||||
eventsPublished[topic] = payload
|
||||
}
|
||||
|
||||
throttleTopic := "topic/throttle"
|
||||
driveModeTopic := "topic/driveMode"
|
||||
rcThrottleTopic := "topic/rcThrottle"
|
||||
steeringTopic := "topic/rcThrottle"
|
||||
|
||||
minValue := float32(0.56)
|
||||
|
||||
p := New(nil, throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic, minValue, 1., 200)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
maxThrottle float32
|
||||
driveMode events.DriveModeMessage
|
||||
rcThrottle events.ThrottleMessage
|
||||
expectedThrottle events.ThrottleMessage
|
||||
}{
|
||||
{"test1", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}},
|
||||
{"test2", 1., events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: 1.0, Confidence: 1.0}},
|
||||
{"test3", 1., events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: 1.0, Confidence: 1.0}},
|
||||
{"test4", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}},
|
||||
{"test5", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
||||
{"test6", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}},
|
||||
{"limit max throttle on user mode", 0.4, events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
||||
}
|
||||
|
||||
go p.Start()
|
||||
defer func() { close(p.cancel) }()
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
p.maxThrottle = c.maxThrottle
|
||||
p.onDriveMode(nil, testtools.NewFakeMessageFromProtobuf(driveModeTopic, &c.driveMode))
|
||||
p.onRCThrottle(nil, testtools.NewFakeMessageFromProtobuf(rcThrottleTopic, &c.rcThrottle))
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
for i := 3; i >= 0; i-- {
|
||||
|
||||
var msg events.ThrottleMessage
|
||||
muEventsPublished.Lock()
|
||||
err := proto.Unmarshal(eventsPublished[throttleTopic], &msg)
|
||||
if err != nil {
|
||||
t.Errorf("unable to unmarshall response: %v", err)
|
||||
t.Fail()
|
||||
}
|
||||
muEventsPublished.Unlock()
|
||||
|
||||
if msg.GetThrottle() != c.expectedThrottle.GetThrottle() {
|
||||
t.Errorf("bad msg value for mode %v: %v, wants %v", c.driveMode.String(), msg.GetThrottle(), c.expectedThrottle.GetThrottle())
|
||||
}
|
||||
if msg.GetConfidence() != 1. {
|
||||
t.Errorf("bad throtlle confidence: %v, wants %v", msg.GetConfidence(), 1.)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestController_Start(t *testing.T) {
|
||||
oldRegister := registerCallbacks
|
||||
oldPublish := publish
|
||||
defer func() {
|
||||
registerCallbacks = oldRegister
|
||||
publish = oldPublish
|
||||
}()
|
||||
registerCallbacks = func(p *Controller) error {
|
||||
return nil
|
||||
}
|
||||
publishPilotFrequency := 10
|
||||
waitPublish := sync.WaitGroup{}
|
||||
var muEventsPublished sync.Mutex
|
||||
eventsPublished := make(map[string][]byte)
|
||||
publish = func(client mqtt.Client, topic string, payload []byte) {
|
||||
muEventsPublished.Lock()
|
||||
defer muEventsPublished.Unlock()
|
||||
eventsPublished[topic] = payload
|
||||
waitPublish.Done()
|
||||
}
|
||||
|
||||
throttleTopic := "topic/throttle"
|
||||
steeringTopic := "topic/steering"
|
||||
driveModeTopic := "topic/driveMode"
|
||||
rcThrottleTopic := "topic/rcThrottle"
|
||||
|
||||
type fields struct {
|
||||
driveMode events.DriveMode
|
||||
min, max float32
|
||||
publishPilotFrequency int
|
||||
}
|
||||
type msgEvents struct {
|
||||
driveMode *events.DriveModeMessage
|
||||
steering *events.SteeringMessage
|
||||
rcThrottle *events.ThrottleMessage
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
msgEvents msgEvents
|
||||
want *events.ThrottleMessage
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "On user drive mode, throttle from rc",
|
||||
fields: fields{
|
||||
driveMode: events.DriveMode_USER,
|
||||
max: 0.8,
|
||||
min: 0.3,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
},
|
||||
msgEvents: msgEvents{
|
||||
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_USER},
|
||||
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
||||
rcThrottle: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
||||
},
|
||||
want: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
||||
},
|
||||
{
|
||||
name: "On user drive mode, limit throttle to max allowed value",
|
||||
fields: fields{
|
||||
driveMode: events.DriveMode_USER,
|
||||
max: 0.8,
|
||||
min: 0.3,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
},
|
||||
msgEvents: msgEvents{
|
||||
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_USER},
|
||||
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
||||
rcThrottle: &events.ThrottleMessage{Throttle: 0.9, Confidence: 1.0},
|
||||
},
|
||||
want: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
||||
},
|
||||
{
|
||||
name: "On user drive mode, throttle can be < to min allowed value",
|
||||
fields: fields{
|
||||
driveMode: events.DriveMode_USER,
|
||||
max: 0.8,
|
||||
min: 0.3,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
},
|
||||
msgEvents: msgEvents{
|
||||
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_USER},
|
||||
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
||||
rcThrottle: &events.ThrottleMessage{Throttle: 0.1, Confidence: 1.0},
|
||||
},
|
||||
want: &events.ThrottleMessage{Throttle: 0.1, Confidence: 1.0},
|
||||
},
|
||||
{
|
||||
name: "On pilot drive mode and straight steering, use max throttle allowed",
|
||||
fields: fields{
|
||||
driveMode: events.DriveMode_PILOT,
|
||||
max: 0.8,
|
||||
min: 0.3,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
},
|
||||
msgEvents: msgEvents{
|
||||
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_PILOT},
|
||||
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
||||
rcThrottle: &events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0},
|
||||
},
|
||||
want: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
||||
},
|
||||
{
|
||||
name: "On pilot drive mode and on left steering, use min throttle allowed",
|
||||
fields: fields{
|
||||
driveMode: events.DriveMode_PILOT,
|
||||
max: 0.8,
|
||||
min: 0.3,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
},
|
||||
msgEvents: msgEvents{
|
||||
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_PILOT},
|
||||
steering: &events.SteeringMessage{Steering: -1.0, Confidence: 1.0},
|
||||
rcThrottle: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
||||
},
|
||||
want: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
||||
},
|
||||
{
|
||||
name: "On pilot drive mode and on right steering, use min throttle allowed",
|
||||
fields: fields{
|
||||
driveMode: events.DriveMode_PILOT,
|
||||
max: 0.8,
|
||||
min: 0.3,
|
||||
publishPilotFrequency: publishPilotFrequency,
|
||||
},
|
||||
msgEvents: msgEvents{
|
||||
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_PILOT},
|
||||
steering: &events.SteeringMessage{Steering: 1.0, Confidence: 1.0},
|
||||
rcThrottle: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
||||
},
|
||||
want: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := New(nil,
|
||||
throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic,
|
||||
tt.fields.min, tt.fields.max,
|
||||
tt.fields.publishPilotFrequency,
|
||||
)
|
||||
|
||||
go c.Start()
|
||||
defer func() { close(c.cancel) }()
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
// Publish events and wait generation of new steering message
|
||||
waitPublish.Add(1)
|
||||
c.onDriveMode(nil, testtools.NewFakeMessageFromProtobuf(driveModeTopic, tt.msgEvents.driveMode))
|
||||
c.onRCThrottle(nil, testtools.NewFakeMessageFromProtobuf(rcThrottleTopic, tt.msgEvents.rcThrottle))
|
||||
c.onSteering(nil, testtools.NewFakeMessageFromProtobuf(steeringTopic, tt.msgEvents.steering))
|
||||
waitPublish.Wait()
|
||||
|
||||
var msg events.ThrottleMessage
|
||||
muEventsPublished.Lock()
|
||||
err := proto.Unmarshal(eventsPublished[throttleTopic], &msg)
|
||||
if err != nil {
|
||||
t.Errorf("unable to unmarshall response: %v", err)
|
||||
t.Fail()
|
||||
}
|
||||
muEventsPublished.Unlock()
|
||||
|
||||
if msg.GetThrottle() != tt.want.GetThrottle() {
|
||||
t.Errorf("bad msg value for mode %v: %v, wants %v", c.driveMode.String(), msg.GetThrottle(), tt.want.GetThrottle())
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
13
pkg/throttle/processor.go
Normal file
13
pkg/throttle/processor.go
Normal file
@ -0,0 +1,13 @@
|
||||
package throttle
|
||||
|
||||
import "math"
|
||||
|
||||
type SteeringProcessor struct {
|
||||
minThrottle, maxThrottle float32
|
||||
}
|
||||
|
||||
// Process compute throttle from steering value
|
||||
func (sp *SteeringProcessor) Process(steering float32) float32 {
|
||||
absSteering := math.Abs(float64(steering))
|
||||
return sp.minThrottle + float32(float64(sp.maxThrottle-sp.minThrottle)*(1-absSteering))
|
||||
}
|
86
pkg/throttle/processor_test.go
Normal file
86
pkg/throttle/processor_test.go
Normal file
@ -0,0 +1,86 @@
|
||||
package throttle
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSteeringProcessor_Process(t *testing.T) {
|
||||
type fields struct {
|
||||
minThrottle float32
|
||||
maxThrottle float32
|
||||
}
|
||||
type args struct {
|
||||
steering float32
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want float32
|
||||
}{
|
||||
{
|
||||
name: "steering straight",
|
||||
fields: fields{
|
||||
minThrottle: 0.2,
|
||||
maxThrottle: 0.5,
|
||||
},
|
||||
args: args{
|
||||
steering: 0.,
|
||||
},
|
||||
want: 0.5,
|
||||
},
|
||||
{
|
||||
name: "steering full left should return min throttle",
|
||||
fields: fields{
|
||||
minThrottle: 0.2,
|
||||
maxThrottle: 0.5,
|
||||
},
|
||||
args: args{
|
||||
steering: -1.,
|
||||
},
|
||||
want: 0.2,
|
||||
},
|
||||
{
|
||||
name: "steering full right should return min throttle",
|
||||
fields: fields{
|
||||
minThrottle: 0.2,
|
||||
maxThrottle: 0.5,
|
||||
},
|
||||
args: args{
|
||||
steering: 1.,
|
||||
},
|
||||
want: 0.2,
|
||||
},
|
||||
{
|
||||
name: "steering mid-left should return intermediate throttle",
|
||||
fields: fields{
|
||||
minThrottle: 0.3,
|
||||
maxThrottle: 0.5,
|
||||
},
|
||||
args: args{
|
||||
steering: -0.5,
|
||||
},
|
||||
want: 0.4,
|
||||
},
|
||||
{
|
||||
name: "steering mid-right should return intermediate throttle",
|
||||
fields: fields{
|
||||
minThrottle: 0.3,
|
||||
maxThrottle: 0.5,
|
||||
},
|
||||
args: args{
|
||||
steering: 0.5,
|
||||
},
|
||||
want: 0.4,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
sp := &SteeringProcessor{
|
||||
minThrottle: tt.fields.minThrottle,
|
||||
maxThrottle: tt.fields.maxThrottle,
|
||||
}
|
||||
if got := sp.Process(tt.args.steering); got != tt.want {
|
||||
t.Errorf("Process() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
30
vendor/github.com/cyrilix/robocar-protobuf/go/events/events.pb.go
generated
vendored
30
vendor/github.com/cyrilix/robocar-protobuf/go/events/events.pb.go
generated
vendored
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.12.4
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc v3.21.4
|
||||
// source: events/events.proto
|
||||
|
||||
package events
|
||||
@ -468,17 +468,17 @@ func (x *ObjectsMessage) GetFrameRef() *FrameRef {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BoundingBox that contains an object
|
||||
// BoundingBox that contains an object, coordinates as percent
|
||||
type Object struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Type TypeObject `protobuf:"varint,1,opt,name=type,proto3,enum=robocar.events.TypeObject" json:"type,omitempty"`
|
||||
Left int32 `protobuf:"varint,2,opt,name=left,proto3" json:"left,omitempty"`
|
||||
Top int32 `protobuf:"varint,3,opt,name=top,proto3" json:"top,omitempty"`
|
||||
Right int32 `protobuf:"varint,4,opt,name=right,proto3" json:"right,omitempty"`
|
||||
Bottom int32 `protobuf:"varint,5,opt,name=bottom,proto3" json:"bottom,omitempty"`
|
||||
Left float32 `protobuf:"fixed32,2,opt,name=left,proto3" json:"left,omitempty"`
|
||||
Top float32 `protobuf:"fixed32,3,opt,name=top,proto3" json:"top,omitempty"`
|
||||
Right float32 `protobuf:"fixed32,4,opt,name=right,proto3" json:"right,omitempty"`
|
||||
Bottom float32 `protobuf:"fixed32,5,opt,name=bottom,proto3" json:"bottom,omitempty"`
|
||||
Confidence float32 `protobuf:"fixed32,6,opt,name=confidence,proto3" json:"confidence,omitempty"`
|
||||
}
|
||||
|
||||
@ -521,28 +521,28 @@ func (x *Object) GetType() TypeObject {
|
||||
return TypeObject_ANY
|
||||
}
|
||||
|
||||
func (x *Object) GetLeft() int32 {
|
||||
func (x *Object) GetLeft() float32 {
|
||||
if x != nil {
|
||||
return x.Left
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Object) GetTop() int32 {
|
||||
func (x *Object) GetTop() float32 {
|
||||
if x != nil {
|
||||
return x.Top
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Object) GetRight() int32 {
|
||||
func (x *Object) GetRight() float32 {
|
||||
if x != nil {
|
||||
return x.Right
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Object) GetBottom() int32 {
|
||||
func (x *Object) GetBottom() float32 {
|
||||
if x != nil {
|
||||
return x.Bottom
|
||||
}
|
||||
@ -918,10 +918,10 @@ var file_events_events_proto_rawDesc = []byte{
|
||||
0x0e, 0x32, 0x1a, 0x2e, 0x72, 0x6f, 0x62, 0x6f, 0x63, 0x61, 0x72, 0x2e, 0x65, 0x76, 0x65, 0x6e,
|
||||
0x74, 0x73, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x04, 0x74,
|
||||
0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x05, 0x52, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6f, 0x70, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x74, 0x6f, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x69, 0x67,
|
||||
0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x69, 0x67, 0x68, 0x74, 0x12,
|
||||
0x16, 0x0a, 0x06, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||
0x02, 0x52, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6f, 0x70, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x02, 0x52, 0x03, 0x74, 0x6f, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x69, 0x67,
|
||||
0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x72, 0x69, 0x67, 0x68, 0x74, 0x12,
|
||||
0x16, 0x0a, 0x06, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x02, 0x52,
|
||||
0x06, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x69,
|
||||
0x64, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x63, 0x6f, 0x6e,
|
||||
0x66, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x2f, 0x0a, 0x13, 0x53, 0x77, 0x69, 0x74, 0x63,
|
||||
|
15
vendor/github.com/eclipse/paho.mqtt.golang/DISTRIBUTION
generated
vendored
15
vendor/github.com/eclipse/paho.mqtt.golang/DISTRIBUTION
generated
vendored
@ -1,15 +0,0 @@
|
||||
|
||||
|
||||
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.
|
296
vendor/github.com/eclipse/paho.mqtt.golang/LICENSE
generated
vendored
296
vendor/github.com/eclipse/paho.mqtt.golang/LICENSE
generated
vendored
@ -1,20 +1,294 @@
|
||||
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.
|
||||
Eclipse Public License - v 2.0 (EPL-2.0)
|
||||
|
||||
The EDL is copied below in order to pass the pkg.go.dev license check (https://pkg.go.dev/license-policy).
|
||||
This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
For an explanation of what dual-licensing means to you, see:
|
||||
https://www.eclipse.org/legal/eplfaq.php#DUALLIC
|
||||
|
||||
****
|
||||
Eclipse Distribution License - v 1.0
|
||||
The epl-2.0 is copied below in order to pass the pkg.go.dev license check (https://pkg.go.dev/license-policy).
|
||||
****
|
||||
Eclipse Public License - v 2.0
|
||||
|
||||
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
|
||||
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.
|
||||
|
||||
All rights reserved.
|
||||
1. DEFINITIONS
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
"Contribution" means:
|
||||
|
||||
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.
|
||||
a) in the case of the initial Contributor, the initial content
|
||||
Distributed under this Agreement, and
|
||||
|
||||
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.
|
||||
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 changes or additions to the Program that
|
||||
are not Modified Works.
|
||||
|
||||
"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
|
||||
or any Secondary License (as applicable), including Contributors.
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source Code or other
|
||||
form, that is based on (or derived from) the Program and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship.
|
||||
|
||||
"Modified Works" shall mean any work in Source Code or other form that
|
||||
results from an addition to, deletion from, or modification of the
|
||||
contents of the Program, including, for purposes of clarity any new file
|
||||
in Source Code form that contains any contents of the Program. Modified
|
||||
Works shall not include works that contain only declarations,
|
||||
interfaces, types, classes, structures, or files of the Program solely
|
||||
in each case in order to link to, bind by name, or subclass the Program
|
||||
or Modified Works thereof.
|
||||
|
||||
"Distribute" means the acts of a) distributing or b) making available
|
||||
in any manner that enables the transfer of a copy.
|
||||
|
||||
"Source Code" means the form of a Program preferred for making
|
||||
modifications, including but not limited to software source code,
|
||||
documentation source, and configuration files.
|
||||
|
||||
"Secondary License" means either the GNU General Public License,
|
||||
Version 2.0, or any later versions of that license, including any
|
||||
exceptions or additional permissions as identified by the initial
|
||||
Contributor.
|
||||
|
||||
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.
|
||||
|
||||
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 or other 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.
|
||||
|
||||
e) Notwithstanding the terms of any Secondary License, no
|
||||
Contributor makes additional grants to any Recipient (other than
|
||||
those set forth in this Agreement) as a result of such Recipient's
|
||||
receipt of the Program under the terms of a Secondary License
|
||||
(if permitted under the terms of Section 3).
|
||||
|
||||
3. REQUIREMENTS
|
||||
|
||||
3.1 If a Contributor Distributes the Program in any form, then:
|
||||
|
||||
a) the Program must also be made available as Source Code, in
|
||||
accordance with section 3.2, and the Contributor must accompany
|
||||
the Program with a statement that the Source Code for the Program
|
||||
is available under this Agreement, and informs Recipients how to
|
||||
obtain it in a reasonable manner on or through a medium customarily
|
||||
used for software exchange; and
|
||||
|
||||
b) the Contributor may Distribute the Program under a license
|
||||
different than this Agreement, provided that such license:
|
||||
i) effectively disclaims on behalf of all other 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 other Contributors all
|
||||
liability for damages, including direct, indirect, special,
|
||||
incidental and consequential damages, such as lost profits;
|
||||
|
||||
iii) does not attempt to limit or alter the recipients' rights
|
||||
in the Source Code under section 3.2; and
|
||||
|
||||
iv) requires any subsequent distribution of the Program by any
|
||||
party to be under a license that satisfies the requirements
|
||||
of this section 3.
|
||||
|
||||
3.2 When the Program is Distributed as Source Code:
|
||||
|
||||
a) it must be made available under this Agreement, or if the
|
||||
Program (i) is combined with other material in a separate file or
|
||||
files made available under a Secondary License, and (ii) the initial
|
||||
Contributor attached to the Source Code the notice described in
|
||||
Exhibit A of this Agreement, then the Program may be made available
|
||||
under the terms of such Secondary Licenses, and
|
||||
|
||||
b) a copy of this Agreement must be included with each copy of
|
||||
the Program.
|
||||
|
||||
3.3 Contributors may not remove or alter any copyright, patent,
|
||||
trademark, attribution notices, disclaimers of warranty, or limitations
|
||||
of liability ("notices") contained within the Program from any copy of
|
||||
the Program which they Distribute, provided that Contributors may add
|
||||
their own appropriate notices.
|
||||
|
||||
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, AND TO THE EXTENT
|
||||
PERMITTED BY APPLICABLE LAW, 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, AND TO THE EXTENT
|
||||
PERMITTED BY APPLICABLE LAW, 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. Nothing in this Agreement is intended
|
||||
to be enforceable by any entity that is not a Contributor or Recipient.
|
||||
No third-party beneficiary rights are created under this Agreement.
|
||||
|
||||
Exhibit A - Form of Secondary Licenses Notice
|
||||
|
||||
"This Source Code may also be made available under the following
|
||||
Secondary Licenses when the conditions for such availability set forth
|
||||
in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
|
||||
version(s), and exceptions or additional permissions here}."
|
||||
|
||||
Simply including a copy of this Agreement, including this Exhibit A
|
||||
is not sufficient to license the Source Code under Secondary Licenses.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to
|
||||
look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
77
vendor/github.com/eclipse/paho.mqtt.golang/NOTICE.md
generated
vendored
Normal file
77
vendor/github.com/eclipse/paho.mqtt.golang/NOTICE.md
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
# Notices for paho.mqtt.golang
|
||||
|
||||
This content is produced and maintained by the Eclipse Paho project.
|
||||
|
||||
* Project home: https://www.eclipse.org/paho/
|
||||
|
||||
Note that a [separate mqtt v5 client](https://github.com/eclipse/paho.golang) also exists (this is a full rewrite
|
||||
and deliberately incompatible with this library).
|
||||
|
||||
## Trademarks
|
||||
|
||||
Eclipse Mosquitto trademarks of the Eclipse Foundation. Eclipse, and the
|
||||
Eclipse Logo are registered trademarks of the Eclipse Foundation.
|
||||
|
||||
Paho is a trademark of the Eclipse Foundation. Eclipse, and the Eclipse Logo are
|
||||
registered trademarks of the Eclipse Foundation.
|
||||
|
||||
## Copyright
|
||||
|
||||
All content is the property of the respective authors or their employers.
|
||||
For more information regarding authorship of content, please consult the
|
||||
listed source code repository logs.
|
||||
|
||||
## Declared Project Licenses
|
||||
|
||||
This program and the accompanying materials are made available under the terms of the
|
||||
Eclipse Public License v2.0 and Eclipse Distribution License v1.0 which accompany this
|
||||
distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
For an explanation of what dual-licensing means to you, see:
|
||||
https://www.eclipse.org/legal/eplfaq.php#DUALLIC
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 or BSD-3-Clause
|
||||
|
||||
## Source Code
|
||||
|
||||
The project maintains the following source code repositories:
|
||||
|
||||
* https://github.com/eclipse/paho.mqtt.golang
|
||||
|
||||
## Third-party Content
|
||||
|
||||
This project makes use of the follow third party projects.
|
||||
|
||||
Go Programming Language and Standard Library
|
||||
|
||||
* License: BSD-style license (https://golang.org/LICENSE)
|
||||
* Project: https://golang.org/
|
||||
|
||||
Go Networking
|
||||
|
||||
* License: BSD 3-Clause style license and patent grant.
|
||||
* Project: https://cs.opensource.google/go/x/net
|
||||
|
||||
Go Sync
|
||||
|
||||
* License: BSD 3-Clause style license and patent grant.
|
||||
* Project: https://cs.opensource.google/go/x/sync/
|
||||
|
||||
Gorilla Websockets v1.4.2
|
||||
|
||||
* License: BSD 2-Clause "Simplified" License
|
||||
* Project: https://github.com/gorilla/websocket
|
||||
|
||||
## Cryptography
|
||||
|
||||
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.
|
63
vendor/github.com/eclipse/paho.mqtt.golang/README.md
generated
vendored
63
vendor/github.com/eclipse/paho.mqtt.golang/README.md
generated
vendored
@ -111,36 +111,54 @@ identifier; this is as per the [spec](https://docs.oasis-open.org/mqtt/mqtt/v3.1
|
||||
`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`.
|
||||
* 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).
|
||||
`ClientOptions.KeepAlive` (sends regular messages to check the link is active).
|
||||
* Reusing a `Client` is not completely safe. After calling `Disconnect` please create a new Client (`NewClient()`) rather
|
||||
than attempting to reuse the existing one (note that features such as `SetAutoReconnect` mean this is rarely necessary).
|
||||
* Brokers offer many configuration options; some settings may lead to unexpected results.
|
||||
* Publish tokens will complete if the connection is lost and re-established using the default
|
||||
options.SetAutoReconnect(true) functionality (token.Error() will return nil). Attempts will be made to re-deliver the
|
||||
message but there is currently no easy way know when such messages are delivered.
|
||||
|
||||
If using Mosquitto then there are a range of fairly common issues:
|
||||
* `listener` - By default [Mosquitto v2+](https://mosquitto.org/documentation/migrating-to-2-0/) listens on loopback
|
||||
interfaces only (meaning it will only accept connections made from the computer its running on).
|
||||
* `max_inflight_messages` - Unless this is set to 1 mosquitto does not guarantee ordered delivery of messages.
|
||||
* `max_queued_messages` / `max_queued_bytes` - These impose limits on the number/size of queued messages. The defaults
|
||||
may lead to messages being silently dropped.
|
||||
* `persistence` - Defaults to false (messages will not survive a broker restart)
|
||||
* `max_keepalive` - defaults to 65535 and, from version 2.0.12, `SetKeepAlive(0)` will result in a rejected connection
|
||||
by default.
|
||||
|
||||
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).*
|
||||
A limited number of contributors monitor the issues section so if you have a general question please see the
|
||||
resources in the [more information](#more-information) section for help.
|
||||
|
||||
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:
|
||||
The information required will vary from issue to issue but almost all bug reports would be expected to include:
|
||||
|
||||
* 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.
|
||||
* Which version of the package you are using (tag or commit - this should be in your `go.mod` file)
|
||||
* A full, clear, description of the problem (detail what you are expecting vs what actually happens).
|
||||
* Configuration information (code showing how you connect, please include all references to `ClientOption`)
|
||||
* Broker details (name and version).
|
||||
|
||||
If at all possible please also include:
|
||||
* 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.
|
||||
* 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.
|
||||
* Broker logs covering the period the issue occurred.
|
||||
* [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).
|
||||
|
||||
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:
|
||||
@ -158,7 +176,7 @@ 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.
|
||||
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
|
||||
@ -167,11 +185,12 @@ note of the requirement that the commit record contain a "Signed-off-by" entry.
|
||||
More information
|
||||
----------------
|
||||
|
||||
[Stack Overflow](https://stackoverflow.com/questions/tagged/mqtt+go) has a range questions/answers covering a range of
|
||||
common issues (both relating to use of this library and MQTT in general). This is the best place to ask general questions
|
||||
(including those relating to the use of this library).
|
||||
|
||||
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).
|
||||
There is much more information available via the [MQTT community site](http://mqtt.org).
|
41
vendor/github.com/eclipse/paho.mqtt.golang/about.html
generated
vendored
41
vendor/github.com/eclipse/paho.mqtt.golang/about.html
generated
vendored
@ -1,41 +0,0 @@
|
||||
<!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>
|
129
vendor/github.com/eclipse/paho.mqtt.golang/client.go
generated
vendored
129
vendor/github.com/eclipse/paho.mqtt.golang/client.go
generated
vendored
@ -1,15 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
* Allan Stockdill-Mander
|
||||
* Mike Robertson
|
||||
* Matt Brittan
|
||||
*/
|
||||
|
||||
// Portions copyright © 2018 TIBCO Software Inc.
|
||||
@ -19,6 +24,7 @@ package mqtt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
@ -27,6 +33,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sync/semaphore"
|
||||
|
||||
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||
)
|
||||
|
||||
@ -274,7 +282,7 @@ func (c *client) Connect() Token {
|
||||
conn, rc, t.sessionPresent, err = c.attemptConnection()
|
||||
if err != nil {
|
||||
if c.options.ConnectRetry {
|
||||
DEBUG.Println(CLI, "Connect failed, sleeping for", int(c.options.ConnectRetryInterval.Seconds()), "seconds and will then retry")
|
||||
DEBUG.Println(CLI, "Connect failed, sleeping for", int(c.options.ConnectRetryInterval.Seconds()), "seconds and will then retry, error:", err.Error())
|
||||
time.Sleep(c.options.ConnectRetryInterval)
|
||||
|
||||
if atomic.LoadUint32(&c.status) == connecting {
|
||||
@ -384,8 +392,17 @@ func (c *client) attemptConnection() (net.Conn, byte, bool, error) {
|
||||
DEBUG.Println(CLI, "using custom onConnectAttempt handler...")
|
||||
tlsCfg = c.options.OnConnectAttempt(broker, c.options.TLSConfig)
|
||||
}
|
||||
dialer := c.options.Dialer
|
||||
if dialer == nil { //
|
||||
WARN.Println(CLI, "dialer was nil, using default")
|
||||
dialer = &net.Dialer{Timeout: 30 * time.Second}
|
||||
}
|
||||
// Start by opening the network connection (tcp, tls, ws) etc
|
||||
conn, err = openConnection(broker, tlsCfg, c.options.ConnectTimeout, c.options.HTTPHeaders, c.options.WebsocketOptions)
|
||||
if c.options.CustomOpenConnectionFn != nil {
|
||||
conn, err = c.options.CustomOpenConnectionFn(broker, c.options)
|
||||
} else {
|
||||
conn, err = openConnection(broker, tlsCfg, c.options.ConnectTimeout, c.options.HTTPHeaders, c.options.WebsocketOptions, dialer)
|
||||
}
|
||||
if err != nil {
|
||||
ERROR.Println(CLI, err.Error())
|
||||
WARN.Println(CLI, "failed to connect to broker, trying next")
|
||||
@ -431,36 +448,36 @@ func (c *client) attemptConnection() (net.Conn, byte, bool, error) {
|
||||
// Disconnect will end the connection with the server, but not before waiting
|
||||
// the specified number of milliseconds to wait for existing work to be
|
||||
// completed.
|
||||
// WARNING: `Disconnect` may return before all activities (goroutines) have completed. This means that
|
||||
// reusing the `client` may lead to panics. If you want to reconnect when the connection drops then use
|
||||
// `SetAutoReconnect` and/or `SetConnectRetry`options instead of implementing this yourself.
|
||||
func (c *client) Disconnect(quiesce uint) {
|
||||
defer c.disconnect()
|
||||
|
||||
status := atomic.LoadUint32(&c.status)
|
||||
if status == connected {
|
||||
DEBUG.Println(CLI, "disconnecting")
|
||||
c.setConnected(disconnected)
|
||||
c.setConnected(disconnected)
|
||||
|
||||
dm := packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
|
||||
dt := newToken(packets.Disconnect)
|
||||
disconnectSent := false
|
||||
select {
|
||||
case c.oboundP <- &PacketAndToken{p: dm, t: dt}:
|
||||
disconnectSent = true
|
||||
case <-c.commsStopped:
|
||||
WARN.Println("Disconnect packet could not be sent because comms stopped")
|
||||
case <-time.After(time.Duration(quiesce) * time.Millisecond):
|
||||
WARN.Println("Disconnect packet not sent due to timeout")
|
||||
}
|
||||
|
||||
// wait for work to finish, or quiesce time consumed
|
||||
if disconnectSent {
|
||||
DEBUG.Println(CLI, "calling WaitTimeout")
|
||||
dt.WaitTimeout(time.Duration(quiesce) * time.Millisecond)
|
||||
DEBUG.Println(CLI, "WaitTimeout done")
|
||||
}
|
||||
} else {
|
||||
if status != connected {
|
||||
WARN.Println(CLI, "Disconnect() called but not connected (disconnected/reconnecting)")
|
||||
c.setConnected(disconnected)
|
||||
return
|
||||
}
|
||||
|
||||
c.disconnect()
|
||||
DEBUG.Println(CLI, "disconnecting")
|
||||
dm := packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
|
||||
dt := newToken(packets.Disconnect)
|
||||
select {
|
||||
case c.oboundP <- &PacketAndToken{p: dm, t: dt}:
|
||||
// wait for work to finish, or quiesce time consumed
|
||||
DEBUG.Println(CLI, "calling WaitTimeout")
|
||||
dt.WaitTimeout(time.Duration(quiesce) * time.Millisecond)
|
||||
DEBUG.Println(CLI, "WaitTimeout done")
|
||||
// Let's comment this chunk of code until we are able to safely read this variable
|
||||
// without data races.
|
||||
// case <-c.commsStopped:
|
||||
// WARN.Println("Disconnect packet could not be sent because comms stopped")
|
||||
case <-time.After(time.Duration(quiesce) * time.Millisecond):
|
||||
WARN.Println("Disconnect packet not sent due to timeout")
|
||||
}
|
||||
}
|
||||
|
||||
// forceDisconnect will end the connection with the mqtt broker immediately (used for tests only)
|
||||
@ -503,7 +520,9 @@ func (c *client) internalConnLost(err error) {
|
||||
reconnect := c.options.AutoReconnect && c.connectionStatus() > connecting
|
||||
|
||||
if c.options.CleanSession && !reconnect {
|
||||
c.messageIds.cleanUp()
|
||||
c.messageIds.cleanUp() // completes PUB/SUB/UNSUB tokens
|
||||
} else if !c.options.ResumeSubs {
|
||||
c.messageIds.cleanUpSubscribe() // completes SUB/UNSUB tokens
|
||||
}
|
||||
if reconnect {
|
||||
c.setConnected(reconnecting)
|
||||
@ -800,7 +819,9 @@ func (c *client) Subscribe(topic string, qos byte, callback MessageHandler) Toke
|
||||
}
|
||||
DEBUG.Println(CLI, sub.String())
|
||||
|
||||
persistOutbound(c.persist, sub)
|
||||
if c.options.ResumeSubs { // Only persist if we need this to resume subs after a disconnection
|
||||
persistOutbound(c.persist, sub)
|
||||
}
|
||||
switch c.connectionStatus() {
|
||||
case connecting:
|
||||
DEBUG.Println(CLI, "storing subscribe message (connecting), topic:", topic)
|
||||
@ -872,7 +893,9 @@ func (c *client) SubscribeMultiple(filters map[string]byte, callback MessageHand
|
||||
sub.MessageID = mID
|
||||
token.messageID = mID
|
||||
}
|
||||
persistOutbound(c.persist, sub)
|
||||
if c.options.ResumeSubs { // Only persist if we need this to resume subs after a disconnection
|
||||
persistOutbound(c.persist, sub)
|
||||
}
|
||||
switch c.connectionStatus() {
|
||||
case connecting:
|
||||
DEBUG.Println(CLI, "storing subscribe message (connecting), topics:", sub.Topics)
|
||||
@ -919,10 +942,42 @@ func (c *client) reserveStoredPublishIDs() {
|
||||
// Load all stored messages and resend them
|
||||
// Call this to ensure QOS > 1,2 even after an application crash
|
||||
// Note: This function will exit if c.stop is closed (this allows the shutdown to proceed avoiding a potential deadlock)
|
||||
//
|
||||
// other than that it does not return until all messages in the store have been sent (connect() does not complete its
|
||||
// token before this completes)
|
||||
func (c *client) resume(subscription bool, ibound chan packets.ControlPacket) {
|
||||
DEBUG.Println(STR, "enter Resume")
|
||||
|
||||
// Prior to sending a message getSemaphore will be called and once sent releaseSemaphore will be called
|
||||
// with the token (so semaphore can be released when ACK received if applicable).
|
||||
// Using a weighted semaphore rather than channels because this retains ordering
|
||||
getSemaphore := func() {} // Default = do nothing
|
||||
releaseSemaphore := func(_ *PublishToken) {} // Default = do nothing
|
||||
var sem *semaphore.Weighted
|
||||
if c.options.MaxResumePubInFlight > 0 {
|
||||
sem = semaphore.NewWeighted(int64(c.options.MaxResumePubInFlight))
|
||||
ctx, cancel := context.WithCancel(context.Background()) // Context needed for semaphore
|
||||
defer cancel() // ensure context gets cancelled
|
||||
|
||||
go func() {
|
||||
select {
|
||||
case <-c.stop: // Request to stop (due to comm error etc)
|
||||
cancel()
|
||||
case <-ctx.Done(): // resume completed normally
|
||||
}
|
||||
}()
|
||||
|
||||
getSemaphore = func() { sem.Acquire(ctx, 1) }
|
||||
releaseSemaphore = func(token *PublishToken) { // Note: If token never completes then resume() may stall (will still exit on ctx.Done())
|
||||
go func() {
|
||||
select {
|
||||
case <-token.Done():
|
||||
case <-ctx.Done():
|
||||
}
|
||||
sem.Release(1)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
storedKeys := c.persist.All()
|
||||
for _, key := range storedKeys {
|
||||
packet := c.persist.Get(key)
|
||||
@ -986,12 +1041,14 @@ func (c *client) resume(subscription bool, ibound chan packets.ControlPacket) {
|
||||
c.claimID(token, details.MessageID)
|
||||
DEBUG.Println(STR, fmt.Sprintf("loaded pending publish (%d)", details.MessageID))
|
||||
DEBUG.Println(STR, details)
|
||||
getSemaphore()
|
||||
select {
|
||||
case c.obound <- &PacketAndToken{p: p, t: token}:
|
||||
case <-c.stop:
|
||||
DEBUG.Println(STR, "resume exiting due to stop")
|
||||
return
|
||||
}
|
||||
releaseSemaphore(token) // If limiting simultaneous messages then we need to know when message is acknowledged
|
||||
default:
|
||||
ERROR.Println(STR, "invalid message type in store (discarded)")
|
||||
c.persist.Del(key)
|
||||
@ -1051,7 +1108,9 @@ func (c *client) Unsubscribe(topics ...string) Token {
|
||||
token.messageID = mID
|
||||
}
|
||||
|
||||
persistOutbound(c.persist, unsub)
|
||||
if c.options.ResumeSubs { // Only persist if we need this to resume subs after a disconnection
|
||||
persistOutbound(c.persist, unsub)
|
||||
}
|
||||
|
||||
switch c.connectionStatus() {
|
||||
case connecting:
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/components.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/components.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
70
vendor/github.com/eclipse/paho.mqtt.golang/epl-v10
generated
vendored
70
vendor/github.com/eclipse/paho.mqtt.golang/epl-v10
generated
vendored
@ -1,70 +0,0 @@
|
||||
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.
|
277
vendor/github.com/eclipse/paho.mqtt.golang/epl-v20
generated
vendored
Normal file
277
vendor/github.com/eclipse/paho.mqtt.golang/epl-v20
generated
vendored
Normal file
@ -0,0 +1,277 @@
|
||||
Eclipse Public License - v 2.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 content
|
||||
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 changes or additions to the Program that
|
||||
are not Modified Works.
|
||||
|
||||
"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
|
||||
or any Secondary License (as applicable), including Contributors.
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source Code or other
|
||||
form, that is based on (or derived from) the Program and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship.
|
||||
|
||||
"Modified Works" shall mean any work in Source Code or other form that
|
||||
results from an addition to, deletion from, or modification of the
|
||||
contents of the Program, including, for purposes of clarity any new file
|
||||
in Source Code form that contains any contents of the Program. Modified
|
||||
Works shall not include works that contain only declarations,
|
||||
interfaces, types, classes, structures, or files of the Program solely
|
||||
in each case in order to link to, bind by name, or subclass the Program
|
||||
or Modified Works thereof.
|
||||
|
||||
"Distribute" means the acts of a) distributing or b) making available
|
||||
in any manner that enables the transfer of a copy.
|
||||
|
||||
"Source Code" means the form of a Program preferred for making
|
||||
modifications, including but not limited to software source code,
|
||||
documentation source, and configuration files.
|
||||
|
||||
"Secondary License" means either the GNU General Public License,
|
||||
Version 2.0, or any later versions of that license, including any
|
||||
exceptions or additional permissions as identified by the initial
|
||||
Contributor.
|
||||
|
||||
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.
|
||||
|
||||
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 or other 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.
|
||||
|
||||
e) Notwithstanding the terms of any Secondary License, no
|
||||
Contributor makes additional grants to any Recipient (other than
|
||||
those set forth in this Agreement) as a result of such Recipient's
|
||||
receipt of the Program under the terms of a Secondary License
|
||||
(if permitted under the terms of Section 3).
|
||||
|
||||
3. REQUIREMENTS
|
||||
|
||||
3.1 If a Contributor Distributes the Program in any form, then:
|
||||
|
||||
a) the Program must also be made available as Source Code, in
|
||||
accordance with section 3.2, and the Contributor must accompany
|
||||
the Program with a statement that the Source Code for the Program
|
||||
is available under this Agreement, and informs Recipients how to
|
||||
obtain it in a reasonable manner on or through a medium customarily
|
||||
used for software exchange; and
|
||||
|
||||
b) the Contributor may Distribute the Program under a license
|
||||
different than this Agreement, provided that such license:
|
||||
i) effectively disclaims on behalf of all other 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 other Contributors all
|
||||
liability for damages, including direct, indirect, special,
|
||||
incidental and consequential damages, such as lost profits;
|
||||
|
||||
iii) does not attempt to limit or alter the recipients' rights
|
||||
in the Source Code under section 3.2; and
|
||||
|
||||
iv) requires any subsequent distribution of the Program by any
|
||||
party to be under a license that satisfies the requirements
|
||||
of this section 3.
|
||||
|
||||
3.2 When the Program is Distributed as Source Code:
|
||||
|
||||
a) it must be made available under this Agreement, or if the
|
||||
Program (i) is combined with other material in a separate file or
|
||||
files made available under a Secondary License, and (ii) the initial
|
||||
Contributor attached to the Source Code the notice described in
|
||||
Exhibit A of this Agreement, then the Program may be made available
|
||||
under the terms of such Secondary Licenses, and
|
||||
|
||||
b) a copy of this Agreement must be included with each copy of
|
||||
the Program.
|
||||
|
||||
3.3 Contributors may not remove or alter any copyright, patent,
|
||||
trademark, attribution notices, disclaimers of warranty, or limitations
|
||||
of liability ("notices") contained within the Program from any copy of
|
||||
the Program which they Distribute, provided that Contributors may add
|
||||
their own appropriate notices.
|
||||
|
||||
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, AND TO THE EXTENT
|
||||
PERMITTED BY APPLICABLE LAW, 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, AND TO THE EXTENT
|
||||
PERMITTED BY APPLICABLE LAW, 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. Nothing in this Agreement is intended
|
||||
to be enforceable by any entity that is not a Contributor or Recipient.
|
||||
No third-party beneficiary rights are created under this Agreement.
|
||||
|
||||
Exhibit A - Form of Secondary Licenses Notice
|
||||
|
||||
"This Source Code may also be made available under the following
|
||||
Secondary Licenses when the conditions for such availability set forth
|
||||
in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
|
||||
version(s), and exceptions or additional permissions here}."
|
||||
|
||||
Simply including a copy of this Agreement, including this Exhibit A
|
||||
is not sufficient to license the Source Code under Secondary Licenses.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to
|
||||
look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
14
vendor/github.com/eclipse/paho.mqtt.golang/filestore.go
generated
vendored
14
vendor/github.com/eclipse/paho.mqtt.golang/filestore.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
@ -168,7 +172,7 @@ func (store *FileStore) all() []string {
|
||||
for _, f := range files {
|
||||
DEBUG.Println(STR, "file in All():", f.Name())
|
||||
name := f.Name()
|
||||
if name[len(name)-4:] != msgExt {
|
||||
if len(name) < len(msgExt) || name[len(name)-len(msgExt):] != msgExt {
|
||||
DEBUG.Println(STR, "skipping file, doesn't have right extension: ", name)
|
||||
continue
|
||||
}
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/memstore.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/memstore.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
166
vendor/github.com/eclipse/paho.mqtt.golang/memstore_ordered.go
generated
vendored
Normal file
166
vendor/github.com/eclipse/paho.mqtt.golang/memstore_ordered.go
generated
vendored
Normal file
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
* Allan Stockdill-Mander
|
||||
* Mike Robertson
|
||||
* Matt Brittan
|
||||
*/
|
||||
|
||||
package mqtt
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||
)
|
||||
|
||||
// OrderedMemoryStore uses a map internally so the order in which All() returns packets is
|
||||
// undefined. OrderedMemoryStore resolves this by storing the time the message is added
|
||||
// and sorting based upon this.
|
||||
|
||||
// storedMessage encapsulates a message and the time it was initially stored
|
||||
type storedMessage struct {
|
||||
ts time.Time
|
||||
msg packets.ControlPacket
|
||||
}
|
||||
|
||||
// OrderedMemoryStore 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 OrderedMemoryStore struct {
|
||||
sync.RWMutex
|
||||
messages map[string]storedMessage
|
||||
opened bool
|
||||
}
|
||||
|
||||
// NewOrderedMemoryStore returns a pointer to a new instance of
|
||||
// OrderedMemoryStore, the instance is not initialized and ready to
|
||||
// use until Open() has been called on it.
|
||||
func NewOrderedMemoryStore() *OrderedMemoryStore {
|
||||
store := &OrderedMemoryStore{
|
||||
messages: make(map[string]storedMessage),
|
||||
opened: false,
|
||||
}
|
||||
return store
|
||||
}
|
||||
|
||||
// Open initializes a OrderedMemoryStore instance.
|
||||
func (store *OrderedMemoryStore) Open() {
|
||||
store.Lock()
|
||||
defer store.Unlock()
|
||||
store.opened = true
|
||||
DEBUG.Println(STR, "OrderedMemoryStore initialized")
|
||||
}
|
||||
|
||||
// Put takes a key and a pointer to a Message and stores the
|
||||
// message.
|
||||
func (store *OrderedMemoryStore) 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] = storedMessage{ts: time.Now(), msg: message}
|
||||
}
|
||||
|
||||
// Get takes a key and looks in the store for a matching Message
|
||||
// returning either the Message pointer or nil.
|
||||
func (store *OrderedMemoryStore) 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, ok := store.messages[key]
|
||||
if !ok || m.msg == nil {
|
||||
CRITICAL.Println(STR, "OrderedMemoryStore get: message", mid, "not found")
|
||||
} else {
|
||||
DEBUG.Println(STR, "OrderedMemoryStore get: message", mid, "found")
|
||||
}
|
||||
return m.msg
|
||||
}
|
||||
|
||||
// All returns a slice of strings containing all the keys currently
|
||||
// in the OrderedMemoryStore.
|
||||
func (store *OrderedMemoryStore) All() []string {
|
||||
store.RLock()
|
||||
defer store.RUnlock()
|
||||
if !store.opened {
|
||||
ERROR.Println(STR, "Trying to use memory store, but not open")
|
||||
return nil
|
||||
}
|
||||
type tsAndKey struct {
|
||||
ts time.Time
|
||||
key string
|
||||
}
|
||||
|
||||
tsKeys := make([]tsAndKey, 0, len(store.messages))
|
||||
for k, v := range store.messages {
|
||||
tsKeys = append(tsKeys, tsAndKey{ts: v.ts, key: k})
|
||||
}
|
||||
sort.Slice(tsKeys, func(a int, b int) bool { return tsKeys[a].ts.Before(tsKeys[b].ts) })
|
||||
|
||||
keys := make([]string, len(tsKeys))
|
||||
for i := range tsKeys {
|
||||
keys[i] = tsKeys[i].key
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
// Del takes a key, searches the OrderedMemoryStore and if the key is found
|
||||
// deletes the Message pointer associated with it.
|
||||
func (store *OrderedMemoryStore) 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)
|
||||
_, ok := store.messages[key]
|
||||
if !ok {
|
||||
WARN.Println(STR, "OrderedMemoryStore del: message", mid, "not found")
|
||||
} else {
|
||||
delete(store.messages, key)
|
||||
DEBUG.Println(STR, "OrderedMemoryStore del: message", mid, "was deleted")
|
||||
}
|
||||
}
|
||||
|
||||
// Close will disallow modifications to the state of the store.
|
||||
func (store *OrderedMemoryStore) 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, "OrderedMemoryStore closed")
|
||||
}
|
||||
|
||||
// Reset eliminates all persisted message data in the store.
|
||||
func (store *OrderedMemoryStore) 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]storedMessage)
|
||||
WARN.Println(STR, "OrderedMemoryStore wiped")
|
||||
}
|
12
vendor/github.com/eclipse/paho.mqtt.golang/message.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/message.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
34
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
34
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
@ -1,15 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2013 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
* Allan Stockdill-Mander
|
||||
* Mike Robertson
|
||||
* Matt Brittan
|
||||
*/
|
||||
|
||||
package mqtt
|
||||
@ -37,6 +42,7 @@ const (
|
||||
midMax uint16 = 65535
|
||||
)
|
||||
|
||||
// cleanup clears the message ID map; completes all token types and sets error on PUB, SUB and UNSUB tokens.
|
||||
func (mids *messageIds) cleanUp() {
|
||||
mids.Lock()
|
||||
for _, token := range mids.index {
|
||||
@ -47,7 +53,7 @@ func (mids *messageIds) cleanUp() {
|
||||
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
|
||||
case *UnsubscribeToken:
|
||||
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
|
||||
case nil:
|
||||
case nil: // should not be any nil entries
|
||||
continue
|
||||
}
|
||||
token.flowComplete()
|
||||
@ -57,6 +63,24 @@ func (mids *messageIds) cleanUp() {
|
||||
DEBUG.Println(MID, "cleaned up")
|
||||
}
|
||||
|
||||
// cleanUpSubscribe removes all SUBSCRIBE and UNSUBSCRIBE tokens (setting error)
|
||||
// This may be called when the connection is lost, and we will not be resending SUB/UNSUB packets
|
||||
func (mids *messageIds) cleanUpSubscribe() {
|
||||
mids.Lock()
|
||||
for mid, token := range mids.index {
|
||||
switch token.(type) {
|
||||
case *SubscribeToken:
|
||||
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
|
||||
delete(mids.index, mid)
|
||||
case *UnsubscribeToken:
|
||||
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
|
||||
delete(mids.index, mid)
|
||||
}
|
||||
}
|
||||
mids.Unlock()
|
||||
DEBUG.Println(MID, "cleaned up subs")
|
||||
}
|
||||
|
||||
func (mids *messageIds) freeID(id uint16) {
|
||||
mids.Lock()
|
||||
delete(mids.index, id)
|
||||
|
13
vendor/github.com/eclipse/paho.mqtt.golang/net.go
generated
vendored
13
vendor/github.com/eclipse/paho.mqtt.golang/net.go
generated
vendored
@ -1,15 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
* Allan Stockdill-Mander
|
||||
* Mike Robertson
|
||||
* Matt Brittan
|
||||
*/
|
||||
|
||||
package mqtt
|
||||
|
32
vendor/github.com/eclipse/paho.mqtt.golang/netconn.go
generated
vendored
32
vendor/github.com/eclipse/paho.mqtt.golang/netconn.go
generated
vendored
@ -1,15 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
* Allan Stockdill-Mander
|
||||
* Mike Robertson
|
||||
* MAtt Brittan
|
||||
*/
|
||||
|
||||
package mqtt
|
||||
@ -32,7 +37,7 @@ import (
|
||||
|
||||
// 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) {
|
||||
func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, headers http.Header, websocketOptions *WebsocketOptions, dialer *net.Dialer) (net.Conn, error) {
|
||||
switch uri.Scheme {
|
||||
case "ws":
|
||||
conn, err := NewWebsocket(uri.String(), nil, timeout, headers, websocketOptions)
|
||||
@ -43,7 +48,7 @@ func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, heade
|
||||
case "mqtt", "tcp":
|
||||
allProxy := os.Getenv("all_proxy")
|
||||
if len(allProxy) == 0 {
|
||||
conn, err := net.DialTimeout("tcp", uri.Host, timeout)
|
||||
conn, err := dialer.Dial("tcp", uri.Host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -57,7 +62,17 @@ func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, heade
|
||||
}
|
||||
return conn, nil
|
||||
case "unix":
|
||||
conn, err := net.DialTimeout("unix", uri.Host, timeout)
|
||||
var conn net.Conn
|
||||
var err error
|
||||
|
||||
// this check is preserved for compatibility with older versions
|
||||
// which used uri.Host only (it works for local paths, e.g. unix://socket.sock in current dir)
|
||||
if len(uri.Host) > 0 {
|
||||
conn, err = dialer.Dial("unix", uri.Host)
|
||||
} else {
|
||||
conn, err = dialer.Dial("unix", uri.Path)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -65,14 +80,13 @@ func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, heade
|
||||
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)
|
||||
conn, err := tls.DialWithDialer(dialer, "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
|
||||
|
108
vendor/github.com/eclipse/paho.mqtt.golang/notice.html
generated
vendored
108
vendor/github.com/eclipse/paho.mqtt.golang/notice.html
generated
vendored
@ -1,108 +0,0 @@
|
||||
<?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>
|
12
vendor/github.com/eclipse/paho.mqtt.golang/oops.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/oops.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
55
vendor/github.com/eclipse/paho.mqtt.golang/options.go
generated
vendored
55
vendor/github.com/eclipse/paho.mqtt.golang/options.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
@ -19,6 +23,7 @@ package mqtt
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@ -52,8 +57,16 @@ type ReconnectHandler func(Client, *ClientOptions)
|
||||
// ConnectionAttemptHandler is invoked prior to making the initial connection.
|
||||
type ConnectionAttemptHandler func(broker *url.URL, tlsCfg *tls.Config) *tls.Config
|
||||
|
||||
// OpenConnectionFunc is invoked to establish the underlying network connection
|
||||
// Its purpose if for custom network transports.
|
||||
// Does not carry out any MQTT specific handshakes.
|
||||
type OpenConnectionFunc func(uri *url.URL, options ClientOptions) (net.Conn, error)
|
||||
|
||||
// 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.
|
||||
// WARNING: Create the below using NewClientOptions unless you have a compelling reason not to. It is easy
|
||||
// to create a configuration with difficult to trace issues (e.g. Mosquitto 2.0.12+ will reject connections
|
||||
// with KeepAlive=0 by default).
|
||||
type ClientOptions struct {
|
||||
Servers []*url.URL
|
||||
ClientID string
|
||||
@ -70,7 +83,7 @@ type ClientOptions struct {
|
||||
ProtocolVersion uint
|
||||
protocolVersionExplicit bool
|
||||
TLSConfig *tls.Config
|
||||
KeepAlive int64
|
||||
KeepAlive int64 // Warning: Some brokers may reject connections with Keepalive = 0.
|
||||
PingTimeout time.Duration
|
||||
ConnectTimeout time.Duration
|
||||
MaxReconnectInterval time.Duration
|
||||
@ -88,6 +101,9 @@ type ClientOptions struct {
|
||||
ResumeSubs bool
|
||||
HTTPHeaders http.Header
|
||||
WebsocketOptions *WebsocketOptions
|
||||
MaxResumePubInFlight int // // 0 = no limit; otherwise this is the maximum simultaneous messages sent while resuming
|
||||
Dialer *net.Dialer
|
||||
CustomOpenConnectionFn OpenConnectionFunc
|
||||
}
|
||||
|
||||
// NewClientOptions will create a new ClientClientOptions type with some
|
||||
@ -129,6 +145,8 @@ func NewClientOptions() *ClientOptions {
|
||||
ResumeSubs: false,
|
||||
HTTPHeaders: make(map[string][]string),
|
||||
WebsocketOptions: &WebsocketOptions{},
|
||||
Dialer: &net.Dialer{Timeout: 30 * time.Second},
|
||||
CustomOpenConnectionFn: nil,
|
||||
}
|
||||
return o
|
||||
}
|
||||
@ -347,6 +365,7 @@ func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions {
|
||||
// Default 30 seconds. Currently only operational on TCP/TLS connections.
|
||||
func (o *ClientOptions) SetConnectTimeout(t time.Duration) *ClientOptions {
|
||||
o.ConnectTimeout = t
|
||||
o.Dialer.Timeout = t
|
||||
return o
|
||||
}
|
||||
|
||||
@ -401,3 +420,29 @@ func (o *ClientOptions) SetWebsocketOptions(w *WebsocketOptions) *ClientOptions
|
||||
o.WebsocketOptions = w
|
||||
return o
|
||||
}
|
||||
|
||||
// SetMaxResumePubInFlight sets the maximum simultaneous publish messages that will be sent while resuming. Note that
|
||||
// this only applies to messages coming from the store (so additional sends may push us over the limit)
|
||||
// Note that the connect token will not be flagged as complete until all messages have been sent from the
|
||||
// store. If broker does not respond to messages then resume may not complete.
|
||||
// This option was put in place because resuming after downtime can saturate low capacity links.
|
||||
func (o *ClientOptions) SetMaxResumePubInFlight(MaxResumePubInFlight int) *ClientOptions {
|
||||
o.MaxResumePubInFlight = MaxResumePubInFlight
|
||||
return o
|
||||
}
|
||||
|
||||
// SetDialer sets the tcp dialer options used in a tcp connection
|
||||
func (o *ClientOptions) SetDialer(dialer *net.Dialer) *ClientOptions {
|
||||
o.Dialer = dialer
|
||||
return o
|
||||
}
|
||||
|
||||
// SetCustomOpenConnectionFn replaces the inbuilt function that establishes a network connection with a custom function.
|
||||
// The passed in function should return an open `net.Conn` or an error (see the existing openConnection function for an example)
|
||||
// It enables custom networking types in addition to the defaults (tcp, tls, websockets...)
|
||||
func (o *ClientOptions) SetCustomOpenConnectionFn(customOpenConnectionFn OpenConnectionFunc) *ClientOptions {
|
||||
if customOpenConnectionFn != nil {
|
||||
o.CustomOpenConnectionFn = customOpenConnectionFn
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/options_reader.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/options_reader.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/connack.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/connack.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/connect.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/connect.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/disconnect.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/disconnect.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingreq.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingreq.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingresp.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pingresp.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/puback.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/puback.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubcomp.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubcomp.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/publish.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/publish.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrec.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrec.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrel.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/pubrel.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/suback.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/suback.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/subscribe.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/subscribe.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsuback.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsuback.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsubscribe.go
generated
vendored
16
vendor/github.com/eclipse/paho.mqtt.golang/packets/unsubscribe.go
generated
vendored
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
*/
|
||||
|
||||
package packets
|
||||
|
||||
import (
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/ping.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/ping.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/router.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/router.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
14
vendor/github.com/eclipse/paho.mqtt.golang/store.go
generated
vendored
14
vendor/github.com/eclipse/paho.mqtt.golang/store.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
@ -45,7 +49,7 @@ type Store interface {
|
||||
// where X is 'i' or 'o'
|
||||
func mIDFromKey(key string) uint16 {
|
||||
s := key[2:]
|
||||
i, err := strconv.Atoi(s)
|
||||
i, err := strconv.ParseUint(s, 10, 16)
|
||||
chkerr(err)
|
||||
return uint16(i)
|
||||
}
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/token.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/token.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2014 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Allan Stockdill-Mander
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/topic.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/topic.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2014 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
12
vendor/github.com/eclipse/paho.mqtt.golang/trace.go
generated
vendored
12
vendor/github.com/eclipse/paho.mqtt.golang/trace.go
generated
vendored
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2013 IBM Corp.
|
||||
* Copyright (c) 2021 IBM Corp and others.
|
||||
*
|
||||
* 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
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Seth Hoenig
|
||||
|
13
vendor/github.com/eclipse/paho.mqtt.golang/websocket.go
generated
vendored
13
vendor/github.com/eclipse/paho.mqtt.golang/websocket.go
generated
vendored
@ -1,3 +1,16 @@
|
||||
/*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v2.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* https://www.eclipse.org/legal/epl-2.0/
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
*/
|
||||
|
||||
package mqtt
|
||||
|
||||
import (
|
||||
|
12
vendor/go.uber.org/zap/.readme.tmpl
generated
vendored
12
vendor/go.uber.org/zap/.readme.tmpl
generated
vendored
@ -96,14 +96,14 @@ Released under the [MIT License](LICENSE.txt).
|
||||
|
||||
<sup id="footnote-versions">1</sup> In particular, keep in mind that we may be
|
||||
benchmarking against slightly older versions of other packages. Versions are
|
||||
pinned in zap's [glide.lock][] file. [↩](#anchor-versions)
|
||||
pinned in the [benchmarks/go.mod][] file. [↩](#anchor-versions)
|
||||
|
||||
[doc-img]: https://godoc.org/go.uber.org/zap?status.svg
|
||||
[doc]: https://godoc.org/go.uber.org/zap
|
||||
[ci-img]: https://travis-ci.com/uber-go/zap.svg?branch=master
|
||||
[ci]: https://travis-ci.com/uber-go/zap
|
||||
[doc-img]: https://pkg.go.dev/badge/go.uber.org/zap
|
||||
[doc]: https://pkg.go.dev/go.uber.org/zap
|
||||
[ci-img]: https://github.com/uber-go/zap/actions/workflows/go.yml/badge.svg
|
||||
[ci]: https://github.com/uber-go/zap/actions/workflows/go.yml
|
||||
[cov-img]: https://codecov.io/gh/uber-go/zap/branch/master/graph/badge.svg
|
||||
[cov]: https://codecov.io/gh/uber-go/zap
|
||||
[benchmarking suite]: https://github.com/uber-go/zap/tree/master/benchmarks
|
||||
[glide.lock]: https://github.com/uber-go/zap/blob/master/glide.lock
|
||||
[benchmarks/go.mod]: https://github.com/uber-go/zap/blob/master/benchmarks/go.mod
|
||||
|
||||
|
90
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
90
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
@ -3,9 +3,97 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 1.23.0 (24 Aug 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#1147][]: Add a `zapcore.LevelOf` function to determine the level of a
|
||||
`LevelEnabler` or `Core`.
|
||||
* [#1155][]: Add `zap.Stringers` field constructor to log arrays of objects
|
||||
that implement `String() string`.
|
||||
|
||||
[#1147]: https://github.com/uber-go/zap/pull/1147
|
||||
[#1155]: https://github.com/uber-go/zap/pull/1155
|
||||
|
||||
|
||||
## 1.22.0 (8 Aug 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#1071][]: Add `zap.Objects` and `zap.ObjectValues` field constructors to log
|
||||
arrays of objects. With these two constructors, you don't need to implement
|
||||
`zapcore.ArrayMarshaler` for use with `zap.Array` if those objects implement
|
||||
`zapcore.ObjectMarshaler`.
|
||||
* [#1079][]: Add `SugaredLogger.WithOptions` to build a copy of an existing
|
||||
`SugaredLogger` with the provided options applied.
|
||||
* [#1080][]: Add `*ln` variants to `SugaredLogger` for each log level.
|
||||
These functions provide a string joining behavior similar to `fmt.Println`.
|
||||
* [#1088][]: Add `zap.WithFatalHook` option to control the behavior of the
|
||||
logger for `Fatal`-level log entries. This defaults to exiting the program.
|
||||
* [#1108][]: Add a `zap.Must` function that you can use with `NewProduction` or
|
||||
`NewDevelopment` to panic if the system was unable to build the logger.
|
||||
* [#1118][]: Add a `Logger.Log` method that allows specifying the log level for
|
||||
a statement dynamically.
|
||||
|
||||
Thanks to @cardil, @craigpastro, @sashamelentyev, @shota3506, and @zhupeijun
|
||||
for their contributions to this release.
|
||||
|
||||
[#1071]: https://github.com/uber-go/zap/pull/1071
|
||||
[#1079]: https://github.com/uber-go/zap/pull/1079
|
||||
[#1080]: https://github.com/uber-go/zap/pull/1080
|
||||
[#1088]: https://github.com/uber-go/zap/pull/1088
|
||||
[#1108]: https://github.com/uber-go/zap/pull/1108
|
||||
[#1118]: https://github.com/uber-go/zap/pull/1118
|
||||
|
||||
## 1.21.0 (7 Feb 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#1047][]: Add `zapcore.ParseLevel` to parse a `Level` from a string.
|
||||
* [#1048][]: Add `zap.ParseAtomicLevel` to parse an `AtomicLevel` from a
|
||||
string.
|
||||
|
||||
Bugfixes:
|
||||
* [#1058][]: Fix panic in JSON encoder when `EncodeLevel` is unset.
|
||||
|
||||
Other changes:
|
||||
* [#1052][]: Improve encoding performance when the `AddCaller` and
|
||||
`AddStacktrace` options are used together.
|
||||
|
||||
[#1047]: https://github.com/uber-go/zap/pull/1047
|
||||
[#1048]: https://github.com/uber-go/zap/pull/1048
|
||||
[#1052]: https://github.com/uber-go/zap/pull/1052
|
||||
[#1058]: https://github.com/uber-go/zap/pull/1058
|
||||
|
||||
Thanks to @aerosol and @Techassi for their contributions to this release.
|
||||
|
||||
## 1.20.0 (4 Jan 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#989][]: Add `EncoderConfig.SkipLineEnding` flag to disable adding newline
|
||||
characters between log statements.
|
||||
* [#1039][]: Add `EncoderConfig.NewReflectedEncoder` field to customize JSON
|
||||
encoding of reflected log fields.
|
||||
|
||||
Bugfixes:
|
||||
* [#1011][]: Fix inaccurate precision when encoding complex64 as JSON.
|
||||
* [#554][], [#1017][]: Close JSON namespaces opened in `MarshalLogObject`
|
||||
methods when the methods return.
|
||||
* [#1033][]: Avoid panicking in Sampler core if `thereafter` is zero.
|
||||
|
||||
Other changes:
|
||||
* [#1028][]: Drop support for Go < 1.15.
|
||||
|
||||
[#554]: https://github.com/uber-go/zap/pull/554
|
||||
[#989]: https://github.com/uber-go/zap/pull/989
|
||||
[#1011]: https://github.com/uber-go/zap/pull/1011
|
||||
[#1017]: https://github.com/uber-go/zap/pull/1017
|
||||
[#1028]: https://github.com/uber-go/zap/pull/1028
|
||||
[#1033]: https://github.com/uber-go/zap/pull/1033
|
||||
[#1039]: https://github.com/uber-go/zap/pull/1039
|
||||
|
||||
Thanks to @psrajat, @lruggieri, @sammyrnycreal for their contributions to this release.
|
||||
|
||||
## 1.19.1 (8 Sep 2021)
|
||||
|
||||
### Fixed
|
||||
Bugfixes:
|
||||
* [#1001][]: JSON: Fix complex number encoding with negative imaginary part. Thanks to @hemantjadon.
|
||||
* [#1003][]: JSON: Fix inaccurate precision when encoding float32.
|
||||
|
||||
|
21
vendor/go.uber.org/zap/CONTRIBUTING.md
generated
vendored
21
vendor/go.uber.org/zap/CONTRIBUTING.md
generated
vendored
@ -16,7 +16,7 @@ you to accept the CLA when you open your pull request.
|
||||
|
||||
[Fork][fork], then clone the repository:
|
||||
|
||||
```
|
||||
```bash
|
||||
mkdir -p $GOPATH/src/go.uber.org
|
||||
cd $GOPATH/src/go.uber.org
|
||||
git clone git@github.com:your_github_username/zap.git
|
||||
@ -27,21 +27,16 @@ git fetch upstream
|
||||
|
||||
Make sure that the tests and the linters pass:
|
||||
|
||||
```
|
||||
```bash
|
||||
make test
|
||||
make lint
|
||||
```
|
||||
|
||||
If you're not using the minor version of Go specified in the Makefile's
|
||||
`LINTABLE_MINOR_VERSIONS` variable, `make lint` doesn't do anything. This is
|
||||
fine, but it means that you'll only discover lint failures after you open your
|
||||
pull request.
|
||||
|
||||
## Making Changes
|
||||
|
||||
Start by creating a new branch for your changes:
|
||||
|
||||
```
|
||||
```bash
|
||||
cd $GOPATH/src/go.uber.org/zap
|
||||
git checkout master
|
||||
git fetch upstream
|
||||
@ -52,22 +47,22 @@ git checkout -b cool_new_feature
|
||||
Make your changes, then ensure that `make lint` and `make test` still pass. If
|
||||
you're satisfied with your changes, push them to your fork.
|
||||
|
||||
```
|
||||
```bash
|
||||
git push origin cool_new_feature
|
||||
```
|
||||
|
||||
Then use the GitHub UI to open a pull request.
|
||||
|
||||
At this point, you're waiting on us to review your changes. We *try* to respond
|
||||
At this point, you're waiting on us to review your changes. We _try_ to respond
|
||||
to issues and pull requests within a few business days, and we may suggest some
|
||||
improvements or alternatives. Once your changes are approved, one of the
|
||||
project maintainers will merge them.
|
||||
|
||||
We're much more likely to approve your changes if you:
|
||||
|
||||
* Add tests for new functionality.
|
||||
* Write a [good commit message][commit-message].
|
||||
* Maintain backward compatibility.
|
||||
- Add tests for new functionality.
|
||||
- Write a [good commit message][commit-message].
|
||||
- Maintain backward compatibility.
|
||||
|
||||
[fork]: https://github.com/uber-go/zap/fork
|
||||
[open-issue]: https://github.com/uber-go/zap/issues/new
|
||||
|
59
vendor/go.uber.org/zap/README.md
generated
vendored
59
vendor/go.uber.org/zap/README.md
generated
vendored
@ -54,7 +54,7 @@ and make many small allocations. Put differently, using `encoding/json` and
|
||||
Zap takes a different approach. It includes a reflection-free, zero-allocation
|
||||
JSON encoder, and the base `Logger` strives to avoid serialization overhead
|
||||
and allocations wherever possible. By building the high-level `SugaredLogger`
|
||||
on that foundation, zap lets users *choose* when they need to count every
|
||||
on that foundation, zap lets users _choose_ when they need to count every
|
||||
allocation and when they'd prefer a more familiar, loosely typed API.
|
||||
|
||||
As measured by its own [benchmarking suite][], not only is zap more performant
|
||||
@ -64,40 +64,40 @@ id="anchor-versions">[1](#footnote-versions)</sup>
|
||||
|
||||
Log a message and 10 fields:
|
||||
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------ | :--: | :-----------: | :---------------: |
|
||||
| :zap: zap | 862 ns/op | +0% | 5 allocs/op
|
||||
| :zap: zap (sugared) | 1250 ns/op | +45% | 11 allocs/op
|
||||
| zerolog | 4021 ns/op | +366% | 76 allocs/op
|
||||
| go-kit | 4542 ns/op | +427% | 105 allocs/op
|
||||
| apex/log | 26785 ns/op | +3007% | 115 allocs/op
|
||||
| logrus | 29501 ns/op | +3322% | 125 allocs/op
|
||||
| log15 | 29906 ns/op | +3369% | 122 allocs/op
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------------------ | :---------: | :-----------: | :---------------: |
|
||||
| :zap: zap | 2900 ns/op | +0% | 5 allocs/op |
|
||||
| :zap: zap (sugared) | 3475 ns/op | +20% | 10 allocs/op |
|
||||
| zerolog | 10639 ns/op | +267% | 32 allocs/op |
|
||||
| go-kit | 14434 ns/op | +398% | 59 allocs/op |
|
||||
| logrus | 17104 ns/op | +490% | 81 allocs/op |
|
||||
| apex/log | 32424 ns/op | +1018% | 66 allocs/op |
|
||||
| log15 | 33579 ns/op | +1058% | 76 allocs/op |
|
||||
|
||||
Log a message with a logger that already has 10 fields of context:
|
||||
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------ | :--: | :-----------: | :---------------: |
|
||||
| :zap: zap | 126 ns/op | +0% | 0 allocs/op
|
||||
| :zap: zap (sugared) | 187 ns/op | +48% | 2 allocs/op
|
||||
| zerolog | 88 ns/op | -30% | 0 allocs/op
|
||||
| go-kit | 5087 ns/op | +3937% | 103 allocs/op
|
||||
| log15 | 18548 ns/op | +14621% | 73 allocs/op
|
||||
| apex/log | 26012 ns/op | +20544% | 104 allocs/op
|
||||
| logrus | 27236 ns/op | +21516% | 113 allocs/op
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------------------ | :---------: | :-----------: | :---------------: |
|
||||
| :zap: zap | 373 ns/op | +0% | 0 allocs/op |
|
||||
| :zap: zap (sugared) | 452 ns/op | +21% | 1 allocs/op |
|
||||
| zerolog | 288 ns/op | -23% | 0 allocs/op |
|
||||
| go-kit | 11785 ns/op | +3060% | 58 allocs/op |
|
||||
| logrus | 19629 ns/op | +5162% | 70 allocs/op |
|
||||
| log15 | 21866 ns/op | +5762% | 72 allocs/op |
|
||||
| apex/log | 30890 ns/op | +8182% | 55 allocs/op |
|
||||
|
||||
Log a static string, without any context or `printf`-style templating:
|
||||
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------ | :--: | :-----------: | :---------------: |
|
||||
| :zap: zap | 118 ns/op | +0% | 0 allocs/op
|
||||
| :zap: zap (sugared) | 191 ns/op | +62% | 2 allocs/op
|
||||
| zerolog | 93 ns/op | -21% | 0 allocs/op
|
||||
| go-kit | 280 ns/op | +137% | 11 allocs/op
|
||||
| standard library | 499 ns/op | +323% | 2 allocs/op
|
||||
| apex/log | 1990 ns/op | +1586% | 10 allocs/op
|
||||
| logrus | 3129 ns/op | +2552% | 24 allocs/op
|
||||
| log15 | 3887 ns/op | +3194% | 23 allocs/op
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------------------ | :--------: | :-----------: | :---------------: |
|
||||
| :zap: zap | 381 ns/op | +0% | 0 allocs/op |
|
||||
| :zap: zap (sugared) | 410 ns/op | +8% | 1 allocs/op |
|
||||
| zerolog | 369 ns/op | -3% | 0 allocs/op |
|
||||
| standard library | 385 ns/op | +1% | 2 allocs/op |
|
||||
| go-kit | 606 ns/op | +59% | 11 allocs/op |
|
||||
| logrus | 1730 ns/op | +354% | 25 allocs/op |
|
||||
| apex/log | 1998 ns/op | +424% | 7 allocs/op |
|
||||
| log15 | 4546 ns/op | +1093% | 22 allocs/op |
|
||||
|
||||
## Development Status: Stable
|
||||
|
||||
@ -131,4 +131,3 @@ pinned in the [benchmarks/go.mod][] file. [↩](#anchor-versions)
|
||||
[cov]: https://codecov.io/gh/uber-go/zap
|
||||
[benchmarking suite]: https://github.com/uber-go/zap/tree/master/benchmarks
|
||||
[benchmarks/go.mod]: https://github.com/uber-go/zap/blob/master/benchmarks/go.mod
|
||||
|
||||
|
156
vendor/go.uber.org/zap/array_go118.go
generated
vendored
Normal file
156
vendor/go.uber.org/zap/array_go118.go
generated
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
// Copyright (c) 2022 Uber Technologies, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
package zap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// Objects constructs a field with the given key, holding a list of the
|
||||
// provided objects that can be marshaled by Zap.
|
||||
//
|
||||
// Note that these objects must implement zapcore.ObjectMarshaler directly.
|
||||
// That is, if you're trying to marshal a []Request, the MarshalLogObject
|
||||
// method must be declared on the Request type, not its pointer (*Request).
|
||||
// If it's on the pointer, use ObjectValues.
|
||||
//
|
||||
// Given an object that implements MarshalLogObject on the value receiver, you
|
||||
// can log a slice of those objects with Objects like so:
|
||||
//
|
||||
// type Author struct{ ... }
|
||||
// func (a Author) MarshalLogObject(enc zapcore.ObjectEncoder) error
|
||||
//
|
||||
// var authors []Author = ...
|
||||
// logger.Info("loading article", zap.Objects("authors", authors))
|
||||
//
|
||||
// Similarly, given a type that implements MarshalLogObject on its pointer
|
||||
// receiver, you can log a slice of pointers to that object with Objects like
|
||||
// so:
|
||||
//
|
||||
// type Request struct{ ... }
|
||||
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
|
||||
//
|
||||
// var requests []*Request = ...
|
||||
// logger.Info("sending requests", zap.Objects("requests", requests))
|
||||
//
|
||||
// If instead, you have a slice of values of such an object, use the
|
||||
// ObjectValues constructor.
|
||||
//
|
||||
// var requests []Request = ...
|
||||
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
|
||||
func Objects[T zapcore.ObjectMarshaler](key string, values []T) Field {
|
||||
return Array(key, objects[T](values))
|
||||
}
|
||||
|
||||
type objects[T zapcore.ObjectMarshaler] []T
|
||||
|
||||
func (os objects[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for _, o := range os {
|
||||
if err := arr.AppendObject(o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// objectMarshalerPtr is a constraint that specifies that the given type
|
||||
// implements zapcore.ObjectMarshaler on a pointer receiver.
|
||||
type objectMarshalerPtr[T any] interface {
|
||||
*T
|
||||
zapcore.ObjectMarshaler
|
||||
}
|
||||
|
||||
// ObjectValues constructs a field with the given key, holding a list of the
|
||||
// provided objects, where pointers to these objects can be marshaled by Zap.
|
||||
//
|
||||
// Note that pointers to these objects must implement zapcore.ObjectMarshaler.
|
||||
// That is, if you're trying to marshal a []Request, the MarshalLogObject
|
||||
// method must be declared on the *Request type, not the value (Request).
|
||||
// If it's on the value, use Objects.
|
||||
//
|
||||
// Given an object that implements MarshalLogObject on the pointer receiver,
|
||||
// you can log a slice of those objects with ObjectValues like so:
|
||||
//
|
||||
// type Request struct{ ... }
|
||||
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
|
||||
//
|
||||
// var requests []Request = ...
|
||||
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
|
||||
//
|
||||
// If instead, you have a slice of pointers of such an object, use the Objects
|
||||
// field constructor.
|
||||
//
|
||||
// var requests []*Request = ...
|
||||
// logger.Info("sending requests", zap.Objects("requests", requests))
|
||||
func ObjectValues[T any, P objectMarshalerPtr[T]](key string, values []T) Field {
|
||||
return Array(key, objectValues[T, P](values))
|
||||
}
|
||||
|
||||
type objectValues[T any, P objectMarshalerPtr[T]] []T
|
||||
|
||||
func (os objectValues[T, P]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for i := range os {
|
||||
// It is necessary for us to explicitly reference the "P" type.
|
||||
// We cannot simply pass "&os[i]" to AppendObject because its type
|
||||
// is "*T", which the type system does not consider as
|
||||
// implementing ObjectMarshaler.
|
||||
// Only the type "P" satisfies ObjectMarshaler, which we have
|
||||
// to convert "*T" to explicitly.
|
||||
var p P = &os[i]
|
||||
if err := arr.AppendObject(p); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stringers constructs a field with the given key, holding a list of the
|
||||
// output provided by the value's String method
|
||||
//
|
||||
// Given an object that implements String on the value receiver, you
|
||||
// can log a slice of those objects with Objects like so:
|
||||
//
|
||||
// type Request struct{ ... }
|
||||
// func (a Request) String() string
|
||||
//
|
||||
// var requests []Request = ...
|
||||
// logger.Info("sending requests", zap.Stringers("requests", requests))
|
||||
//
|
||||
// Note that these objects must implement fmt.Stringer directly.
|
||||
// That is, if you're trying to marshal a []Request, the String method
|
||||
// must be declared on the Request type, not its pointer (*Request).
|
||||
func Stringers[T fmt.Stringer](key string, values []T) Field {
|
||||
return Array(key, stringers[T](values))
|
||||
}
|
||||
|
||||
type stringers[T fmt.Stringer] []T
|
||||
|
||||
func (os stringers[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for _, o := range os {
|
||||
arr.AppendString(o.String())
|
||||
}
|
||||
return nil
|
||||
}
|
4
vendor/go.uber.org/zap/config.go
generated
vendored
4
vendor/go.uber.org/zap/config.go
generated
vendored
@ -21,7 +21,7 @@
|
||||
package zap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@ -182,7 +182,7 @@ func (cfg Config) Build(opts ...Option) (*Logger, error) {
|
||||
}
|
||||
|
||||
if cfg.Level == (AtomicLevel{}) {
|
||||
return nil, fmt.Errorf("missing Level")
|
||||
return nil, errors.New("missing Level")
|
||||
}
|
||||
|
||||
log := New(
|
||||
|
60
vendor/go.uber.org/zap/doc.go
generated
vendored
60
vendor/go.uber.org/zap/doc.go
generated
vendored
@ -32,7 +32,7 @@
|
||||
// they need to count every allocation and when they'd prefer a more familiar,
|
||||
// loosely typed API.
|
||||
//
|
||||
// Choosing a Logger
|
||||
// # Choosing a Logger
|
||||
//
|
||||
// In contexts where performance is nice, but not critical, use the
|
||||
// SugaredLogger. It's 4-10x faster than other structured logging packages and
|
||||
@ -41,14 +41,15 @@
|
||||
// variadic number of key-value pairs. (For more advanced use cases, they also
|
||||
// accept strongly typed fields - see the SugaredLogger.With documentation for
|
||||
// details.)
|
||||
// sugar := zap.NewExample().Sugar()
|
||||
// defer sugar.Sync()
|
||||
// sugar.Infow("failed to fetch URL",
|
||||
// "url", "http://example.com",
|
||||
// "attempt", 3,
|
||||
// "backoff", time.Second,
|
||||
// )
|
||||
// sugar.Infof("failed to fetch URL: %s", "http://example.com")
|
||||
//
|
||||
// sugar := zap.NewExample().Sugar()
|
||||
// defer sugar.Sync()
|
||||
// sugar.Infow("failed to fetch URL",
|
||||
// "url", "http://example.com",
|
||||
// "attempt", 3,
|
||||
// "backoff", time.Second,
|
||||
// )
|
||||
// sugar.Infof("failed to fetch URL: %s", "http://example.com")
|
||||
//
|
||||
// By default, loggers are unbuffered. However, since zap's low-level APIs
|
||||
// allow buffering, calling Sync before letting your process exit is a good
|
||||
@ -57,32 +58,35 @@
|
||||
// In the rare contexts where every microsecond and every allocation matter,
|
||||
// use the Logger. It's even faster than the SugaredLogger and allocates far
|
||||
// less, but it only supports strongly-typed, structured logging.
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// logger.Info("failed to fetch URL",
|
||||
// zap.String("url", "http://example.com"),
|
||||
// zap.Int("attempt", 3),
|
||||
// zap.Duration("backoff", time.Second),
|
||||
// )
|
||||
//
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// logger.Info("failed to fetch URL",
|
||||
// zap.String("url", "http://example.com"),
|
||||
// zap.Int("attempt", 3),
|
||||
// zap.Duration("backoff", time.Second),
|
||||
// )
|
||||
//
|
||||
// Choosing between the Logger and SugaredLogger doesn't need to be an
|
||||
// application-wide decision: converting between the two is simple and
|
||||
// inexpensive.
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// sugar := logger.Sugar()
|
||||
// plain := sugar.Desugar()
|
||||
//
|
||||
// Configuring Zap
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// sugar := logger.Sugar()
|
||||
// plain := sugar.Desugar()
|
||||
//
|
||||
// # Configuring Zap
|
||||
//
|
||||
// The simplest way to build a Logger is to use zap's opinionated presets:
|
||||
// NewExample, NewProduction, and NewDevelopment. These presets build a logger
|
||||
// with a single function call:
|
||||
// logger, err := zap.NewProduction()
|
||||
// if err != nil {
|
||||
// log.Fatalf("can't initialize zap logger: %v", err)
|
||||
// }
|
||||
// defer logger.Sync()
|
||||
//
|
||||
// logger, err := zap.NewProduction()
|
||||
// if err != nil {
|
||||
// log.Fatalf("can't initialize zap logger: %v", err)
|
||||
// }
|
||||
// defer logger.Sync()
|
||||
//
|
||||
// Presets are fine for small projects, but larger projects and organizations
|
||||
// naturally require a bit more customization. For most users, zap's Config
|
||||
@ -94,7 +98,7 @@
|
||||
// go.uber.org/zap/zapcore. See the package-level AdvancedConfiguration
|
||||
// example for sample code.
|
||||
//
|
||||
// Extending Zap
|
||||
// # Extending Zap
|
||||
//
|
||||
// The zap package itself is a relatively thin wrapper around the interfaces
|
||||
// in go.uber.org/zap/zapcore. Extending zap to support a new encoding (e.g.,
|
||||
@ -106,7 +110,7 @@
|
||||
// Similarly, package authors can use the high-performance Encoder and Core
|
||||
// implementations in the zapcore package to build their own loggers.
|
||||
//
|
||||
// Frequently Asked Questions
|
||||
// # Frequently Asked Questions
|
||||
//
|
||||
// An FAQ covering everything from installation errors to design decisions is
|
||||
// available at https://github.com/uber-go/zap/blob/master/FAQ.md.
|
||||
|
2
vendor/go.uber.org/zap/encoder.go
generated
vendored
2
vendor/go.uber.org/zap/encoder.go
generated
vendored
@ -63,7 +63,7 @@ func RegisterEncoder(name string, constructor func(zapcore.EncoderConfig) (zapco
|
||||
|
||||
func newEncoder(name string, encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) {
|
||||
if encoderConfig.TimeKey != "" && encoderConfig.EncodeTime == nil {
|
||||
return nil, fmt.Errorf("missing EncodeTime in EncoderConfig")
|
||||
return nil, errors.New("missing EncodeTime in EncoderConfig")
|
||||
}
|
||||
|
||||
_encoderMutex.RLock()
|
||||
|
1
vendor/go.uber.org/zap/global.go
generated
vendored
1
vendor/go.uber.org/zap/global.go
generated
vendored
@ -31,6 +31,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
_stdLogDefaultDepth = 1
|
||||
_loggerWriterDepth = 2
|
||||
_programmerErrorTemplate = "You've found a bug in zap! Please file a bug at " +
|
||||
"https://github.com/uber-go/zap/issues/new and reference this error: %v"
|
||||
|
25
vendor/go.uber.org/zap/http_handler.go
generated
vendored
25
vendor/go.uber.org/zap/http_handler.go
generated
vendored
@ -22,6 +22,7 @@ package zap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -32,22 +33,23 @@ import (
|
||||
// ServeHTTP is a simple JSON endpoint that can report on or change the current
|
||||
// logging level.
|
||||
//
|
||||
// GET
|
||||
// # GET
|
||||
//
|
||||
// The GET request returns a JSON description of the current logging level like:
|
||||
// {"level":"info"}
|
||||
//
|
||||
// PUT
|
||||
// {"level":"info"}
|
||||
//
|
||||
// # PUT
|
||||
//
|
||||
// The PUT request changes the logging level. It is perfectly safe to change the
|
||||
// logging level while a program is running. Two content types are supported:
|
||||
//
|
||||
// Content-Type: application/x-www-form-urlencoded
|
||||
// Content-Type: application/x-www-form-urlencoded
|
||||
//
|
||||
// With this content type, the level can be provided through the request body or
|
||||
// a query parameter. The log level is URL encoded like:
|
||||
//
|
||||
// level=debug
|
||||
// level=debug
|
||||
//
|
||||
// The request body takes precedence over the query parameter, if both are
|
||||
// specified.
|
||||
@ -55,18 +57,17 @@ import (
|
||||
// This content type is the default for a curl PUT request. Following are two
|
||||
// example curl requests that both set the logging level to debug.
|
||||
//
|
||||
// curl -X PUT localhost:8080/log/level?level=debug
|
||||
// curl -X PUT localhost:8080/log/level -d level=debug
|
||||
// curl -X PUT localhost:8080/log/level?level=debug
|
||||
// curl -X PUT localhost:8080/log/level -d level=debug
|
||||
//
|
||||
// For any other content type, the payload is expected to be JSON encoded and
|
||||
// look like:
|
||||
//
|
||||
// {"level":"info"}
|
||||
// {"level":"info"}
|
||||
//
|
||||
// An example curl request could look like this:
|
||||
//
|
||||
// curl -X PUT localhost:8080/log/level -H "Content-Type: application/json" -d '{"level":"debug"}'
|
||||
//
|
||||
// curl -X PUT localhost:8080/log/level -H "Content-Type: application/json" -d '{"level":"debug"}'
|
||||
func (lvl AtomicLevel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
type errorResponse struct {
|
||||
Error string `json:"error"`
|
||||
@ -108,7 +109,7 @@ func decodePutRequest(contentType string, r *http.Request) (zapcore.Level, error
|
||||
func decodePutURL(r *http.Request) (zapcore.Level, error) {
|
||||
lvl := r.FormValue("level")
|
||||
if lvl == "" {
|
||||
return 0, fmt.Errorf("must specify logging level")
|
||||
return 0, errors.New("must specify logging level")
|
||||
}
|
||||
var l zapcore.Level
|
||||
if err := l.UnmarshalText([]byte(lvl)); err != nil {
|
||||
@ -125,7 +126,7 @@ func decodePutJSON(body io.Reader) (zapcore.Level, error) {
|
||||
return 0, fmt.Errorf("malformed request body: %v", err)
|
||||
}
|
||||
if pld.Level == nil {
|
||||
return 0, fmt.Errorf("must specify logging level")
|
||||
return 0, errors.New("must specify logging level")
|
||||
}
|
||||
return *pld.Level, nil
|
||||
|
||||
|
22
vendor/go.uber.org/zap/internal/exit/exit.go
generated
vendored
22
vendor/go.uber.org/zap/internal/exit/exit.go
generated
vendored
@ -24,24 +24,25 @@ package exit
|
||||
|
||||
import "os"
|
||||
|
||||
var real = func() { os.Exit(1) }
|
||||
var _exit = os.Exit
|
||||
|
||||
// Exit normally terminates the process by calling os.Exit(1). If the package
|
||||
// is stubbed, it instead records a call in the testing spy.
|
||||
func Exit() {
|
||||
real()
|
||||
// With terminates the process by calling os.Exit(code). If the package is
|
||||
// stubbed, it instead records a call in the testing spy.
|
||||
func With(code int) {
|
||||
_exit(code)
|
||||
}
|
||||
|
||||
// A StubbedExit is a testing fake for os.Exit.
|
||||
type StubbedExit struct {
|
||||
Exited bool
|
||||
prev func()
|
||||
Code int
|
||||
prev func(code int)
|
||||
}
|
||||
|
||||
// Stub substitutes a fake for the call to os.Exit(1).
|
||||
func Stub() *StubbedExit {
|
||||
s := &StubbedExit{prev: real}
|
||||
real = s.exit
|
||||
s := &StubbedExit{prev: _exit}
|
||||
_exit = s.exit
|
||||
return s
|
||||
}
|
||||
|
||||
@ -56,9 +57,10 @@ func WithStub(f func()) *StubbedExit {
|
||||
|
||||
// Unstub restores the previous exit function.
|
||||
func (se *StubbedExit) Unstub() {
|
||||
real = se.prev
|
||||
_exit = se.prev
|
||||
}
|
||||
|
||||
func (se *StubbedExit) exit() {
|
||||
func (se *StubbedExit) exit(code int) {
|
||||
se.Exited = true
|
||||
se.Code = code
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2019 Uber Technologies, Inc.
|
||||
// Copyright (c) 2022 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@ -18,9 +18,18 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
// See #682 for more information.
|
||||
// +build go1.12
|
||||
package internal
|
||||
|
||||
package zap
|
||||
import "go.uber.org/zap/zapcore"
|
||||
|
||||
const _stdLogDefaultDepth = 1
|
||||
// LeveledEnabler is an interface satisfied by LevelEnablers that are able to
|
||||
// report their own level.
|
||||
//
|
||||
// This interface is defined to use more conveniently in tests and non-zapcore
|
||||
// packages.
|
||||
// This cannot be imported from zapcore because of the cyclic dependency.
|
||||
type LeveledEnabler interface {
|
||||
zapcore.LevelEnabler
|
||||
|
||||
Level() zapcore.Level
|
||||
}
|
20
vendor/go.uber.org/zap/level.go
generated
vendored
20
vendor/go.uber.org/zap/level.go
generated
vendored
@ -22,6 +22,7 @@ package zap
|
||||
|
||||
import (
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap/internal"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
@ -70,6 +71,8 @@ type AtomicLevel struct {
|
||||
l *atomic.Int32
|
||||
}
|
||||
|
||||
var _ internal.LeveledEnabler = AtomicLevel{}
|
||||
|
||||
// NewAtomicLevel creates an AtomicLevel with InfoLevel and above logging
|
||||
// enabled.
|
||||
func NewAtomicLevel() AtomicLevel {
|
||||
@ -86,6 +89,23 @@ func NewAtomicLevelAt(l zapcore.Level) AtomicLevel {
|
||||
return a
|
||||
}
|
||||
|
||||
// ParseAtomicLevel parses an AtomicLevel based on a lowercase or all-caps ASCII
|
||||
// representation of the log level. If the provided ASCII representation is
|
||||
// invalid an error is returned.
|
||||
//
|
||||
// This is particularly useful when dealing with text input to configure log
|
||||
// levels.
|
||||
func ParseAtomicLevel(text string) (AtomicLevel, error) {
|
||||
a := NewAtomicLevel()
|
||||
l, err := zapcore.ParseLevel(text)
|
||||
if err != nil {
|
||||
return a, err
|
||||
}
|
||||
|
||||
a.SetLevel(l)
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Enabled implements the zapcore.LevelEnabler interface, which allows the
|
||||
// AtomicLevel to be used in place of traditional static levels.
|
||||
func (lvl AtomicLevel) Enabled(l zapcore.Level) bool {
|
||||
|
119
vendor/go.uber.org/zap/logger.go
generated
vendored
119
vendor/go.uber.org/zap/logger.go
generated
vendored
@ -22,11 +22,11 @@ package zap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
@ -42,7 +42,7 @@ type Logger struct {
|
||||
|
||||
development bool
|
||||
addCaller bool
|
||||
onFatal zapcore.CheckWriteAction // default is WriteThenFatal
|
||||
onFatal zapcore.CheckWriteHook // default is WriteThenFatal
|
||||
|
||||
name string
|
||||
errorOutput zapcore.WriteSyncer
|
||||
@ -85,7 +85,7 @@ func New(core zapcore.Core, options ...Option) *Logger {
|
||||
func NewNop() *Logger {
|
||||
return &Logger{
|
||||
core: zapcore.NewNopCore(),
|
||||
errorOutput: zapcore.AddSync(ioutil.Discard),
|
||||
errorOutput: zapcore.AddSync(io.Discard),
|
||||
addStack: zapcore.FatalLevel + 1,
|
||||
clock: zapcore.DefaultClock,
|
||||
}
|
||||
@ -107,6 +107,19 @@ func NewDevelopment(options ...Option) (*Logger, error) {
|
||||
return NewDevelopmentConfig().Build(options...)
|
||||
}
|
||||
|
||||
// Must is a helper that wraps a call to a function returning (*Logger, error)
|
||||
// and panics if the error is non-nil. It is intended for use in variable
|
||||
// initialization such as:
|
||||
//
|
||||
// var logger = zap.Must(zap.NewProduction())
|
||||
func Must(logger *Logger, err error) *Logger {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return logger
|
||||
}
|
||||
|
||||
// NewExample builds a Logger that's designed for use in zap's testable
|
||||
// examples. It writes DebugLevel and above logs to standard out as JSON, but
|
||||
// omits the timestamp and calling function to keep example output
|
||||
@ -177,6 +190,14 @@ func (log *Logger) Check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
|
||||
return log.check(lvl, msg)
|
||||
}
|
||||
|
||||
// Log logs a message at the specified level. The message includes any fields
|
||||
// passed at the log site, as well as any fields accumulated on the logger.
|
||||
func (log *Logger) Log(lvl zapcore.Level, msg string, fields ...Field) {
|
||||
if ce := log.check(lvl, msg); ce != nil {
|
||||
ce.Write(fields...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug logs a message at DebugLevel. The message includes any fields passed
|
||||
// at the log site, as well as any fields accumulated on the logger.
|
||||
func (log *Logger) Debug(msg string, fields ...Field) {
|
||||
@ -259,8 +280,10 @@ func (log *Logger) clone() *Logger {
|
||||
}
|
||||
|
||||
func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
|
||||
// check must always be called directly by a method in the Logger interface
|
||||
// (e.g., Check, Info, Fatal).
|
||||
// Logger.check must always be called directly by a method in the
|
||||
// Logger interface (e.g., Check, Info, Fatal).
|
||||
// This skips Logger.check and the Info/Fatal/Check/etc. method that
|
||||
// called it.
|
||||
const callerSkipOffset = 2
|
||||
|
||||
// Check the level first to reduce the cost of disabled log calls.
|
||||
@ -283,18 +306,27 @@ func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
|
||||
// Set up any required terminal behavior.
|
||||
switch ent.Level {
|
||||
case zapcore.PanicLevel:
|
||||
ce = ce.Should(ent, zapcore.WriteThenPanic)
|
||||
ce = ce.After(ent, zapcore.WriteThenPanic)
|
||||
case zapcore.FatalLevel:
|
||||
onFatal := log.onFatal
|
||||
// Noop is the default value for CheckWriteAction, and it leads to
|
||||
// continued execution after a Fatal which is unexpected.
|
||||
if onFatal == zapcore.WriteThenNoop {
|
||||
// nil or WriteThenNoop will lead to continued execution after
|
||||
// a Fatal log entry, which is unexpected. For example,
|
||||
//
|
||||
// f, err := os.Open(..)
|
||||
// if err != nil {
|
||||
// log.Fatal("cannot open", zap.Error(err))
|
||||
// }
|
||||
// fmt.Println(f.Name())
|
||||
//
|
||||
// The f.Name() will panic if we continue execution after the
|
||||
// log.Fatal.
|
||||
if onFatal == nil || onFatal == zapcore.WriteThenNoop {
|
||||
onFatal = zapcore.WriteThenFatal
|
||||
}
|
||||
ce = ce.Should(ent, onFatal)
|
||||
ce = ce.After(ent, onFatal)
|
||||
case zapcore.DPanicLevel:
|
||||
if log.development {
|
||||
ce = ce.Should(ent, zapcore.WriteThenPanic)
|
||||
ce = ce.After(ent, zapcore.WriteThenPanic)
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,42 +339,55 @@ func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
|
||||
|
||||
// Thread the error output through to the CheckedEntry.
|
||||
ce.ErrorOutput = log.errorOutput
|
||||
if log.addCaller {
|
||||
frame, defined := getCallerFrame(log.callerSkip + callerSkipOffset)
|
||||
if !defined {
|
||||
|
||||
addStack := log.addStack.Enabled(ce.Level)
|
||||
if !log.addCaller && !addStack {
|
||||
return ce
|
||||
}
|
||||
|
||||
// Adding the caller or stack trace requires capturing the callers of
|
||||
// this function. We'll share information between these two.
|
||||
stackDepth := stacktraceFirst
|
||||
if addStack {
|
||||
stackDepth = stacktraceFull
|
||||
}
|
||||
stack := captureStacktrace(log.callerSkip+callerSkipOffset, stackDepth)
|
||||
defer stack.Free()
|
||||
|
||||
if stack.Count() == 0 {
|
||||
if log.addCaller {
|
||||
fmt.Fprintf(log.errorOutput, "%v Logger.check error: failed to get caller\n", ent.Time.UTC())
|
||||
log.errorOutput.Sync()
|
||||
}
|
||||
return ce
|
||||
}
|
||||
|
||||
ce.Entry.Caller = zapcore.EntryCaller{
|
||||
Defined: defined,
|
||||
frame, more := stack.Next()
|
||||
|
||||
if log.addCaller {
|
||||
ce.Caller = zapcore.EntryCaller{
|
||||
Defined: frame.PC != 0,
|
||||
PC: frame.PC,
|
||||
File: frame.File,
|
||||
Line: frame.Line,
|
||||
Function: frame.Function,
|
||||
}
|
||||
}
|
||||
if log.addStack.Enabled(ce.Entry.Level) {
|
||||
ce.Entry.Stack = StackSkip("", log.callerSkip+callerSkipOffset).String
|
||||
|
||||
if addStack {
|
||||
buffer := bufferpool.Get()
|
||||
defer buffer.Free()
|
||||
|
||||
stackfmt := newStackFormatter(buffer)
|
||||
|
||||
// We've already extracted the first frame, so format that
|
||||
// separately and defer to stackfmt for the rest.
|
||||
stackfmt.FormatFrame(frame)
|
||||
if more {
|
||||
stackfmt.FormatStack(stack)
|
||||
}
|
||||
ce.Stack = buffer.String()
|
||||
}
|
||||
|
||||
return ce
|
||||
}
|
||||
|
||||
// getCallerFrame gets caller frame. The argument skip is the number of stack
|
||||
// frames to ascend, with 0 identifying the caller of getCallerFrame. The
|
||||
// boolean ok is false if it was not possible to recover the information.
|
||||
//
|
||||
// Note: This implementation is similar to runtime.Caller, but it returns the whole frame.
|
||||
func getCallerFrame(skip int) (frame runtime.Frame, ok bool) {
|
||||
const skipOffset = 2 // skip getCallerFrame and Callers
|
||||
|
||||
pc := make([]uintptr, 1)
|
||||
numFrames := runtime.Callers(skip+skipOffset, pc)
|
||||
if numFrames < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
frame, _ = runtime.CallersFrames(pc).Next()
|
||||
return frame, frame.PC != 0
|
||||
}
|
||||
|
20
vendor/go.uber.org/zap/options.go
generated
vendored
20
vendor/go.uber.org/zap/options.go
generated
vendored
@ -133,9 +133,27 @@ func IncreaseLevel(lvl zapcore.LevelEnabler) Option {
|
||||
}
|
||||
|
||||
// OnFatal sets the action to take on fatal logs.
|
||||
// Deprecated: Use WithFatalHook instead.
|
||||
func OnFatal(action zapcore.CheckWriteAction) Option {
|
||||
return WithFatalHook(action)
|
||||
}
|
||||
|
||||
// WithFatalHook sets a CheckWriteHook to run on fatal logs.
|
||||
// Zap will call this hook after writing a log statement with a Fatal level.
|
||||
//
|
||||
// For example, the following builds a logger that will exit the current
|
||||
// goroutine after writing a fatal log message, but it will not exit the
|
||||
// program.
|
||||
//
|
||||
// zap.New(core, zap.WithFatalHook(zapcore.WriteThenGoexit))
|
||||
//
|
||||
// It is important that the provided CheckWriteHook stops the control flow at
|
||||
// the current statement to meet expectations of callers of the logger.
|
||||
// We recommend calling os.Exit or runtime.Goexit inside custom hooks at
|
||||
// minimum.
|
||||
func WithFatalHook(hook zapcore.CheckWriteHook) Option {
|
||||
return optionFunc(func(log *Logger) {
|
||||
log.onFatal = action
|
||||
log.onFatal = hook
|
||||
})
|
||||
}
|
||||
|
||||
|
179
vendor/go.uber.org/zap/stacktrace.go
generated
vendored
179
vendor/go.uber.org/zap/stacktrace.go
generated
vendored
@ -24,62 +24,153 @@ import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap/buffer"
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
)
|
||||
|
||||
var (
|
||||
_stacktracePool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return newProgramCounters(64)
|
||||
},
|
||||
}
|
||||
var _stacktracePool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &stacktrace{
|
||||
storage: make([]uintptr, 64),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
type stacktrace struct {
|
||||
pcs []uintptr // program counters; always a subslice of storage
|
||||
frames *runtime.Frames
|
||||
|
||||
// The size of pcs varies depending on requirements:
|
||||
// it will be one if the only the first frame was requested,
|
||||
// and otherwise it will reflect the depth of the call stack.
|
||||
//
|
||||
// storage decouples the slice we need (pcs) from the slice we pool.
|
||||
// We will always allocate a reasonably large storage, but we'll use
|
||||
// only as much of it as we need.
|
||||
storage []uintptr
|
||||
}
|
||||
|
||||
// stacktraceDepth specifies how deep of a stack trace should be captured.
|
||||
type stacktraceDepth int
|
||||
|
||||
const (
|
||||
// stacktraceFirst captures only the first frame.
|
||||
stacktraceFirst stacktraceDepth = iota
|
||||
|
||||
// stacktraceFull captures the entire call stack, allocating more
|
||||
// storage for it if needed.
|
||||
stacktraceFull
|
||||
)
|
||||
|
||||
// captureStacktrace captures a stack trace of the specified depth, skipping
|
||||
// the provided number of frames. skip=0 identifies the caller of
|
||||
// captureStacktrace.
|
||||
//
|
||||
// The caller must call Free on the returned stacktrace after using it.
|
||||
func captureStacktrace(skip int, depth stacktraceDepth) *stacktrace {
|
||||
stack := _stacktracePool.Get().(*stacktrace)
|
||||
|
||||
switch depth {
|
||||
case stacktraceFirst:
|
||||
stack.pcs = stack.storage[:1]
|
||||
case stacktraceFull:
|
||||
stack.pcs = stack.storage
|
||||
}
|
||||
|
||||
// Unlike other "skip"-based APIs, skip=0 identifies runtime.Callers
|
||||
// itself. +2 to skip captureStacktrace and runtime.Callers.
|
||||
numFrames := runtime.Callers(
|
||||
skip+2,
|
||||
stack.pcs,
|
||||
)
|
||||
|
||||
// runtime.Callers truncates the recorded stacktrace if there is no
|
||||
// room in the provided slice. For the full stack trace, keep expanding
|
||||
// storage until there are fewer frames than there is room.
|
||||
if depth == stacktraceFull {
|
||||
pcs := stack.pcs
|
||||
for numFrames == len(pcs) {
|
||||
pcs = make([]uintptr, len(pcs)*2)
|
||||
numFrames = runtime.Callers(skip+2, pcs)
|
||||
}
|
||||
|
||||
// Discard old storage instead of returning it to the pool.
|
||||
// This will adjust the pool size over time if stack traces are
|
||||
// consistently very deep.
|
||||
stack.storage = pcs
|
||||
stack.pcs = pcs[:numFrames]
|
||||
} else {
|
||||
stack.pcs = stack.pcs[:numFrames]
|
||||
}
|
||||
|
||||
stack.frames = runtime.CallersFrames(stack.pcs)
|
||||
return stack
|
||||
}
|
||||
|
||||
// Free releases resources associated with this stacktrace
|
||||
// and returns it back to the pool.
|
||||
func (st *stacktrace) Free() {
|
||||
st.frames = nil
|
||||
st.pcs = nil
|
||||
_stacktracePool.Put(st)
|
||||
}
|
||||
|
||||
// Count reports the total number of frames in this stacktrace.
|
||||
// Count DOES NOT change as Next is called.
|
||||
func (st *stacktrace) Count() int {
|
||||
return len(st.pcs)
|
||||
}
|
||||
|
||||
// Next returns the next frame in the stack trace,
|
||||
// and a boolean indicating whether there are more after it.
|
||||
func (st *stacktrace) Next() (_ runtime.Frame, more bool) {
|
||||
return st.frames.Next()
|
||||
}
|
||||
|
||||
func takeStacktrace(skip int) string {
|
||||
stack := captureStacktrace(skip+1, stacktraceFull)
|
||||
defer stack.Free()
|
||||
|
||||
buffer := bufferpool.Get()
|
||||
defer buffer.Free()
|
||||
programCounters := _stacktracePool.Get().(*programCounters)
|
||||
defer _stacktracePool.Put(programCounters)
|
||||
|
||||
var numFrames int
|
||||
for {
|
||||
// Skip the call to runtime.Callers and takeStacktrace so that the
|
||||
// program counters start at the caller of takeStacktrace.
|
||||
numFrames = runtime.Callers(skip+2, programCounters.pcs)
|
||||
if numFrames < len(programCounters.pcs) {
|
||||
break
|
||||
}
|
||||
// Don't put the too-short counter slice back into the pool; this lets
|
||||
// the pool adjust if we consistently take deep stacktraces.
|
||||
programCounters = newProgramCounters(len(programCounters.pcs) * 2)
|
||||
}
|
||||
|
||||
i := 0
|
||||
frames := runtime.CallersFrames(programCounters.pcs[:numFrames])
|
||||
|
||||
// Note: On the last iteration, frames.Next() returns false, with a valid
|
||||
// frame, but we ignore this frame. The last frame is a a runtime frame which
|
||||
// adds noise, since it's only either runtime.main or runtime.goexit.
|
||||
for frame, more := frames.Next(); more; frame, more = frames.Next() {
|
||||
if i != 0 {
|
||||
buffer.AppendByte('\n')
|
||||
}
|
||||
i++
|
||||
buffer.AppendString(frame.Function)
|
||||
buffer.AppendByte('\n')
|
||||
buffer.AppendByte('\t')
|
||||
buffer.AppendString(frame.File)
|
||||
buffer.AppendByte(':')
|
||||
buffer.AppendInt(int64(frame.Line))
|
||||
}
|
||||
|
||||
stackfmt := newStackFormatter(buffer)
|
||||
stackfmt.FormatStack(stack)
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
type programCounters struct {
|
||||
pcs []uintptr
|
||||
// stackFormatter formats a stack trace into a readable string representation.
|
||||
type stackFormatter struct {
|
||||
b *buffer.Buffer
|
||||
nonEmpty bool // whehther we've written at least one frame already
|
||||
}
|
||||
|
||||
func newProgramCounters(size int) *programCounters {
|
||||
return &programCounters{make([]uintptr, size)}
|
||||
// newStackFormatter builds a new stackFormatter.
|
||||
func newStackFormatter(b *buffer.Buffer) stackFormatter {
|
||||
return stackFormatter{b: b}
|
||||
}
|
||||
|
||||
// FormatStack formats all remaining frames in the provided stacktrace -- minus
|
||||
// the final runtime.main/runtime.goexit frame.
|
||||
func (sf *stackFormatter) FormatStack(stack *stacktrace) {
|
||||
// Note: On the last iteration, frames.Next() returns false, with a valid
|
||||
// frame, but we ignore this frame. The last frame is a a runtime frame which
|
||||
// adds noise, since it's only either runtime.main or runtime.goexit.
|
||||
for frame, more := stack.Next(); more; frame, more = stack.Next() {
|
||||
sf.FormatFrame(frame)
|
||||
}
|
||||
}
|
||||
|
||||
// FormatFrame formats the given frame.
|
||||
func (sf *stackFormatter) FormatFrame(frame runtime.Frame) {
|
||||
if sf.nonEmpty {
|
||||
sf.b.AppendByte('\n')
|
||||
}
|
||||
sf.nonEmpty = true
|
||||
sf.b.AppendString(frame.Function)
|
||||
sf.b.AppendByte('\n')
|
||||
sf.b.AppendByte('\t')
|
||||
sf.b.AppendString(frame.File)
|
||||
sf.b.AppendByte(':')
|
||||
sf.b.AppendInt(int64(frame.Line))
|
||||
}
|
||||
|
116
vendor/go.uber.org/zap/sugar.go
generated
vendored
116
vendor/go.uber.org/zap/sugar.go
generated
vendored
@ -38,10 +38,19 @@ const (
|
||||
// method.
|
||||
//
|
||||
// Unlike the Logger, the SugaredLogger doesn't insist on structured logging.
|
||||
// For each log level, it exposes three methods: one for loosely-typed
|
||||
// structured logging, one for println-style formatting, and one for
|
||||
// printf-style formatting. For example, SugaredLoggers can produce InfoLevel
|
||||
// output with Infow ("info with" structured context), Info, or Infof.
|
||||
// For each log level, it exposes four methods:
|
||||
//
|
||||
// - methods named after the log level for log.Print-style logging
|
||||
// - methods ending in "w" for loosely-typed structured logging
|
||||
// - methods ending in "f" for log.Printf-style logging
|
||||
// - methods ending in "ln" for log.Println-style logging
|
||||
//
|
||||
// For example, the methods for InfoLevel are:
|
||||
//
|
||||
// Info(...any) Print-style logging
|
||||
// Infow(...any) Structured logging (read as "info with")
|
||||
// Infof(string, ...any) Printf-style logging
|
||||
// Infoln(...any) Println-style logging
|
||||
type SugaredLogger struct {
|
||||
base *Logger
|
||||
}
|
||||
@ -61,27 +70,40 @@ func (s *SugaredLogger) Named(name string) *SugaredLogger {
|
||||
return &SugaredLogger{base: s.base.Named(name)}
|
||||
}
|
||||
|
||||
// WithOptions clones the current SugaredLogger, applies the supplied Options,
|
||||
// and returns the result. It's safe to use concurrently.
|
||||
func (s *SugaredLogger) WithOptions(opts ...Option) *SugaredLogger {
|
||||
base := s.base.clone()
|
||||
for _, opt := range opts {
|
||||
opt.apply(base)
|
||||
}
|
||||
return &SugaredLogger{base: base}
|
||||
}
|
||||
|
||||
// With adds a variadic number of fields to the logging context. It accepts a
|
||||
// mix of strongly-typed Field objects and loosely-typed key-value pairs. When
|
||||
// processing pairs, the first element of the pair is used as the field key
|
||||
// and the second as the field value.
|
||||
//
|
||||
// For example,
|
||||
// sugaredLogger.With(
|
||||
// "hello", "world",
|
||||
// "failure", errors.New("oh no"),
|
||||
// Stack(),
|
||||
// "count", 42,
|
||||
// "user", User{Name: "alice"},
|
||||
// )
|
||||
//
|
||||
// sugaredLogger.With(
|
||||
// "hello", "world",
|
||||
// "failure", errors.New("oh no"),
|
||||
// Stack(),
|
||||
// "count", 42,
|
||||
// "user", User{Name: "alice"},
|
||||
// )
|
||||
//
|
||||
// is the equivalent of
|
||||
// unsugared.With(
|
||||
// String("hello", "world"),
|
||||
// String("failure", "oh no"),
|
||||
// Stack(),
|
||||
// Int("count", 42),
|
||||
// Object("user", User{Name: "alice"}),
|
||||
// )
|
||||
//
|
||||
// unsugared.With(
|
||||
// String("hello", "world"),
|
||||
// String("failure", "oh no"),
|
||||
// Stack(),
|
||||
// Int("count", 42),
|
||||
// Object("user", User{Name: "alice"}),
|
||||
// )
|
||||
//
|
||||
// Note that the keys in key-value pairs should be strings. In development,
|
||||
// passing a non-string key panics. In production, the logger is more
|
||||
@ -168,7 +190,8 @@ func (s *SugaredLogger) Fatalf(template string, args ...interface{}) {
|
||||
// pairs are treated as they are in With.
|
||||
//
|
||||
// When debug-level logging is disabled, this is much faster than
|
||||
// s.With(keysAndValues).Debug(msg)
|
||||
//
|
||||
// s.With(keysAndValues).Debug(msg)
|
||||
func (s *SugaredLogger) Debugw(msg string, keysAndValues ...interface{}) {
|
||||
s.log(DebugLevel, msg, nil, keysAndValues)
|
||||
}
|
||||
@ -210,11 +233,48 @@ func (s *SugaredLogger) Fatalw(msg string, keysAndValues ...interface{}) {
|
||||
s.log(FatalLevel, msg, nil, keysAndValues)
|
||||
}
|
||||
|
||||
// Debugln uses fmt.Sprintln to construct and log a message.
|
||||
func (s *SugaredLogger) Debugln(args ...interface{}) {
|
||||
s.logln(DebugLevel, args, nil)
|
||||
}
|
||||
|
||||
// Infoln uses fmt.Sprintln to construct and log a message.
|
||||
func (s *SugaredLogger) Infoln(args ...interface{}) {
|
||||
s.logln(InfoLevel, args, nil)
|
||||
}
|
||||
|
||||
// Warnln uses fmt.Sprintln to construct and log a message.
|
||||
func (s *SugaredLogger) Warnln(args ...interface{}) {
|
||||
s.logln(WarnLevel, args, nil)
|
||||
}
|
||||
|
||||
// Errorln uses fmt.Sprintln to construct and log a message.
|
||||
func (s *SugaredLogger) Errorln(args ...interface{}) {
|
||||
s.logln(ErrorLevel, args, nil)
|
||||
}
|
||||
|
||||
// DPanicln uses fmt.Sprintln to construct and log a message. In development, the
|
||||
// logger then panics. (See DPanicLevel for details.)
|
||||
func (s *SugaredLogger) DPanicln(args ...interface{}) {
|
||||
s.logln(DPanicLevel, args, nil)
|
||||
}
|
||||
|
||||
// Panicln uses fmt.Sprintln to construct and log a message, then panics.
|
||||
func (s *SugaredLogger) Panicln(args ...interface{}) {
|
||||
s.logln(PanicLevel, args, nil)
|
||||
}
|
||||
|
||||
// Fatalln uses fmt.Sprintln to construct and log a message, then calls os.Exit.
|
||||
func (s *SugaredLogger) Fatalln(args ...interface{}) {
|
||||
s.logln(FatalLevel, args, nil)
|
||||
}
|
||||
|
||||
// Sync flushes any buffered log entries.
|
||||
func (s *SugaredLogger) Sync() error {
|
||||
return s.base.Sync()
|
||||
}
|
||||
|
||||
// log message with Sprint, Sprintf, or neither.
|
||||
func (s *SugaredLogger) log(lvl zapcore.Level, template string, fmtArgs []interface{}, context []interface{}) {
|
||||
// If logging at this level is completely disabled, skip the overhead of
|
||||
// string formatting.
|
||||
@ -228,6 +288,18 @@ func (s *SugaredLogger) log(lvl zapcore.Level, template string, fmtArgs []interf
|
||||
}
|
||||
}
|
||||
|
||||
// logln message with Sprintln
|
||||
func (s *SugaredLogger) logln(lvl zapcore.Level, fmtArgs []interface{}, context []interface{}) {
|
||||
if lvl < DPanicLevel && !s.base.Core().Enabled(lvl) {
|
||||
return
|
||||
}
|
||||
|
||||
msg := getMessageln(fmtArgs)
|
||||
if ce := s.base.Check(lvl, msg); ce != nil {
|
||||
ce.Write(s.sweetenFields(context)...)
|
||||
}
|
||||
}
|
||||
|
||||
// getMessage format with Sprint, Sprintf, or neither.
|
||||
func getMessage(template string, fmtArgs []interface{}) string {
|
||||
if len(fmtArgs) == 0 {
|
||||
@ -246,6 +318,12 @@ func getMessage(template string, fmtArgs []interface{}) string {
|
||||
return fmt.Sprint(fmtArgs...)
|
||||
}
|
||||
|
||||
// getMessageln format with Sprintln.
|
||||
func getMessageln(fmtArgs []interface{}) string {
|
||||
msg := fmt.Sprintln(fmtArgs...)
|
||||
return msg[:len(msg)-1]
|
||||
}
|
||||
|
||||
func (s *SugaredLogger) sweetenFields(args []interface{}) []Field {
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
|
9
vendor/go.uber.org/zap/writer.go
generated
vendored
9
vendor/go.uber.org/zap/writer.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
// Copyright (c) 2016-2022 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@ -23,7 +23,6 @@ package zap
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
@ -71,7 +70,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
for _, path := range paths {
|
||||
sink, err := newSink(path)
|
||||
if err != nil {
|
||||
openErr = multierr.Append(openErr, fmt.Errorf("couldn't open sink %q: %v", path, err))
|
||||
openErr = multierr.Append(openErr, fmt.Errorf("open sink %q: %w", path, err))
|
||||
continue
|
||||
}
|
||||
writers = append(writers, sink)
|
||||
@ -79,7 +78,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
}
|
||||
if openErr != nil {
|
||||
close()
|
||||
return writers, nil, openErr
|
||||
return nil, nil, openErr
|
||||
}
|
||||
|
||||
return writers, close, nil
|
||||
@ -93,7 +92,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
// using zapcore.NewMultiWriteSyncer and zapcore.Lock individually.
|
||||
func CombineWriteSyncers(writers ...zapcore.WriteSyncer) zapcore.WriteSyncer {
|
||||
if len(writers) == 0 {
|
||||
return zapcore.AddSync(ioutil.Discard)
|
||||
return zapcore.AddSync(io.Discard)
|
||||
}
|
||||
return zapcore.Lock(zapcore.NewMultiWriteSyncer(writers...))
|
||||
}
|
||||
|
31
vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go
generated
vendored
31
vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go
generated
vendored
@ -43,6 +43,37 @@ const (
|
||||
//
|
||||
// BufferedWriteSyncer is safe for concurrent use. You don't need to use
|
||||
// zapcore.Lock for WriteSyncers with BufferedWriteSyncer.
|
||||
//
|
||||
// To set up a BufferedWriteSyncer, construct a WriteSyncer for your log
|
||||
// destination (*os.File is a valid WriteSyncer), wrap it with
|
||||
// BufferedWriteSyncer, and defer a Stop() call for when you no longer need the
|
||||
// object.
|
||||
//
|
||||
// func main() {
|
||||
// ws := ... // your log destination
|
||||
// bws := &zapcore.BufferedWriteSyncer{WS: ws}
|
||||
// defer bws.Stop()
|
||||
//
|
||||
// // ...
|
||||
// core := zapcore.NewCore(enc, bws, lvl)
|
||||
// logger := zap.New(core)
|
||||
//
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
// By default, a BufferedWriteSyncer will buffer up to 256 kilobytes of logs,
|
||||
// waiting at most 30 seconds between flushes.
|
||||
// You can customize these parameters by setting the Size or FlushInterval
|
||||
// fields.
|
||||
// For example, the following buffers up to 512 kB of logs before flushing them
|
||||
// to Stderr, with a maximum of one minute between each flush.
|
||||
//
|
||||
// ws := &BufferedWriteSyncer{
|
||||
// WS: os.Stderr,
|
||||
// Size: 512 * 1024, // 512 kB
|
||||
// FlushInterval: time.Minute,
|
||||
// }
|
||||
// defer ws.Stop()
|
||||
type BufferedWriteSyncer struct {
|
||||
// WS is the WriteSyncer around which BufferedWriteSyncer will buffer
|
||||
// writes.
|
||||
|
4
vendor/go.uber.org/zap/zapcore/clock.go
generated
vendored
4
vendor/go.uber.org/zap/zapcore/clock.go
generated
vendored
@ -20,9 +20,7 @@
|
||||
|
||||
package zapcore
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
import "time"
|
||||
|
||||
// DefaultClock is the default clock used by Zap in operations that require
|
||||
// time. This clock uses the system clock for all operations.
|
||||
|
6
vendor/go.uber.org/zap/zapcore/console_encoder.go
generated
vendored
6
vendor/go.uber.org/zap/zapcore/console_encoder.go
generated
vendored
@ -125,11 +125,7 @@ func (c consoleEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer,
|
||||
line.AppendString(ent.Stack)
|
||||
}
|
||||
|
||||
if c.LineEnding != "" {
|
||||
line.AppendString(c.LineEnding)
|
||||
} else {
|
||||
line.AppendString(DefaultLineEnding)
|
||||
}
|
||||
line.AppendString(c.LineEnding)
|
||||
return line, nil
|
||||
}
|
||||
|
||||
|
9
vendor/go.uber.org/zap/zapcore/core.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/core.go
generated
vendored
@ -69,6 +69,15 @@ type ioCore struct {
|
||||
out WriteSyncer
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*ioCore)(nil)
|
||||
_ leveledEnabler = (*ioCore)(nil)
|
||||
)
|
||||
|
||||
func (c *ioCore) Level() Level {
|
||||
return LevelOf(c.LevelEnabler)
|
||||
}
|
||||
|
||||
func (c *ioCore) With(fields []Field) Core {
|
||||
clone := c.clone()
|
||||
addFields(clone.enc, fields)
|
||||
|
30
vendor/go.uber.org/zap/zapcore/encoder.go
generated
vendored
30
vendor/go.uber.org/zap/zapcore/encoder.go
generated
vendored
@ -22,6 +22,7 @@ package zapcore
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap/buffer"
|
||||
@ -187,10 +188,13 @@ func (e *TimeEncoder) UnmarshalText(text []byte) error {
|
||||
|
||||
// UnmarshalYAML unmarshals YAML to a TimeEncoder.
|
||||
// If value is an object with a "layout" field, it will be unmarshaled to TimeEncoder with given layout.
|
||||
// timeEncoder:
|
||||
// layout: 06/01/02 03:04pm
|
||||
//
|
||||
// timeEncoder:
|
||||
// layout: 06/01/02 03:04pm
|
||||
//
|
||||
// If value is string, it uses UnmarshalText.
|
||||
// timeEncoder: iso8601
|
||||
//
|
||||
// timeEncoder: iso8601
|
||||
func (e *TimeEncoder) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var o struct {
|
||||
Layout string `json:"layout" yaml:"layout"`
|
||||
@ -312,14 +316,15 @@ func (e *NameEncoder) UnmarshalText(text []byte) error {
|
||||
type EncoderConfig struct {
|
||||
// Set the keys used for each log entry. If any key is empty, that portion
|
||||
// of the entry is omitted.
|
||||
MessageKey string `json:"messageKey" yaml:"messageKey"`
|
||||
LevelKey string `json:"levelKey" yaml:"levelKey"`
|
||||
TimeKey string `json:"timeKey" yaml:"timeKey"`
|
||||
NameKey string `json:"nameKey" yaml:"nameKey"`
|
||||
CallerKey string `json:"callerKey" yaml:"callerKey"`
|
||||
FunctionKey string `json:"functionKey" yaml:"functionKey"`
|
||||
StacktraceKey string `json:"stacktraceKey" yaml:"stacktraceKey"`
|
||||
LineEnding string `json:"lineEnding" yaml:"lineEnding"`
|
||||
MessageKey string `json:"messageKey" yaml:"messageKey"`
|
||||
LevelKey string `json:"levelKey" yaml:"levelKey"`
|
||||
TimeKey string `json:"timeKey" yaml:"timeKey"`
|
||||
NameKey string `json:"nameKey" yaml:"nameKey"`
|
||||
CallerKey string `json:"callerKey" yaml:"callerKey"`
|
||||
FunctionKey string `json:"functionKey" yaml:"functionKey"`
|
||||
StacktraceKey string `json:"stacktraceKey" yaml:"stacktraceKey"`
|
||||
SkipLineEnding bool `json:"skipLineEnding" yaml:"skipLineEnding"`
|
||||
LineEnding string `json:"lineEnding" yaml:"lineEnding"`
|
||||
// Configure the primitive representations of common complex types. For
|
||||
// example, some users may want all time.Times serialized as floating-point
|
||||
// seconds since epoch, while others may prefer ISO8601 strings.
|
||||
@ -330,6 +335,9 @@ type EncoderConfig struct {
|
||||
// Unlike the other primitive type encoders, EncodeName is optional. The
|
||||
// zero value falls back to FullNameEncoder.
|
||||
EncodeName NameEncoder `json:"nameEncoder" yaml:"nameEncoder"`
|
||||
// Configure the encoder for interface{} type objects.
|
||||
// If not provided, objects are encoded using json.Encoder
|
||||
NewReflectedEncoder func(io.Writer) ReflectedEncoder `json:"-" yaml:"-"`
|
||||
// Configures the field separator used by the console encoder. Defaults
|
||||
// to tab.
|
||||
ConsoleSeparator string `json:"consoleSeparator" yaml:"consoleSeparator"`
|
||||
|
71
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
71
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
@ -27,10 +27,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
"go.uber.org/zap/internal/exit"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -152,6 +151,27 @@ type Entry struct {
|
||||
Stack string
|
||||
}
|
||||
|
||||
// CheckWriteHook is a custom action that may be executed after an entry is
|
||||
// written.
|
||||
//
|
||||
// Register one on a CheckedEntry with the After method.
|
||||
//
|
||||
// if ce := logger.Check(...); ce != nil {
|
||||
// ce = ce.After(hook)
|
||||
// ce.Write(...)
|
||||
// }
|
||||
//
|
||||
// You can configure the hook for Fatal log statements at the logger level with
|
||||
// the zap.WithFatalHook option.
|
||||
type CheckWriteHook interface {
|
||||
// OnWrite is invoked with the CheckedEntry that was written and a list
|
||||
// of fields added with that entry.
|
||||
//
|
||||
// The list of fields DOES NOT include fields that were already added
|
||||
// to the logger with the With method.
|
||||
OnWrite(*CheckedEntry, []Field)
|
||||
}
|
||||
|
||||
// CheckWriteAction indicates what action to take after a log entry is
|
||||
// processed. Actions are ordered in increasing severity.
|
||||
type CheckWriteAction uint8
|
||||
@ -164,21 +184,36 @@ const (
|
||||
WriteThenGoexit
|
||||
// WriteThenPanic causes a panic after Write.
|
||||
WriteThenPanic
|
||||
// WriteThenFatal causes a fatal os.Exit after Write.
|
||||
// WriteThenFatal causes an os.Exit(1) after Write.
|
||||
WriteThenFatal
|
||||
)
|
||||
|
||||
// OnWrite implements the OnWrite method to keep CheckWriteAction compatible
|
||||
// with the new CheckWriteHook interface which deprecates CheckWriteAction.
|
||||
func (a CheckWriteAction) OnWrite(ce *CheckedEntry, _ []Field) {
|
||||
switch a {
|
||||
case WriteThenGoexit:
|
||||
runtime.Goexit()
|
||||
case WriteThenPanic:
|
||||
panic(ce.Message)
|
||||
case WriteThenFatal:
|
||||
exit.With(1)
|
||||
}
|
||||
}
|
||||
|
||||
var _ CheckWriteHook = CheckWriteAction(0)
|
||||
|
||||
// CheckedEntry is an Entry together with a collection of Cores that have
|
||||
// already agreed to log it.
|
||||
//
|
||||
// CheckedEntry references should be created by calling AddCore or Should on a
|
||||
// CheckedEntry references should be created by calling AddCore or After on a
|
||||
// nil *CheckedEntry. References are returned to a pool after Write, and MUST
|
||||
// NOT be retained after calling their Write method.
|
||||
type CheckedEntry struct {
|
||||
Entry
|
||||
ErrorOutput WriteSyncer
|
||||
dirty bool // best-effort detection of pool misuse
|
||||
should CheckWriteAction
|
||||
after CheckWriteHook
|
||||
cores []Core
|
||||
}
|
||||
|
||||
@ -186,7 +221,7 @@ func (ce *CheckedEntry) reset() {
|
||||
ce.Entry = Entry{}
|
||||
ce.ErrorOutput = nil
|
||||
ce.dirty = false
|
||||
ce.should = WriteThenNoop
|
||||
ce.after = nil
|
||||
for i := range ce.cores {
|
||||
// don't keep references to cores
|
||||
ce.cores[i] = nil
|
||||
@ -224,17 +259,11 @@ func (ce *CheckedEntry) Write(fields ...Field) {
|
||||
ce.ErrorOutput.Sync()
|
||||
}
|
||||
|
||||
should, msg := ce.should, ce.Message
|
||||
putCheckedEntry(ce)
|
||||
|
||||
switch should {
|
||||
case WriteThenPanic:
|
||||
panic(msg)
|
||||
case WriteThenFatal:
|
||||
exit.Exit()
|
||||
case WriteThenGoexit:
|
||||
runtime.Goexit()
|
||||
hook := ce.after
|
||||
if hook != nil {
|
||||
hook.OnWrite(ce, fields)
|
||||
}
|
||||
putCheckedEntry(ce)
|
||||
}
|
||||
|
||||
// AddCore adds a Core that has agreed to log this CheckedEntry. It's intended to be
|
||||
@ -252,11 +281,19 @@ func (ce *CheckedEntry) AddCore(ent Entry, core Core) *CheckedEntry {
|
||||
// Should sets this CheckedEntry's CheckWriteAction, which controls whether a
|
||||
// Core will panic or fatal after writing this log entry. Like AddCore, it's
|
||||
// safe to call on nil CheckedEntry references.
|
||||
// Deprecated: Use After(ent Entry, after CheckWriteHook) instead.
|
||||
func (ce *CheckedEntry) Should(ent Entry, should CheckWriteAction) *CheckedEntry {
|
||||
return ce.After(ent, should)
|
||||
}
|
||||
|
||||
// After sets this CheckEntry's CheckWriteHook, which will be called after this
|
||||
// log entry has been written. It's safe to call this on nil CheckedEntry
|
||||
// references.
|
||||
func (ce *CheckedEntry) After(ent Entry, hook CheckWriteHook) *CheckedEntry {
|
||||
if ce == nil {
|
||||
ce = getCheckedEntry()
|
||||
ce.Entry = ent
|
||||
}
|
||||
ce.should = should
|
||||
ce.after = hook
|
||||
return ce
|
||||
}
|
||||
|
14
vendor/go.uber.org/zap/zapcore/error.go
generated
vendored
14
vendor/go.uber.org/zap/zapcore/error.go
generated
vendored
@ -36,13 +36,13 @@ import (
|
||||
// causer (from github.com/pkg/errors), a ${key}Causes field is added with an
|
||||
// array of objects containing the errors this error was comprised of.
|
||||
//
|
||||
// {
|
||||
// "error": err.Error(),
|
||||
// "errorVerbose": fmt.Sprintf("%+v", err),
|
||||
// "errorCauses": [
|
||||
// ...
|
||||
// ],
|
||||
// }
|
||||
// {
|
||||
// "error": err.Error(),
|
||||
// "errorVerbose": fmt.Sprintf("%+v", err),
|
||||
// "errorCauses": [
|
||||
// ...
|
||||
// ],
|
||||
// }
|
||||
func encodeError(key string, err error, enc ObjectEncoder) (retErr error) {
|
||||
// Try to capture panics (from nil references or otherwise) when calling
|
||||
// the Error() method
|
||||
|
9
vendor/go.uber.org/zap/zapcore/hook.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/hook.go
generated
vendored
@ -27,6 +27,11 @@ type hooked struct {
|
||||
funcs []func(Entry) error
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*hooked)(nil)
|
||||
_ leveledEnabler = (*hooked)(nil)
|
||||
)
|
||||
|
||||
// RegisterHooks wraps a Core and runs a collection of user-defined callback
|
||||
// hooks each time a message is logged. Execution of the callbacks is blocking.
|
||||
//
|
||||
@ -40,6 +45,10 @@ func RegisterHooks(core Core, hooks ...func(Entry) error) Core {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *hooked) Level() Level {
|
||||
return LevelOf(h.Core)
|
||||
}
|
||||
|
||||
func (h *hooked) Check(ent Entry, ce *CheckedEntry) *CheckedEntry {
|
||||
// Let the wrapped Core decide whether to log this message or not. This
|
||||
// also gives the downstream a chance to register itself directly with the
|
||||
|
9
vendor/go.uber.org/zap/zapcore/increase_level.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/increase_level.go
generated
vendored
@ -27,6 +27,11 @@ type levelFilterCore struct {
|
||||
level LevelEnabler
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*levelFilterCore)(nil)
|
||||
_ leveledEnabler = (*levelFilterCore)(nil)
|
||||
)
|
||||
|
||||
// NewIncreaseLevelCore creates a core that can be used to increase the level of
|
||||
// an existing Core. It cannot be used to decrease the logging level, as it acts
|
||||
// as a filter before calling the underlying core. If level decreases the log level,
|
||||
@ -45,6 +50,10 @@ func (c *levelFilterCore) Enabled(lvl Level) bool {
|
||||
return c.level.Enabled(lvl)
|
||||
}
|
||||
|
||||
func (c *levelFilterCore) Level() Level {
|
||||
return LevelOf(c.level)
|
||||
}
|
||||
|
||||
func (c *levelFilterCore) With(fields []Field) Core {
|
||||
return &levelFilterCore{c.core.With(fields), c.level}
|
||||
}
|
||||
|
96
vendor/go.uber.org/zap/zapcore/json_encoder.go
generated
vendored
96
vendor/go.uber.org/zap/zapcore/json_encoder.go
generated
vendored
@ -22,7 +22,6 @@ package zapcore
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
@ -64,7 +63,7 @@ type jsonEncoder struct {
|
||||
|
||||
// for encoding generic values by reflection
|
||||
reflectBuf *buffer.Buffer
|
||||
reflectEnc *json.Encoder
|
||||
reflectEnc ReflectedEncoder
|
||||
}
|
||||
|
||||
// NewJSONEncoder creates a fast, low-allocation JSON encoder. The encoder
|
||||
@ -72,7 +71,9 @@ type jsonEncoder struct {
|
||||
//
|
||||
// Note that the encoder doesn't deduplicate keys, so it's possible to produce
|
||||
// a message like
|
||||
// {"foo":"bar","foo":"baz"}
|
||||
//
|
||||
// {"foo":"bar","foo":"baz"}
|
||||
//
|
||||
// This is permitted by the JSON specification, but not encouraged. Many
|
||||
// libraries will ignore duplicate key-value pairs (typically keeping the last
|
||||
// pair) when unmarshaling, but users should attempt to avoid adding duplicate
|
||||
@ -82,6 +83,17 @@ func NewJSONEncoder(cfg EncoderConfig) Encoder {
|
||||
}
|
||||
|
||||
func newJSONEncoder(cfg EncoderConfig, spaced bool) *jsonEncoder {
|
||||
if cfg.SkipLineEnding {
|
||||
cfg.LineEnding = ""
|
||||
} else if cfg.LineEnding == "" {
|
||||
cfg.LineEnding = DefaultLineEnding
|
||||
}
|
||||
|
||||
// If no EncoderConfig.NewReflectedEncoder is provided by the user, then use default
|
||||
if cfg.NewReflectedEncoder == nil {
|
||||
cfg.NewReflectedEncoder = defaultReflectedEncoder
|
||||
}
|
||||
|
||||
return &jsonEncoder{
|
||||
EncoderConfig: &cfg,
|
||||
buf: bufferpool.Get(),
|
||||
@ -118,6 +130,11 @@ func (enc *jsonEncoder) AddComplex128(key string, val complex128) {
|
||||
enc.AppendComplex128(val)
|
||||
}
|
||||
|
||||
func (enc *jsonEncoder) AddComplex64(key string, val complex64) {
|
||||
enc.addKey(key)
|
||||
enc.AppendComplex64(val)
|
||||
}
|
||||
|
||||
func (enc *jsonEncoder) AddDuration(key string, val time.Duration) {
|
||||
enc.addKey(key)
|
||||
enc.AppendDuration(val)
|
||||
@ -141,10 +158,7 @@ func (enc *jsonEncoder) AddInt64(key string, val int64) {
|
||||
func (enc *jsonEncoder) resetReflectBuf() {
|
||||
if enc.reflectBuf == nil {
|
||||
enc.reflectBuf = bufferpool.Get()
|
||||
enc.reflectEnc = json.NewEncoder(enc.reflectBuf)
|
||||
|
||||
// For consistency with our custom JSON encoder.
|
||||
enc.reflectEnc.SetEscapeHTML(false)
|
||||
enc.reflectEnc = enc.NewReflectedEncoder(enc.reflectBuf)
|
||||
} else {
|
||||
enc.reflectBuf.Reset()
|
||||
}
|
||||
@ -206,10 +220,16 @@ func (enc *jsonEncoder) AppendArray(arr ArrayMarshaler) error {
|
||||
}
|
||||
|
||||
func (enc *jsonEncoder) AppendObject(obj ObjectMarshaler) error {
|
||||
// Close ONLY new openNamespaces that are created during
|
||||
// AppendObject().
|
||||
old := enc.openNamespaces
|
||||
enc.openNamespaces = 0
|
||||
enc.addElementSeparator()
|
||||
enc.buf.AppendByte('{')
|
||||
err := obj.MarshalLogObject(enc)
|
||||
enc.buf.AppendByte('}')
|
||||
enc.closeOpenNamespaces()
|
||||
enc.openNamespaces = old
|
||||
return err
|
||||
}
|
||||
|
||||
@ -225,20 +245,23 @@ func (enc *jsonEncoder) AppendByteString(val []byte) {
|
||||
enc.buf.AppendByte('"')
|
||||
}
|
||||
|
||||
func (enc *jsonEncoder) AppendComplex128(val complex128) {
|
||||
// appendComplex appends the encoded form of the provided complex128 value.
|
||||
// precision specifies the encoding precision for the real and imaginary
|
||||
// components of the complex number.
|
||||
func (enc *jsonEncoder) appendComplex(val complex128, precision int) {
|
||||
enc.addElementSeparator()
|
||||
// Cast to a platform-independent, fixed-size type.
|
||||
r, i := float64(real(val)), float64(imag(val))
|
||||
enc.buf.AppendByte('"')
|
||||
// Because we're always in a quoted string, we can use strconv without
|
||||
// special-casing NaN and +/-Inf.
|
||||
enc.buf.AppendFloat(r, 64)
|
||||
enc.buf.AppendFloat(r, precision)
|
||||
// If imaginary part is less than 0, minus (-) sign is added by default
|
||||
// by AppendFloat.
|
||||
if i >= 0 {
|
||||
enc.buf.AppendByte('+')
|
||||
}
|
||||
enc.buf.AppendFloat(i, 64)
|
||||
enc.buf.AppendFloat(i, precision)
|
||||
enc.buf.AppendByte('i')
|
||||
enc.buf.AppendByte('"')
|
||||
}
|
||||
@ -301,28 +324,28 @@ func (enc *jsonEncoder) AppendUint64(val uint64) {
|
||||
enc.buf.AppendUint(val)
|
||||
}
|
||||
|
||||
func (enc *jsonEncoder) AddComplex64(k string, v complex64) { enc.AddComplex128(k, complex128(v)) }
|
||||
func (enc *jsonEncoder) AddInt(k string, v int) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddInt32(k string, v int32) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddInt16(k string, v int16) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddInt8(k string, v int8) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddUint(k string, v uint) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUint32(k string, v uint32) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUint16(k string, v uint16) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUint8(k string, v uint8) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUintptr(k string, v uintptr) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendComplex64(v complex64) { enc.AppendComplex128(complex128(v)) }
|
||||
func (enc *jsonEncoder) AppendFloat64(v float64) { enc.appendFloat(v, 64) }
|
||||
func (enc *jsonEncoder) AppendFloat32(v float32) { enc.appendFloat(float64(v), 32) }
|
||||
func (enc *jsonEncoder) AppendInt(v int) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendInt32(v int32) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendInt16(v int16) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendInt8(v int8) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint(v uint) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint32(v uint32) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint16(v uint16) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint8(v uint8) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUintptr(v uintptr) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AddInt(k string, v int) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddInt32(k string, v int32) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddInt16(k string, v int16) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddInt8(k string, v int8) { enc.AddInt64(k, int64(v)) }
|
||||
func (enc *jsonEncoder) AddUint(k string, v uint) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUint32(k string, v uint32) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUint16(k string, v uint16) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUint8(k string, v uint8) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AddUintptr(k string, v uintptr) { enc.AddUint64(k, uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendComplex64(v complex64) { enc.appendComplex(complex128(v), 32) }
|
||||
func (enc *jsonEncoder) AppendComplex128(v complex128) { enc.appendComplex(complex128(v), 64) }
|
||||
func (enc *jsonEncoder) AppendFloat64(v float64) { enc.appendFloat(v, 64) }
|
||||
func (enc *jsonEncoder) AppendFloat32(v float32) { enc.appendFloat(float64(v), 32) }
|
||||
func (enc *jsonEncoder) AppendInt(v int) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendInt32(v int32) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendInt16(v int16) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendInt8(v int8) { enc.AppendInt64(int64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint(v uint) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint32(v uint32) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint16(v uint16) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUint8(v uint8) { enc.AppendUint64(uint64(v)) }
|
||||
func (enc *jsonEncoder) AppendUintptr(v uintptr) { enc.AppendUint64(uint64(v)) }
|
||||
|
||||
func (enc *jsonEncoder) Clone() Encoder {
|
||||
clone := enc.clone()
|
||||
@ -343,7 +366,7 @@ func (enc *jsonEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer,
|
||||
final := enc.clone()
|
||||
final.buf.AppendByte('{')
|
||||
|
||||
if final.LevelKey != "" {
|
||||
if final.LevelKey != "" && final.EncodeLevel != nil {
|
||||
final.addKey(final.LevelKey)
|
||||
cur := final.buf.Len()
|
||||
final.EncodeLevel(ent.Level, final)
|
||||
@ -404,11 +427,7 @@ func (enc *jsonEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer,
|
||||
final.AddString(final.StacktraceKey, ent.Stack)
|
||||
}
|
||||
final.buf.AppendByte('}')
|
||||
if final.LineEnding != "" {
|
||||
final.buf.AppendString(final.LineEnding)
|
||||
} else {
|
||||
final.buf.AppendString(DefaultLineEnding)
|
||||
}
|
||||
final.buf.AppendString(final.LineEnding)
|
||||
|
||||
ret := final.buf
|
||||
putJSONEncoder(final)
|
||||
@ -423,6 +442,7 @@ func (enc *jsonEncoder) closeOpenNamespaces() {
|
||||
for i := 0; i < enc.openNamespaces; i++ {
|
||||
enc.buf.AppendByte('}')
|
||||
}
|
||||
enc.openNamespaces = 0
|
||||
}
|
||||
|
||||
func (enc *jsonEncoder) addKey(key string) {
|
||||
|
54
vendor/go.uber.org/zap/zapcore/level.go
generated
vendored
54
vendor/go.uber.org/zap/zapcore/level.go
generated
vendored
@ -53,8 +53,62 @@ const (
|
||||
|
||||
_minLevel = DebugLevel
|
||||
_maxLevel = FatalLevel
|
||||
|
||||
// InvalidLevel is an invalid value for Level.
|
||||
//
|
||||
// Core implementations may panic if they see messages of this level.
|
||||
InvalidLevel = _maxLevel + 1
|
||||
)
|
||||
|
||||
// ParseLevel parses a level based on the lower-case or all-caps ASCII
|
||||
// representation of the log level. If the provided ASCII representation is
|
||||
// invalid an error is returned.
|
||||
//
|
||||
// This is particularly useful when dealing with text input to configure log
|
||||
// levels.
|
||||
func ParseLevel(text string) (Level, error) {
|
||||
var level Level
|
||||
err := level.UnmarshalText([]byte(text))
|
||||
return level, err
|
||||
}
|
||||
|
||||
type leveledEnabler interface {
|
||||
LevelEnabler
|
||||
|
||||
Level() Level
|
||||
}
|
||||
|
||||
// LevelOf reports the minimum enabled log level for the given LevelEnabler
|
||||
// from Zap's supported log levels, or [InvalidLevel] if none of them are
|
||||
// enabled.
|
||||
//
|
||||
// A LevelEnabler may implement a 'Level() Level' method to override the
|
||||
// behavior of this function.
|
||||
//
|
||||
// func (c *core) Level() Level {
|
||||
// return c.currentLevel
|
||||
// }
|
||||
//
|
||||
// It is recommended that [Core] implementations that wrap other cores use
|
||||
// LevelOf to retrieve the level of the wrapped core. For example,
|
||||
//
|
||||
// func (c *coreWrapper) Level() Level {
|
||||
// return zapcore.LevelOf(c.wrappedCore)
|
||||
// }
|
||||
func LevelOf(enab LevelEnabler) Level {
|
||||
if lvler, ok := enab.(leveledEnabler); ok {
|
||||
return lvler.Level()
|
||||
}
|
||||
|
||||
for lvl := _minLevel; lvl <= _maxLevel; lvl++ {
|
||||
if enab.Enabled(lvl) {
|
||||
return lvl
|
||||
}
|
||||
}
|
||||
|
||||
return InvalidLevel
|
||||
}
|
||||
|
||||
// String returns a lower-case ASCII representation of the log level.
|
||||
func (l Level) String() string {
|
||||
switch l {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2019 Uber Technologies, Inc.
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@ -18,9 +18,24 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
// See #682 for more information.
|
||||
// +build !go1.12
|
||||
package zapcore
|
||||
|
||||
package zap
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
const _stdLogDefaultDepth = 2
|
||||
// ReflectedEncoder serializes log fields that can't be serialized with Zap's
|
||||
// JSON encoder. These have the ReflectType field type.
|
||||
// Use EncoderConfig.NewReflectedEncoder to set this.
|
||||
type ReflectedEncoder interface {
|
||||
// Encode encodes and writes to the underlying data stream.
|
||||
Encode(interface{}) error
|
||||
}
|
||||
|
||||
func defaultReflectedEncoder(w io.Writer) ReflectedEncoder {
|
||||
enc := json.NewEncoder(w)
|
||||
// For consistency with our custom JSON encoder.
|
||||
enc.SetEscapeHTML(false)
|
||||
return enc
|
||||
}
|
38
vendor/go.uber.org/zap/zapcore/sampler.go
generated
vendored
38
vendor/go.uber.org/zap/zapcore/sampler.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
// Copyright (c) 2016-2022 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@ -113,12 +113,12 @@ func nopSamplingHook(Entry, SamplingDecision) {}
|
||||
// This hook may be used to get visibility into the performance of the sampler.
|
||||
// For example, use it to track metrics of dropped versus sampled logs.
|
||||
//
|
||||
// var dropped atomic.Int64
|
||||
// zapcore.SamplerHook(func(ent zapcore.Entry, dec zapcore.SamplingDecision) {
|
||||
// if dec&zapcore.LogDropped > 0 {
|
||||
// dropped.Inc()
|
||||
// }
|
||||
// })
|
||||
// var dropped atomic.Int64
|
||||
// zapcore.SamplerHook(func(ent zapcore.Entry, dec zapcore.SamplingDecision) {
|
||||
// if dec&zapcore.LogDropped > 0 {
|
||||
// dropped.Inc()
|
||||
// }
|
||||
// })
|
||||
func SamplerHook(hook func(entry Entry, dec SamplingDecision)) SamplerOption {
|
||||
return optionFunc(func(s *sampler) {
|
||||
s.hook = hook
|
||||
@ -133,10 +133,21 @@ func SamplerHook(hook func(entry Entry, dec SamplingDecision)) SamplerOption {
|
||||
// each tick. If more Entries with the same level and message are seen during
|
||||
// the same interval, every Mth message is logged and the rest are dropped.
|
||||
//
|
||||
// For example,
|
||||
//
|
||||
// core = NewSamplerWithOptions(core, time.Second, 10, 5)
|
||||
//
|
||||
// This will log the first 10 log entries with the same level and message
|
||||
// in a one second interval as-is. Following that, it will allow through
|
||||
// every 5th log entry with the same level and message in that interval.
|
||||
//
|
||||
// If thereafter is zero, the Core will drop all log entries after the first N
|
||||
// in that interval.
|
||||
//
|
||||
// Sampler can be configured to report sampling decisions with the SamplerHook
|
||||
// option.
|
||||
//
|
||||
// Keep in mind that zap's sampling implementation is optimized for speed over
|
||||
// Keep in mind that Zap's sampling implementation is optimized for speed over
|
||||
// absolute precision; under load, each tick may be slightly over- or
|
||||
// under-sampled.
|
||||
func NewSamplerWithOptions(core Core, tick time.Duration, first, thereafter int, opts ...SamplerOption) Core {
|
||||
@ -164,6 +175,11 @@ type sampler struct {
|
||||
hook func(Entry, SamplingDecision)
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*sampler)(nil)
|
||||
_ leveledEnabler = (*sampler)(nil)
|
||||
)
|
||||
|
||||
// NewSampler creates a Core that samples incoming entries, which
|
||||
// caps the CPU and I/O load of logging while attempting to preserve a
|
||||
// representative subset of your logs.
|
||||
@ -181,6 +197,10 @@ func NewSampler(core Core, tick time.Duration, first, thereafter int) Core {
|
||||
return NewSamplerWithOptions(core, tick, first, thereafter)
|
||||
}
|
||||
|
||||
func (s *sampler) Level() Level {
|
||||
return LevelOf(s.Core)
|
||||
}
|
||||
|
||||
func (s *sampler) With(fields []Field) Core {
|
||||
return &sampler{
|
||||
Core: s.Core.With(fields),
|
||||
@ -200,7 +220,7 @@ func (s *sampler) Check(ent Entry, ce *CheckedEntry) *CheckedEntry {
|
||||
if ent.Level >= _minLevel && ent.Level <= _maxLevel {
|
||||
counter := s.counts.get(ent.Level, ent.Message)
|
||||
n := counter.IncCheckReset(ent.Time, s.tick)
|
||||
if n > s.first && (n-s.first)%s.thereafter != 0 {
|
||||
if n > s.first && (s.thereafter == 0 || (n-s.first)%s.thereafter != 0) {
|
||||
s.hook(ent, LogDropped)
|
||||
return ce
|
||||
}
|
||||
|
17
vendor/go.uber.org/zap/zapcore/tee.go
generated
vendored
17
vendor/go.uber.org/zap/zapcore/tee.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
// Copyright (c) 2016-2022 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@ -24,6 +24,11 @@ import "go.uber.org/multierr"
|
||||
|
||||
type multiCore []Core
|
||||
|
||||
var (
|
||||
_ leveledEnabler = multiCore(nil)
|
||||
_ Core = multiCore(nil)
|
||||
)
|
||||
|
||||
// NewTee creates a Core that duplicates log entries into two or more
|
||||
// underlying Cores.
|
||||
//
|
||||
@ -48,6 +53,16 @@ func (mc multiCore) With(fields []Field) Core {
|
||||
return clone
|
||||
}
|
||||
|
||||
func (mc multiCore) Level() Level {
|
||||
minLvl := _maxLevel // mc is never empty
|
||||
for i := range mc {
|
||||
if lvl := LevelOf(mc[i]); lvl < minLvl {
|
||||
minLvl = lvl
|
||||
}
|
||||
}
|
||||
return minLvl
|
||||
}
|
||||
|
||||
func (mc multiCore) Enabled(lvl Level) bool {
|
||||
for i := range mc {
|
||||
if mc[i].Enabled(lvl) {
|
||||
|
2
vendor/google.golang.org/protobuf/AUTHORS → vendor/golang.org/x/sync/AUTHORS
generated
vendored
2
vendor/google.golang.org/protobuf/AUTHORS → vendor/golang.org/x/sync/AUTHORS
generated
vendored
@ -1,3 +1,3 @@
|
||||
# This source code refers to The Go Authors for copyright purposes.
|
||||
# The master list of authors is in the main Go distribution,
|
||||
# visible at https://tip.golang.org/AUTHORS.
|
||||
# visible at http://tip.golang.org/AUTHORS.
|
@ -1,3 +1,3 @@
|
||||
# This source code was written by the Go contributors.
|
||||
# The master list of contributors is in the main Go distribution,
|
||||
# visible at https://tip.golang.org/CONTRIBUTORS.
|
||||
# visible at http://tip.golang.org/CONTRIBUTORS.
|
27
vendor/golang.org/x/sync/LICENSE
generated
vendored
Normal file
27
vendor/golang.org/x/sync/LICENSE
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright (c) 2009 The Go Authors. 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 Google 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.
|
22
vendor/golang.org/x/sync/PATENTS
generated
vendored
Normal file
22
vendor/golang.org/x/sync/PATENTS
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
Additional IP Rights Grant (Patents)
|
||||
|
||||
"This implementation" means the copyrightable works distributed by
|
||||
Google as part of the Go project.
|
||||
|
||||
Google hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||
no-charge, royalty-free, irrevocable (except as stated in this section)
|
||||
patent license to make, have made, use, offer to sell, sell, import,
|
||||
transfer and otherwise run, modify and propagate the contents of this
|
||||
implementation of Go, where such license applies only to those patent
|
||||
claims, both currently owned or controlled by Google and acquired in
|
||||
the future, licensable by Google that are necessarily infringed by this
|
||||
implementation of Go. This grant does not include claims that would be
|
||||
infringed only as a consequence of further modification of this
|
||||
implementation. If you or your agent or exclusive licensee institute or
|
||||
order or agree to the institution of patent litigation against any
|
||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that this implementation of Go or any code incorporated within this
|
||||
implementation of Go constitutes direct or contributory patent
|
||||
infringement, or inducement of patent infringement, then any patent
|
||||
rights granted to you under this License for this implementation of Go
|
||||
shall terminate as of the date such litigation is filed.
|
136
vendor/golang.org/x/sync/semaphore/semaphore.go
generated
vendored
Normal file
136
vendor/golang.org/x/sync/semaphore/semaphore.go
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package semaphore provides a weighted semaphore implementation.
|
||||
package semaphore // import "golang.org/x/sync/semaphore"
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type waiter struct {
|
||||
n int64
|
||||
ready chan<- struct{} // Closed when semaphore acquired.
|
||||
}
|
||||
|
||||
// NewWeighted creates a new weighted semaphore with the given
|
||||
// maximum combined weight for concurrent access.
|
||||
func NewWeighted(n int64) *Weighted {
|
||||
w := &Weighted{size: n}
|
||||
return w
|
||||
}
|
||||
|
||||
// Weighted provides a way to bound concurrent access to a resource.
|
||||
// The callers can request access with a given weight.
|
||||
type Weighted struct {
|
||||
size int64
|
||||
cur int64
|
||||
mu sync.Mutex
|
||||
waiters list.List
|
||||
}
|
||||
|
||||
// Acquire acquires the semaphore with a weight of n, blocking until resources
|
||||
// are available or ctx is done. On success, returns nil. On failure, returns
|
||||
// ctx.Err() and leaves the semaphore unchanged.
|
||||
//
|
||||
// If ctx is already done, Acquire may still succeed without blocking.
|
||||
func (s *Weighted) Acquire(ctx context.Context, n int64) error {
|
||||
s.mu.Lock()
|
||||
if s.size-s.cur >= n && s.waiters.Len() == 0 {
|
||||
s.cur += n
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
if n > s.size {
|
||||
// Don't make other Acquire calls block on one that's doomed to fail.
|
||||
s.mu.Unlock()
|
||||
<-ctx.Done()
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
ready := make(chan struct{})
|
||||
w := waiter{n: n, ready: ready}
|
||||
elem := s.waiters.PushBack(w)
|
||||
s.mu.Unlock()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
err := ctx.Err()
|
||||
s.mu.Lock()
|
||||
select {
|
||||
case <-ready:
|
||||
// Acquired the semaphore after we were canceled. Rather than trying to
|
||||
// fix up the queue, just pretend we didn't notice the cancelation.
|
||||
err = nil
|
||||
default:
|
||||
isFront := s.waiters.Front() == elem
|
||||
s.waiters.Remove(elem)
|
||||
// If we're at the front and there're extra tokens left, notify other waiters.
|
||||
if isFront && s.size > s.cur {
|
||||
s.notifyWaiters()
|
||||
}
|
||||
}
|
||||
s.mu.Unlock()
|
||||
return err
|
||||
|
||||
case <-ready:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// TryAcquire acquires the semaphore with a weight of n without blocking.
|
||||
// On success, returns true. On failure, returns false and leaves the semaphore unchanged.
|
||||
func (s *Weighted) TryAcquire(n int64) bool {
|
||||
s.mu.Lock()
|
||||
success := s.size-s.cur >= n && s.waiters.Len() == 0
|
||||
if success {
|
||||
s.cur += n
|
||||
}
|
||||
s.mu.Unlock()
|
||||
return success
|
||||
}
|
||||
|
||||
// Release releases the semaphore with a weight of n.
|
||||
func (s *Weighted) Release(n int64) {
|
||||
s.mu.Lock()
|
||||
s.cur -= n
|
||||
if s.cur < 0 {
|
||||
s.mu.Unlock()
|
||||
panic("semaphore: released more than held")
|
||||
}
|
||||
s.notifyWaiters()
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *Weighted) notifyWaiters() {
|
||||
for {
|
||||
next := s.waiters.Front()
|
||||
if next == nil {
|
||||
break // No more waiters blocked.
|
||||
}
|
||||
|
||||
w := next.Value.(waiter)
|
||||
if s.size-s.cur < w.n {
|
||||
// Not enough tokens for the next waiter. We could keep going (to try to
|
||||
// find a waiter with a smaller request), but under load that could cause
|
||||
// starvation for large requests; instead, we leave all remaining waiters
|
||||
// blocked.
|
||||
//
|
||||
// Consider a semaphore used as a read-write lock, with N tokens, N
|
||||
// readers, and one writer. Each reader can Acquire(1) to obtain a read
|
||||
// lock. The writer can Acquire(N) to obtain a write lock, excluding all
|
||||
// of the readers. If we allow the readers to jump ahead in the queue,
|
||||
// the writer will starve — there is always one token available for every
|
||||
// reader.
|
||||
break
|
||||
}
|
||||
|
||||
s.cur += w.n
|
||||
s.waiters.Remove(next)
|
||||
close(w.ready)
|
||||
}
|
||||
}
|
116
vendor/google.golang.org/protobuf/encoding/prototext/decode.go
generated
vendored
116
vendor/google.golang.org/protobuf/encoding/prototext/decode.go
generated
vendored
@ -17,7 +17,7 @@ import (
|
||||
"google.golang.org/protobuf/internal/set"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
)
|
||||
|
||||
@ -103,7 +103,7 @@ func (d decoder) syntaxError(pos int, f string, x ...interface{}) error {
|
||||
}
|
||||
|
||||
// unmarshalMessage unmarshals into the given protoreflect.Message.
|
||||
func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
|
||||
func (d decoder) unmarshalMessage(m protoreflect.Message, checkDelims bool) error {
|
||||
messageDesc := m.Descriptor()
|
||||
if !flags.ProtoLegacy && messageset.IsMessageSet(messageDesc) {
|
||||
return errors.New("no support for proto1 MessageSets")
|
||||
@ -150,24 +150,24 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
|
||||
}
|
||||
|
||||
// Resolve the field descriptor.
|
||||
var name pref.Name
|
||||
var fd pref.FieldDescriptor
|
||||
var xt pref.ExtensionType
|
||||
var name protoreflect.Name
|
||||
var fd protoreflect.FieldDescriptor
|
||||
var xt protoreflect.ExtensionType
|
||||
var xtErr error
|
||||
var isFieldNumberName bool
|
||||
|
||||
switch tok.NameKind() {
|
||||
case text.IdentName:
|
||||
name = pref.Name(tok.IdentName())
|
||||
name = protoreflect.Name(tok.IdentName())
|
||||
fd = fieldDescs.ByTextName(string(name))
|
||||
|
||||
case text.TypeName:
|
||||
// Handle extensions only. This code path is not for Any.
|
||||
xt, xtErr = d.opts.Resolver.FindExtensionByName(pref.FullName(tok.TypeName()))
|
||||
xt, xtErr = d.opts.Resolver.FindExtensionByName(protoreflect.FullName(tok.TypeName()))
|
||||
|
||||
case text.FieldNumber:
|
||||
isFieldNumberName = true
|
||||
num := pref.FieldNumber(tok.FieldNumber())
|
||||
num := protoreflect.FieldNumber(tok.FieldNumber())
|
||||
if !num.IsValid() {
|
||||
return d.newError(tok.Pos(), "invalid field number: %d", num)
|
||||
}
|
||||
@ -215,7 +215,7 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
|
||||
switch {
|
||||
case fd.IsList():
|
||||
kind := fd.Kind()
|
||||
if kind != pref.MessageKind && kind != pref.GroupKind && !tok.HasSeparator() {
|
||||
if kind != protoreflect.MessageKind && kind != protoreflect.GroupKind && !tok.HasSeparator() {
|
||||
return d.syntaxError(tok.Pos(), "missing field separator :")
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
|
||||
|
||||
default:
|
||||
kind := fd.Kind()
|
||||
if kind != pref.MessageKind && kind != pref.GroupKind && !tok.HasSeparator() {
|
||||
if kind != protoreflect.MessageKind && kind != protoreflect.GroupKind && !tok.HasSeparator() {
|
||||
return d.syntaxError(tok.Pos(), "missing field separator :")
|
||||
}
|
||||
|
||||
@ -262,11 +262,11 @@ func (d decoder) unmarshalMessage(m pref.Message, checkDelims bool) error {
|
||||
|
||||
// unmarshalSingular unmarshals a non-repeated field value specified by the
|
||||
// given FieldDescriptor.
|
||||
func (d decoder) unmarshalSingular(fd pref.FieldDescriptor, m pref.Message) error {
|
||||
var val pref.Value
|
||||
func (d decoder) unmarshalSingular(fd protoreflect.FieldDescriptor, m protoreflect.Message) error {
|
||||
var val protoreflect.Value
|
||||
var err error
|
||||
switch fd.Kind() {
|
||||
case pref.MessageKind, pref.GroupKind:
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
val = m.NewField(fd)
|
||||
err = d.unmarshalMessage(val.Message(), true)
|
||||
default:
|
||||
@ -280,94 +280,94 @@ func (d decoder) unmarshalSingular(fd pref.FieldDescriptor, m pref.Message) erro
|
||||
|
||||
// unmarshalScalar unmarshals a scalar/enum protoreflect.Value specified by the
|
||||
// given FieldDescriptor.
|
||||
func (d decoder) unmarshalScalar(fd pref.FieldDescriptor) (pref.Value, error) {
|
||||
func (d decoder) unmarshalScalar(fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
|
||||
tok, err := d.Read()
|
||||
if err != nil {
|
||||
return pref.Value{}, err
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
|
||||
if tok.Kind() != text.Scalar {
|
||||
return pref.Value{}, d.unexpectedTokenError(tok)
|
||||
return protoreflect.Value{}, d.unexpectedTokenError(tok)
|
||||
}
|
||||
|
||||
kind := fd.Kind()
|
||||
switch kind {
|
||||
case pref.BoolKind:
|
||||
case protoreflect.BoolKind:
|
||||
if b, ok := tok.Bool(); ok {
|
||||
return pref.ValueOfBool(b), nil
|
||||
return protoreflect.ValueOfBool(b), nil
|
||||
}
|
||||
|
||||
case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
|
||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||
if n, ok := tok.Int32(); ok {
|
||||
return pref.ValueOfInt32(n), nil
|
||||
return protoreflect.ValueOfInt32(n), nil
|
||||
}
|
||||
|
||||
case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
|
||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
||||
if n, ok := tok.Int64(); ok {
|
||||
return pref.ValueOfInt64(n), nil
|
||||
return protoreflect.ValueOfInt64(n), nil
|
||||
}
|
||||
|
||||
case pref.Uint32Kind, pref.Fixed32Kind:
|
||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
||||
if n, ok := tok.Uint32(); ok {
|
||||
return pref.ValueOfUint32(n), nil
|
||||
return protoreflect.ValueOfUint32(n), nil
|
||||
}
|
||||
|
||||
case pref.Uint64Kind, pref.Fixed64Kind:
|
||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
||||
if n, ok := tok.Uint64(); ok {
|
||||
return pref.ValueOfUint64(n), nil
|
||||
return protoreflect.ValueOfUint64(n), nil
|
||||
}
|
||||
|
||||
case pref.FloatKind:
|
||||
case protoreflect.FloatKind:
|
||||
if n, ok := tok.Float32(); ok {
|
||||
return pref.ValueOfFloat32(n), nil
|
||||
return protoreflect.ValueOfFloat32(n), nil
|
||||
}
|
||||
|
||||
case pref.DoubleKind:
|
||||
case protoreflect.DoubleKind:
|
||||
if n, ok := tok.Float64(); ok {
|
||||
return pref.ValueOfFloat64(n), nil
|
||||
return protoreflect.ValueOfFloat64(n), nil
|
||||
}
|
||||
|
||||
case pref.StringKind:
|
||||
case protoreflect.StringKind:
|
||||
if s, ok := tok.String(); ok {
|
||||
if strs.EnforceUTF8(fd) && !utf8.ValidString(s) {
|
||||
return pref.Value{}, d.newError(tok.Pos(), "contains invalid UTF-8")
|
||||
return protoreflect.Value{}, d.newError(tok.Pos(), "contains invalid UTF-8")
|
||||
}
|
||||
return pref.ValueOfString(s), nil
|
||||
return protoreflect.ValueOfString(s), nil
|
||||
}
|
||||
|
||||
case pref.BytesKind:
|
||||
case protoreflect.BytesKind:
|
||||
if b, ok := tok.String(); ok {
|
||||
return pref.ValueOfBytes([]byte(b)), nil
|
||||
return protoreflect.ValueOfBytes([]byte(b)), nil
|
||||
}
|
||||
|
||||
case pref.EnumKind:
|
||||
case protoreflect.EnumKind:
|
||||
if lit, ok := tok.Enum(); ok {
|
||||
// Lookup EnumNumber based on name.
|
||||
if enumVal := fd.Enum().Values().ByName(pref.Name(lit)); enumVal != nil {
|
||||
return pref.ValueOfEnum(enumVal.Number()), nil
|
||||
if enumVal := fd.Enum().Values().ByName(protoreflect.Name(lit)); enumVal != nil {
|
||||
return protoreflect.ValueOfEnum(enumVal.Number()), nil
|
||||
}
|
||||
}
|
||||
if num, ok := tok.Int32(); ok {
|
||||
return pref.ValueOfEnum(pref.EnumNumber(num)), nil
|
||||
return protoreflect.ValueOfEnum(protoreflect.EnumNumber(num)), nil
|
||||
}
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid scalar kind %v", kind))
|
||||
}
|
||||
|
||||
return pref.Value{}, d.newError(tok.Pos(), "invalid value for %v type: %v", kind, tok.RawString())
|
||||
return protoreflect.Value{}, d.newError(tok.Pos(), "invalid value for %v type: %v", kind, tok.RawString())
|
||||
}
|
||||
|
||||
// unmarshalList unmarshals into given protoreflect.List. A list value can
|
||||
// either be in [] syntax or simply just a single scalar/message value.
|
||||
func (d decoder) unmarshalList(fd pref.FieldDescriptor, list pref.List) error {
|
||||
func (d decoder) unmarshalList(fd protoreflect.FieldDescriptor, list protoreflect.List) error {
|
||||
tok, err := d.Peek()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch fd.Kind() {
|
||||
case pref.MessageKind, pref.GroupKind:
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
switch tok.Kind() {
|
||||
case text.ListOpen:
|
||||
d.Read()
|
||||
@ -441,22 +441,22 @@ func (d decoder) unmarshalList(fd pref.FieldDescriptor, list pref.List) error {
|
||||
|
||||
// unmarshalMap unmarshals into given protoreflect.Map. A map value is a
|
||||
// textproto message containing {key: <kvalue>, value: <mvalue>}.
|
||||
func (d decoder) unmarshalMap(fd pref.FieldDescriptor, mmap pref.Map) error {
|
||||
func (d decoder) unmarshalMap(fd protoreflect.FieldDescriptor, mmap protoreflect.Map) error {
|
||||
// Determine ahead whether map entry is a scalar type or a message type in
|
||||
// order to call the appropriate unmarshalMapValue func inside
|
||||
// unmarshalMapEntry.
|
||||
var unmarshalMapValue func() (pref.Value, error)
|
||||
var unmarshalMapValue func() (protoreflect.Value, error)
|
||||
switch fd.MapValue().Kind() {
|
||||
case pref.MessageKind, pref.GroupKind:
|
||||
unmarshalMapValue = func() (pref.Value, error) {
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
unmarshalMapValue = func() (protoreflect.Value, error) {
|
||||
pval := mmap.NewValue()
|
||||
if err := d.unmarshalMessage(pval.Message(), true); err != nil {
|
||||
return pref.Value{}, err
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
return pval, nil
|
||||
}
|
||||
default:
|
||||
unmarshalMapValue = func() (pref.Value, error) {
|
||||
unmarshalMapValue = func() (protoreflect.Value, error) {
|
||||
return d.unmarshalScalar(fd.MapValue())
|
||||
}
|
||||
}
|
||||
@ -494,9 +494,9 @@ func (d decoder) unmarshalMap(fd pref.FieldDescriptor, mmap pref.Map) error {
|
||||
|
||||
// unmarshalMap unmarshals into given protoreflect.Map. A map value is a
|
||||
// textproto message containing {key: <kvalue>, value: <mvalue>}.
|
||||
func (d decoder) unmarshalMapEntry(fd pref.FieldDescriptor, mmap pref.Map, unmarshalMapValue func() (pref.Value, error)) error {
|
||||
var key pref.MapKey
|
||||
var pval pref.Value
|
||||
func (d decoder) unmarshalMapEntry(fd protoreflect.FieldDescriptor, mmap protoreflect.Map, unmarshalMapValue func() (protoreflect.Value, error)) error {
|
||||
var key protoreflect.MapKey
|
||||
var pval protoreflect.Value
|
||||
Loop:
|
||||
for {
|
||||
// Read field name.
|
||||
@ -520,7 +520,7 @@ Loop:
|
||||
return d.unexpectedTokenError(tok)
|
||||
}
|
||||
|
||||
switch name := pref.Name(tok.IdentName()); name {
|
||||
switch name := protoreflect.Name(tok.IdentName()); name {
|
||||
case genid.MapEntry_Key_field_name:
|
||||
if !tok.HasSeparator() {
|
||||
return d.syntaxError(tok.Pos(), "missing field separator :")
|
||||
@ -535,7 +535,7 @@ Loop:
|
||||
key = val.MapKey()
|
||||
|
||||
case genid.MapEntry_Value_field_name:
|
||||
if kind := fd.MapValue().Kind(); (kind != pref.MessageKind) && (kind != pref.GroupKind) {
|
||||
if kind := fd.MapValue().Kind(); (kind != protoreflect.MessageKind) && (kind != protoreflect.GroupKind) {
|
||||
if !tok.HasSeparator() {
|
||||
return d.syntaxError(tok.Pos(), "missing field separator :")
|
||||
}
|
||||
@ -561,7 +561,7 @@ Loop:
|
||||
}
|
||||
if !pval.IsValid() {
|
||||
switch fd.MapValue().Kind() {
|
||||
case pref.MessageKind, pref.GroupKind:
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
// If value field is not set for message/group types, construct an
|
||||
// empty one as default.
|
||||
pval = mmap.NewValue()
|
||||
@ -575,7 +575,7 @@ Loop:
|
||||
|
||||
// unmarshalAny unmarshals an Any textproto. It can either be in expanded form
|
||||
// or non-expanded form.
|
||||
func (d decoder) unmarshalAny(m pref.Message, checkDelims bool) error {
|
||||
func (d decoder) unmarshalAny(m protoreflect.Message, checkDelims bool) error {
|
||||
var typeURL string
|
||||
var bValue []byte
|
||||
var seenTypeUrl bool
|
||||
@ -619,7 +619,7 @@ Loop:
|
||||
return d.syntaxError(tok.Pos(), "missing field separator :")
|
||||
}
|
||||
|
||||
switch name := pref.Name(tok.IdentName()); name {
|
||||
switch name := protoreflect.Name(tok.IdentName()); name {
|
||||
case genid.Any_TypeUrl_field_name:
|
||||
if seenTypeUrl {
|
||||
return d.newError(tok.Pos(), "duplicate %v field", genid.Any_TypeUrl_field_fullname)
|
||||
@ -686,10 +686,10 @@ Loop:
|
||||
|
||||
fds := m.Descriptor().Fields()
|
||||
if len(typeURL) > 0 {
|
||||
m.Set(fds.ByNumber(genid.Any_TypeUrl_field_number), pref.ValueOfString(typeURL))
|
||||
m.Set(fds.ByNumber(genid.Any_TypeUrl_field_number), protoreflect.ValueOfString(typeURL))
|
||||
}
|
||||
if len(bValue) > 0 {
|
||||
m.Set(fds.ByNumber(genid.Any_Value_field_number), pref.ValueOfBytes(bValue))
|
||||
m.Set(fds.ByNumber(genid.Any_Value_field_number), protoreflect.ValueOfBytes(bValue))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
39
vendor/google.golang.org/protobuf/encoding/prototext/encode.go
generated
vendored
39
vendor/google.golang.org/protobuf/encoding/prototext/encode.go
generated
vendored
@ -20,7 +20,6 @@ import (
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
)
|
||||
|
||||
@ -150,7 +149,7 @@ type encoder struct {
|
||||
}
|
||||
|
||||
// marshalMessage marshals the given protoreflect.Message.
|
||||
func (e encoder) marshalMessage(m pref.Message, inclDelims bool) error {
|
||||
func (e encoder) marshalMessage(m protoreflect.Message, inclDelims bool) error {
|
||||
messageDesc := m.Descriptor()
|
||||
if !flags.ProtoLegacy && messageset.IsMessageSet(messageDesc) {
|
||||
return errors.New("no support for proto1 MessageSets")
|
||||
@ -190,7 +189,7 @@ func (e encoder) marshalMessage(m pref.Message, inclDelims bool) error {
|
||||
}
|
||||
|
||||
// marshalField marshals the given field with protoreflect.Value.
|
||||
func (e encoder) marshalField(name string, val pref.Value, fd pref.FieldDescriptor) error {
|
||||
func (e encoder) marshalField(name string, val protoreflect.Value, fd protoreflect.FieldDescriptor) error {
|
||||
switch {
|
||||
case fd.IsList():
|
||||
return e.marshalList(name, val.List(), fd)
|
||||
@ -204,40 +203,40 @@ func (e encoder) marshalField(name string, val pref.Value, fd pref.FieldDescript
|
||||
|
||||
// marshalSingular marshals the given non-repeated field value. This includes
|
||||
// all scalar types, enums, messages, and groups.
|
||||
func (e encoder) marshalSingular(val pref.Value, fd pref.FieldDescriptor) error {
|
||||
func (e encoder) marshalSingular(val protoreflect.Value, fd protoreflect.FieldDescriptor) error {
|
||||
kind := fd.Kind()
|
||||
switch kind {
|
||||
case pref.BoolKind:
|
||||
case protoreflect.BoolKind:
|
||||
e.WriteBool(val.Bool())
|
||||
|
||||
case pref.StringKind:
|
||||
case protoreflect.StringKind:
|
||||
s := val.String()
|
||||
if !e.opts.allowInvalidUTF8 && strs.EnforceUTF8(fd) && !utf8.ValidString(s) {
|
||||
return errors.InvalidUTF8(string(fd.FullName()))
|
||||
}
|
||||
e.WriteString(s)
|
||||
|
||||
case pref.Int32Kind, pref.Int64Kind,
|
||||
pref.Sint32Kind, pref.Sint64Kind,
|
||||
pref.Sfixed32Kind, pref.Sfixed64Kind:
|
||||
case protoreflect.Int32Kind, protoreflect.Int64Kind,
|
||||
protoreflect.Sint32Kind, protoreflect.Sint64Kind,
|
||||
protoreflect.Sfixed32Kind, protoreflect.Sfixed64Kind:
|
||||
e.WriteInt(val.Int())
|
||||
|
||||
case pref.Uint32Kind, pref.Uint64Kind,
|
||||
pref.Fixed32Kind, pref.Fixed64Kind:
|
||||
case protoreflect.Uint32Kind, protoreflect.Uint64Kind,
|
||||
protoreflect.Fixed32Kind, protoreflect.Fixed64Kind:
|
||||
e.WriteUint(val.Uint())
|
||||
|
||||
case pref.FloatKind:
|
||||
case protoreflect.FloatKind:
|
||||
// Encoder.WriteFloat handles the special numbers NaN and infinites.
|
||||
e.WriteFloat(val.Float(), 32)
|
||||
|
||||
case pref.DoubleKind:
|
||||
case protoreflect.DoubleKind:
|
||||
// Encoder.WriteFloat handles the special numbers NaN and infinites.
|
||||
e.WriteFloat(val.Float(), 64)
|
||||
|
||||
case pref.BytesKind:
|
||||
case protoreflect.BytesKind:
|
||||
e.WriteString(string(val.Bytes()))
|
||||
|
||||
case pref.EnumKind:
|
||||
case protoreflect.EnumKind:
|
||||
num := val.Enum()
|
||||
if desc := fd.Enum().Values().ByNumber(num); desc != nil {
|
||||
e.WriteLiteral(string(desc.Name()))
|
||||
@ -246,7 +245,7 @@ func (e encoder) marshalSingular(val pref.Value, fd pref.FieldDescriptor) error
|
||||
e.WriteInt(int64(num))
|
||||
}
|
||||
|
||||
case pref.MessageKind, pref.GroupKind:
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
return e.marshalMessage(val.Message(), true)
|
||||
|
||||
default:
|
||||
@ -256,7 +255,7 @@ func (e encoder) marshalSingular(val pref.Value, fd pref.FieldDescriptor) error
|
||||
}
|
||||
|
||||
// marshalList marshals the given protoreflect.List as multiple name-value fields.
|
||||
func (e encoder) marshalList(name string, list pref.List, fd pref.FieldDescriptor) error {
|
||||
func (e encoder) marshalList(name string, list protoreflect.List, fd protoreflect.FieldDescriptor) error {
|
||||
size := list.Len()
|
||||
for i := 0; i < size; i++ {
|
||||
e.WriteName(name)
|
||||
@ -268,9 +267,9 @@ func (e encoder) marshalList(name string, list pref.List, fd pref.FieldDescripto
|
||||
}
|
||||
|
||||
// marshalMap marshals the given protoreflect.Map as multiple name-value fields.
|
||||
func (e encoder) marshalMap(name string, mmap pref.Map, fd pref.FieldDescriptor) error {
|
||||
func (e encoder) marshalMap(name string, mmap protoreflect.Map, fd protoreflect.FieldDescriptor) error {
|
||||
var err error
|
||||
order.RangeEntries(mmap, order.GenericKeyOrder, func(key pref.MapKey, val pref.Value) bool {
|
||||
order.RangeEntries(mmap, order.GenericKeyOrder, func(key protoreflect.MapKey, val protoreflect.Value) bool {
|
||||
e.WriteName(name)
|
||||
e.StartMessage()
|
||||
defer e.EndMessage()
|
||||
@ -334,7 +333,7 @@ func (e encoder) marshalUnknown(b []byte) {
|
||||
|
||||
// marshalAny marshals the given google.protobuf.Any message in expanded form.
|
||||
// It returns true if it was able to marshal, else false.
|
||||
func (e encoder) marshalAny(any pref.Message) bool {
|
||||
func (e encoder) marshalAny(any protoreflect.Message) bool {
|
||||
// Construct the embedded message.
|
||||
fds := any.Descriptor().Fields()
|
||||
fdType := fds.ByNumber(genid.Any_TypeUrl_field_number)
|
||||
|
23
vendor/google.golang.org/protobuf/encoding/protowire/wire.go
generated
vendored
23
vendor/google.golang.org/protobuf/encoding/protowire/wire.go
generated
vendored
@ -21,10 +21,11 @@ import (
|
||||
type Number int32
|
||||
|
||||
const (
|
||||
MinValidNumber Number = 1
|
||||
FirstReservedNumber Number = 19000
|
||||
LastReservedNumber Number = 19999
|
||||
MaxValidNumber Number = 1<<29 - 1
|
||||
MinValidNumber Number = 1
|
||||
FirstReservedNumber Number = 19000
|
||||
LastReservedNumber Number = 19999
|
||||
MaxValidNumber Number = 1<<29 - 1
|
||||
DefaultRecursionLimit = 10000
|
||||
)
|
||||
|
||||
// IsValid reports whether the field number is semantically valid.
|
||||
@ -55,6 +56,7 @@ const (
|
||||
errCodeOverflow
|
||||
errCodeReserved
|
||||
errCodeEndGroup
|
||||
errCodeRecursionDepth
|
||||
)
|
||||
|
||||
var (
|
||||
@ -112,6 +114,10 @@ func ConsumeField(b []byte) (Number, Type, int) {
|
||||
// When parsing a group, the length includes the end group marker and
|
||||
// the end group is verified to match the starting field number.
|
||||
func ConsumeFieldValue(num Number, typ Type, b []byte) (n int) {
|
||||
return consumeFieldValueD(num, typ, b, DefaultRecursionLimit)
|
||||
}
|
||||
|
||||
func consumeFieldValueD(num Number, typ Type, b []byte, depth int) (n int) {
|
||||
switch typ {
|
||||
case VarintType:
|
||||
_, n = ConsumeVarint(b)
|
||||
@ -126,6 +132,9 @@ func ConsumeFieldValue(num Number, typ Type, b []byte) (n int) {
|
||||
_, n = ConsumeBytes(b)
|
||||
return n
|
||||
case StartGroupType:
|
||||
if depth < 0 {
|
||||
return errCodeRecursionDepth
|
||||
}
|
||||
n0 := len(b)
|
||||
for {
|
||||
num2, typ2, n := ConsumeTag(b)
|
||||
@ -140,7 +149,7 @@ func ConsumeFieldValue(num Number, typ Type, b []byte) (n int) {
|
||||
return n0 - len(b)
|
||||
}
|
||||
|
||||
n = ConsumeFieldValue(num2, typ2, b)
|
||||
n = consumeFieldValueD(num2, typ2, b, depth-1)
|
||||
if n < 0 {
|
||||
return n // forward error code
|
||||
}
|
||||
@ -507,6 +516,7 @@ func EncodeTag(num Number, typ Type) uint64 {
|
||||
}
|
||||
|
||||
// DecodeZigZag decodes a zig-zag-encoded uint64 as an int64.
|
||||
//
|
||||
// Input: {…, 5, 3, 1, 0, 2, 4, 6, …}
|
||||
// Output: {…, -3, -2, -1, 0, +1, +2, +3, …}
|
||||
func DecodeZigZag(x uint64) int64 {
|
||||
@ -514,6 +524,7 @@ func DecodeZigZag(x uint64) int64 {
|
||||
}
|
||||
|
||||
// EncodeZigZag encodes an int64 as a zig-zag-encoded uint64.
|
||||
//
|
||||
// Input: {…, -3, -2, -1, 0, +1, +2, +3, …}
|
||||
// Output: {…, 5, 3, 1, 0, 2, 4, 6, …}
|
||||
func EncodeZigZag(x int64) uint64 {
|
||||
@ -521,6 +532,7 @@ func EncodeZigZag(x int64) uint64 {
|
||||
}
|
||||
|
||||
// DecodeBool decodes a uint64 as a bool.
|
||||
//
|
||||
// Input: { 0, 1, 2, …}
|
||||
// Output: {false, true, true, …}
|
||||
func DecodeBool(x uint64) bool {
|
||||
@ -528,6 +540,7 @@ func DecodeBool(x uint64) bool {
|
||||
}
|
||||
|
||||
// EncodeBool encodes a bool as a uint64.
|
||||
//
|
||||
// Input: {false, true}
|
||||
// Output: { 0, 1}
|
||||
func EncodeBool(x bool) uint64 {
|
||||
|
66
vendor/google.golang.org/protobuf/internal/descfmt/stringer.go
generated
vendored
66
vendor/google.golang.org/protobuf/internal/descfmt/stringer.go
generated
vendored
@ -14,7 +14,7 @@ import (
|
||||
|
||||
"google.golang.org/protobuf/internal/detrand"
|
||||
"google.golang.org/protobuf/internal/pragma"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
type list interface {
|
||||
@ -30,17 +30,17 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
|
||||
if isRoot {
|
||||
var name string
|
||||
switch vs.(type) {
|
||||
case pref.Names:
|
||||
case protoreflect.Names:
|
||||
name = "Names"
|
||||
case pref.FieldNumbers:
|
||||
case protoreflect.FieldNumbers:
|
||||
name = "FieldNumbers"
|
||||
case pref.FieldRanges:
|
||||
case protoreflect.FieldRanges:
|
||||
name = "FieldRanges"
|
||||
case pref.EnumRanges:
|
||||
case protoreflect.EnumRanges:
|
||||
name = "EnumRanges"
|
||||
case pref.FileImports:
|
||||
case protoreflect.FileImports:
|
||||
name = "FileImports"
|
||||
case pref.Descriptor:
|
||||
case protoreflect.Descriptor:
|
||||
name = reflect.ValueOf(vs).MethodByName("Get").Type().Out(0).Name() + "s"
|
||||
default:
|
||||
name = reflect.ValueOf(vs).Elem().Type().Name()
|
||||
@ -50,17 +50,17 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
|
||||
|
||||
var ss []string
|
||||
switch vs := vs.(type) {
|
||||
case pref.Names:
|
||||
case protoreflect.Names:
|
||||
for i := 0; i < vs.Len(); i++ {
|
||||
ss = append(ss, fmt.Sprint(vs.Get(i)))
|
||||
}
|
||||
return start + joinStrings(ss, false) + end
|
||||
case pref.FieldNumbers:
|
||||
case protoreflect.FieldNumbers:
|
||||
for i := 0; i < vs.Len(); i++ {
|
||||
ss = append(ss, fmt.Sprint(vs.Get(i)))
|
||||
}
|
||||
return start + joinStrings(ss, false) + end
|
||||
case pref.FieldRanges:
|
||||
case protoreflect.FieldRanges:
|
||||
for i := 0; i < vs.Len(); i++ {
|
||||
r := vs.Get(i)
|
||||
if r[0]+1 == r[1] {
|
||||
@ -70,7 +70,7 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
|
||||
}
|
||||
}
|
||||
return start + joinStrings(ss, false) + end
|
||||
case pref.EnumRanges:
|
||||
case protoreflect.EnumRanges:
|
||||
for i := 0; i < vs.Len(); i++ {
|
||||
r := vs.Get(i)
|
||||
if r[0] == r[1] {
|
||||
@ -80,7 +80,7 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
|
||||
}
|
||||
}
|
||||
return start + joinStrings(ss, false) + end
|
||||
case pref.FileImports:
|
||||
case protoreflect.FileImports:
|
||||
for i := 0; i < vs.Len(); i++ {
|
||||
var rs records
|
||||
rs.Append(reflect.ValueOf(vs.Get(i)), "Path", "Package", "IsPublic", "IsWeak")
|
||||
@ -88,11 +88,11 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
|
||||
}
|
||||
return start + joinStrings(ss, allowMulti) + end
|
||||
default:
|
||||
_, isEnumValue := vs.(pref.EnumValueDescriptors)
|
||||
_, isEnumValue := vs.(protoreflect.EnumValueDescriptors)
|
||||
for i := 0; i < vs.Len(); i++ {
|
||||
m := reflect.ValueOf(vs).MethodByName("Get")
|
||||
v := m.Call([]reflect.Value{reflect.ValueOf(i)})[0].Interface()
|
||||
ss = append(ss, formatDescOpt(v.(pref.Descriptor), false, allowMulti && !isEnumValue))
|
||||
ss = append(ss, formatDescOpt(v.(protoreflect.Descriptor), false, allowMulti && !isEnumValue))
|
||||
}
|
||||
return start + joinStrings(ss, allowMulti && isEnumValue) + end
|
||||
}
|
||||
@ -106,20 +106,20 @@ func formatListOpt(vs list, isRoot, allowMulti bool) string {
|
||||
//
|
||||
// Using a list allows us to print the accessors in a sensible order.
|
||||
var descriptorAccessors = map[reflect.Type][]string{
|
||||
reflect.TypeOf((*pref.FileDescriptor)(nil)).Elem(): {"Path", "Package", "Imports", "Messages", "Enums", "Extensions", "Services"},
|
||||
reflect.TypeOf((*pref.MessageDescriptor)(nil)).Elem(): {"IsMapEntry", "Fields", "Oneofs", "ReservedNames", "ReservedRanges", "RequiredNumbers", "ExtensionRanges", "Messages", "Enums", "Extensions"},
|
||||
reflect.TypeOf((*pref.FieldDescriptor)(nil)).Elem(): {"Number", "Cardinality", "Kind", "HasJSONName", "JSONName", "HasPresence", "IsExtension", "IsPacked", "IsWeak", "IsList", "IsMap", "MapKey", "MapValue", "HasDefault", "Default", "ContainingOneof", "ContainingMessage", "Message", "Enum"},
|
||||
reflect.TypeOf((*pref.OneofDescriptor)(nil)).Elem(): {"Fields"}, // not directly used; must keep in sync with formatDescOpt
|
||||
reflect.TypeOf((*pref.EnumDescriptor)(nil)).Elem(): {"Values", "ReservedNames", "ReservedRanges"},
|
||||
reflect.TypeOf((*pref.EnumValueDescriptor)(nil)).Elem(): {"Number"},
|
||||
reflect.TypeOf((*pref.ServiceDescriptor)(nil)).Elem(): {"Methods"},
|
||||
reflect.TypeOf((*pref.MethodDescriptor)(nil)).Elem(): {"Input", "Output", "IsStreamingClient", "IsStreamingServer"},
|
||||
reflect.TypeOf((*protoreflect.FileDescriptor)(nil)).Elem(): {"Path", "Package", "Imports", "Messages", "Enums", "Extensions", "Services"},
|
||||
reflect.TypeOf((*protoreflect.MessageDescriptor)(nil)).Elem(): {"IsMapEntry", "Fields", "Oneofs", "ReservedNames", "ReservedRanges", "RequiredNumbers", "ExtensionRanges", "Messages", "Enums", "Extensions"},
|
||||
reflect.TypeOf((*protoreflect.FieldDescriptor)(nil)).Elem(): {"Number", "Cardinality", "Kind", "HasJSONName", "JSONName", "HasPresence", "IsExtension", "IsPacked", "IsWeak", "IsList", "IsMap", "MapKey", "MapValue", "HasDefault", "Default", "ContainingOneof", "ContainingMessage", "Message", "Enum"},
|
||||
reflect.TypeOf((*protoreflect.OneofDescriptor)(nil)).Elem(): {"Fields"}, // not directly used; must keep in sync with formatDescOpt
|
||||
reflect.TypeOf((*protoreflect.EnumDescriptor)(nil)).Elem(): {"Values", "ReservedNames", "ReservedRanges"},
|
||||
reflect.TypeOf((*protoreflect.EnumValueDescriptor)(nil)).Elem(): {"Number"},
|
||||
reflect.TypeOf((*protoreflect.ServiceDescriptor)(nil)).Elem(): {"Methods"},
|
||||
reflect.TypeOf((*protoreflect.MethodDescriptor)(nil)).Elem(): {"Input", "Output", "IsStreamingClient", "IsStreamingServer"},
|
||||
}
|
||||
|
||||
func FormatDesc(s fmt.State, r rune, t pref.Descriptor) {
|
||||
func FormatDesc(s fmt.State, r rune, t protoreflect.Descriptor) {
|
||||
io.WriteString(s, formatDescOpt(t, true, r == 'v' && (s.Flag('+') || s.Flag('#'))))
|
||||
}
|
||||
func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
|
||||
func formatDescOpt(t protoreflect.Descriptor, isRoot, allowMulti bool) string {
|
||||
rv := reflect.ValueOf(t)
|
||||
rt := rv.MethodByName("ProtoType").Type().In(0)
|
||||
|
||||
@ -128,7 +128,7 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
|
||||
start = rt.Name() + "{"
|
||||
}
|
||||
|
||||
_, isFile := t.(pref.FileDescriptor)
|
||||
_, isFile := t.(protoreflect.FileDescriptor)
|
||||
rs := records{allowMulti: allowMulti}
|
||||
if t.IsPlaceholder() {
|
||||
if isFile {
|
||||
@ -146,7 +146,7 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
|
||||
rs.Append(rv, "Name")
|
||||
}
|
||||
switch t := t.(type) {
|
||||
case pref.FieldDescriptor:
|
||||
case protoreflect.FieldDescriptor:
|
||||
for _, s := range descriptorAccessors[rt] {
|
||||
switch s {
|
||||
case "MapKey":
|
||||
@ -156,9 +156,9 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
|
||||
case "MapValue":
|
||||
if v := t.MapValue(); v != nil {
|
||||
switch v.Kind() {
|
||||
case pref.EnumKind:
|
||||
case protoreflect.EnumKind:
|
||||
rs.recs = append(rs.recs, [2]string{"MapValue", string(v.Enum().FullName())})
|
||||
case pref.MessageKind, pref.GroupKind:
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
rs.recs = append(rs.recs, [2]string{"MapValue", string(v.Message().FullName())})
|
||||
default:
|
||||
rs.recs = append(rs.recs, [2]string{"MapValue", v.Kind().String()})
|
||||
@ -180,7 +180,7 @@ func formatDescOpt(t pref.Descriptor, isRoot, allowMulti bool) string {
|
||||
rs.Append(rv, s)
|
||||
}
|
||||
}
|
||||
case pref.OneofDescriptor:
|
||||
case protoreflect.OneofDescriptor:
|
||||
var ss []string
|
||||
fs := t.Fields()
|
||||
for i := 0; i < fs.Len(); i++ {
|
||||
@ -216,7 +216,7 @@ func (rs *records) Append(v reflect.Value, accessors ...string) {
|
||||
if !rv.IsValid() {
|
||||
panic(fmt.Sprintf("unknown accessor: %v.%s", v.Type(), a))
|
||||
}
|
||||
if _, ok := rv.Interface().(pref.Value); ok {
|
||||
if _, ok := rv.Interface().(protoreflect.Value); ok {
|
||||
rv = rv.MethodByName("Interface").Call(nil)[0]
|
||||
if !rv.IsNil() {
|
||||
rv = rv.Elem()
|
||||
@ -250,9 +250,9 @@ func (rs *records) Append(v reflect.Value, accessors ...string) {
|
||||
switch v := v.(type) {
|
||||
case list:
|
||||
s = formatListOpt(v, false, rs.allowMulti)
|
||||
case pref.FieldDescriptor, pref.OneofDescriptor, pref.EnumValueDescriptor, pref.MethodDescriptor:
|
||||
s = string(v.(pref.Descriptor).Name())
|
||||
case pref.Descriptor:
|
||||
case protoreflect.FieldDescriptor, protoreflect.OneofDescriptor, protoreflect.EnumValueDescriptor, protoreflect.MethodDescriptor:
|
||||
s = string(v.(protoreflect.Descriptor).Name())
|
||||
case protoreflect.Descriptor:
|
||||
s = string(v.FullName())
|
||||
case string:
|
||||
s = strconv.Quote(v)
|
||||
|
78
vendor/google.golang.org/protobuf/internal/encoding/defval/default.go
generated
vendored
78
vendor/google.golang.org/protobuf/internal/encoding/defval/default.go
generated
vendored
@ -15,8 +15,8 @@ import (
|
||||
"strconv"
|
||||
|
||||
ptext "google.golang.org/protobuf/internal/encoding/text"
|
||||
errors "google.golang.org/protobuf/internal/errors"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// Format is the serialization format used to represent the default value.
|
||||
@ -35,56 +35,56 @@ const (
|
||||
|
||||
// Unmarshal deserializes the default string s according to the given kind k.
|
||||
// When k is an enum, a list of enum value descriptors must be provided.
|
||||
func Unmarshal(s string, k pref.Kind, evs pref.EnumValueDescriptors, f Format) (pref.Value, pref.EnumValueDescriptor, error) {
|
||||
func Unmarshal(s string, k protoreflect.Kind, evs protoreflect.EnumValueDescriptors, f Format) (protoreflect.Value, protoreflect.EnumValueDescriptor, error) {
|
||||
switch k {
|
||||
case pref.BoolKind:
|
||||
case protoreflect.BoolKind:
|
||||
if f == GoTag {
|
||||
switch s {
|
||||
case "1":
|
||||
return pref.ValueOfBool(true), nil, nil
|
||||
return protoreflect.ValueOfBool(true), nil, nil
|
||||
case "0":
|
||||
return pref.ValueOfBool(false), nil, nil
|
||||
return protoreflect.ValueOfBool(false), nil, nil
|
||||
}
|
||||
} else {
|
||||
switch s {
|
||||
case "true":
|
||||
return pref.ValueOfBool(true), nil, nil
|
||||
return protoreflect.ValueOfBool(true), nil, nil
|
||||
case "false":
|
||||
return pref.ValueOfBool(false), nil, nil
|
||||
return protoreflect.ValueOfBool(false), nil, nil
|
||||
}
|
||||
}
|
||||
case pref.EnumKind:
|
||||
case protoreflect.EnumKind:
|
||||
if f == GoTag {
|
||||
// Go tags use the numeric form of the enum value.
|
||||
if n, err := strconv.ParseInt(s, 10, 32); err == nil {
|
||||
if ev := evs.ByNumber(pref.EnumNumber(n)); ev != nil {
|
||||
return pref.ValueOfEnum(ev.Number()), ev, nil
|
||||
if ev := evs.ByNumber(protoreflect.EnumNumber(n)); ev != nil {
|
||||
return protoreflect.ValueOfEnum(ev.Number()), ev, nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Descriptor default_value use the enum identifier.
|
||||
ev := evs.ByName(pref.Name(s))
|
||||
ev := evs.ByName(protoreflect.Name(s))
|
||||
if ev != nil {
|
||||
return pref.ValueOfEnum(ev.Number()), ev, nil
|
||||
return protoreflect.ValueOfEnum(ev.Number()), ev, nil
|
||||
}
|
||||
}
|
||||
case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
|
||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||
if v, err := strconv.ParseInt(s, 10, 32); err == nil {
|
||||
return pref.ValueOfInt32(int32(v)), nil, nil
|
||||
return protoreflect.ValueOfInt32(int32(v)), nil, nil
|
||||
}
|
||||
case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
|
||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
||||
if v, err := strconv.ParseInt(s, 10, 64); err == nil {
|
||||
return pref.ValueOfInt64(int64(v)), nil, nil
|
||||
return protoreflect.ValueOfInt64(int64(v)), nil, nil
|
||||
}
|
||||
case pref.Uint32Kind, pref.Fixed32Kind:
|
||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
||||
if v, err := strconv.ParseUint(s, 10, 32); err == nil {
|
||||
return pref.ValueOfUint32(uint32(v)), nil, nil
|
||||
return protoreflect.ValueOfUint32(uint32(v)), nil, nil
|
||||
}
|
||||
case pref.Uint64Kind, pref.Fixed64Kind:
|
||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
||||
if v, err := strconv.ParseUint(s, 10, 64); err == nil {
|
||||
return pref.ValueOfUint64(uint64(v)), nil, nil
|
||||
return protoreflect.ValueOfUint64(uint64(v)), nil, nil
|
||||
}
|
||||
case pref.FloatKind, pref.DoubleKind:
|
||||
case protoreflect.FloatKind, protoreflect.DoubleKind:
|
||||
var v float64
|
||||
var err error
|
||||
switch s {
|
||||
@ -98,29 +98,29 @@ func Unmarshal(s string, k pref.Kind, evs pref.EnumValueDescriptors, f Format) (
|
||||
v, err = strconv.ParseFloat(s, 64)
|
||||
}
|
||||
if err == nil {
|
||||
if k == pref.FloatKind {
|
||||
return pref.ValueOfFloat32(float32(v)), nil, nil
|
||||
if k == protoreflect.FloatKind {
|
||||
return protoreflect.ValueOfFloat32(float32(v)), nil, nil
|
||||
} else {
|
||||
return pref.ValueOfFloat64(float64(v)), nil, nil
|
||||
return protoreflect.ValueOfFloat64(float64(v)), nil, nil
|
||||
}
|
||||
}
|
||||
case pref.StringKind:
|
||||
case protoreflect.StringKind:
|
||||
// String values are already unescaped and can be used as is.
|
||||
return pref.ValueOfString(s), nil, nil
|
||||
case pref.BytesKind:
|
||||
return protoreflect.ValueOfString(s), nil, nil
|
||||
case protoreflect.BytesKind:
|
||||
if b, ok := unmarshalBytes(s); ok {
|
||||
return pref.ValueOfBytes(b), nil, nil
|
||||
return protoreflect.ValueOfBytes(b), nil, nil
|
||||
}
|
||||
}
|
||||
return pref.Value{}, nil, errors.New("could not parse value for %v: %q", k, s)
|
||||
return protoreflect.Value{}, nil, errors.New("could not parse value for %v: %q", k, s)
|
||||
}
|
||||
|
||||
// Marshal serializes v as the default string according to the given kind k.
|
||||
// When specifying the Descriptor format for an enum kind, the associated
|
||||
// enum value descriptor must be provided.
|
||||
func Marshal(v pref.Value, ev pref.EnumValueDescriptor, k pref.Kind, f Format) (string, error) {
|
||||
func Marshal(v protoreflect.Value, ev protoreflect.EnumValueDescriptor, k protoreflect.Kind, f Format) (string, error) {
|
||||
switch k {
|
||||
case pref.BoolKind:
|
||||
case protoreflect.BoolKind:
|
||||
if f == GoTag {
|
||||
if v.Bool() {
|
||||
return "1", nil
|
||||
@ -134,17 +134,17 @@ func Marshal(v pref.Value, ev pref.EnumValueDescriptor, k pref.Kind, f Format) (
|
||||
return "false", nil
|
||||
}
|
||||
}
|
||||
case pref.EnumKind:
|
||||
case protoreflect.EnumKind:
|
||||
if f == GoTag {
|
||||
return strconv.FormatInt(int64(v.Enum()), 10), nil
|
||||
} else {
|
||||
return string(ev.Name()), nil
|
||||
}
|
||||
case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind, pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
|
||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
||||
return strconv.FormatInt(v.Int(), 10), nil
|
||||
case pref.Uint32Kind, pref.Fixed32Kind, pref.Uint64Kind, pref.Fixed64Kind:
|
||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
||||
return strconv.FormatUint(v.Uint(), 10), nil
|
||||
case pref.FloatKind, pref.DoubleKind:
|
||||
case protoreflect.FloatKind, protoreflect.DoubleKind:
|
||||
f := v.Float()
|
||||
switch {
|
||||
case math.IsInf(f, -1):
|
||||
@ -154,16 +154,16 @@ func Marshal(v pref.Value, ev pref.EnumValueDescriptor, k pref.Kind, f Format) (
|
||||
case math.IsNaN(f):
|
||||
return "nan", nil
|
||||
default:
|
||||
if k == pref.FloatKind {
|
||||
if k == protoreflect.FloatKind {
|
||||
return strconv.FormatFloat(f, 'g', -1, 32), nil
|
||||
} else {
|
||||
return strconv.FormatFloat(f, 'g', -1, 64), nil
|
||||
}
|
||||
}
|
||||
case pref.StringKind:
|
||||
case protoreflect.StringKind:
|
||||
// String values are serialized as is without any escaping.
|
||||
return v.String(), nil
|
||||
case pref.BytesKind:
|
||||
case protoreflect.BytesKind:
|
||||
if s, ok := marshalBytes(v.Bytes()); ok {
|
||||
return s, nil
|
||||
}
|
||||
|
7
vendor/google.golang.org/protobuf/internal/encoding/messageset/messageset.go
generated
vendored
7
vendor/google.golang.org/protobuf/internal/encoding/messageset/messageset.go
generated
vendored
@ -10,7 +10,7 @@ import (
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// The MessageSet wire format is equivalent to a message defined as follows,
|
||||
@ -33,6 +33,7 @@ const (
|
||||
// ExtensionName is the field name for extensions of MessageSet.
|
||||
//
|
||||
// A valid MessageSet extension must be of the form:
|
||||
//
|
||||
// message MyMessage {
|
||||
// extend proto2.bridge.MessageSet {
|
||||
// optional MyMessage message_set_extension = 1234;
|
||||
@ -42,13 +43,13 @@ const (
|
||||
const ExtensionName = "message_set_extension"
|
||||
|
||||
// IsMessageSet returns whether the message uses the MessageSet wire format.
|
||||
func IsMessageSet(md pref.MessageDescriptor) bool {
|
||||
func IsMessageSet(md protoreflect.MessageDescriptor) bool {
|
||||
xmd, ok := md.(interface{ IsMessageSet() bool })
|
||||
return ok && xmd.IsMessageSet()
|
||||
}
|
||||
|
||||
// IsMessageSetExtension reports this field properly extends a MessageSet.
|
||||
func IsMessageSetExtension(fd pref.FieldDescriptor) bool {
|
||||
func IsMessageSetExtension(fd protoreflect.FieldDescriptor) bool {
|
||||
switch {
|
||||
case fd.Name() != ExtensionName:
|
||||
return false
|
||||
|
96
vendor/google.golang.org/protobuf/internal/encoding/tag/tag.go
generated
vendored
96
vendor/google.golang.org/protobuf/internal/encoding/tag/tag.go
generated
vendored
@ -11,10 +11,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
defval "google.golang.org/protobuf/internal/encoding/defval"
|
||||
fdesc "google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/internal/encoding/defval"
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
var byteType = reflect.TypeOf(byte(0))
|
||||
@ -29,9 +29,9 @@ var byteType = reflect.TypeOf(byte(0))
|
||||
// This does not populate the Enum or Message (except for weak message).
|
||||
//
|
||||
// This function is a best effort attempt; parsing errors are ignored.
|
||||
func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) pref.FieldDescriptor {
|
||||
f := new(fdesc.Field)
|
||||
f.L0.ParentFile = fdesc.SurrogateProto2
|
||||
func Unmarshal(tag string, goType reflect.Type, evs protoreflect.EnumValueDescriptors) protoreflect.FieldDescriptor {
|
||||
f := new(filedesc.Field)
|
||||
f.L0.ParentFile = filedesc.SurrogateProto2
|
||||
for len(tag) > 0 {
|
||||
i := strings.IndexByte(tag, ',')
|
||||
if i < 0 {
|
||||
@ -39,68 +39,68 @@ func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) p
|
||||
}
|
||||
switch s := tag[:i]; {
|
||||
case strings.HasPrefix(s, "name="):
|
||||
f.L0.FullName = pref.FullName(s[len("name="):])
|
||||
f.L0.FullName = protoreflect.FullName(s[len("name="):])
|
||||
case strings.Trim(s, "0123456789") == "":
|
||||
n, _ := strconv.ParseUint(s, 10, 32)
|
||||
f.L1.Number = pref.FieldNumber(n)
|
||||
f.L1.Number = protoreflect.FieldNumber(n)
|
||||
case s == "opt":
|
||||
f.L1.Cardinality = pref.Optional
|
||||
f.L1.Cardinality = protoreflect.Optional
|
||||
case s == "req":
|
||||
f.L1.Cardinality = pref.Required
|
||||
f.L1.Cardinality = protoreflect.Required
|
||||
case s == "rep":
|
||||
f.L1.Cardinality = pref.Repeated
|
||||
f.L1.Cardinality = protoreflect.Repeated
|
||||
case s == "varint":
|
||||
switch goType.Kind() {
|
||||
case reflect.Bool:
|
||||
f.L1.Kind = pref.BoolKind
|
||||
f.L1.Kind = protoreflect.BoolKind
|
||||
case reflect.Int32:
|
||||
f.L1.Kind = pref.Int32Kind
|
||||
f.L1.Kind = protoreflect.Int32Kind
|
||||
case reflect.Int64:
|
||||
f.L1.Kind = pref.Int64Kind
|
||||
f.L1.Kind = protoreflect.Int64Kind
|
||||
case reflect.Uint32:
|
||||
f.L1.Kind = pref.Uint32Kind
|
||||
f.L1.Kind = protoreflect.Uint32Kind
|
||||
case reflect.Uint64:
|
||||
f.L1.Kind = pref.Uint64Kind
|
||||
f.L1.Kind = protoreflect.Uint64Kind
|
||||
}
|
||||
case s == "zigzag32":
|
||||
if goType.Kind() == reflect.Int32 {
|
||||
f.L1.Kind = pref.Sint32Kind
|
||||
f.L1.Kind = protoreflect.Sint32Kind
|
||||
}
|
||||
case s == "zigzag64":
|
||||
if goType.Kind() == reflect.Int64 {
|
||||
f.L1.Kind = pref.Sint64Kind
|
||||
f.L1.Kind = protoreflect.Sint64Kind
|
||||
}
|
||||
case s == "fixed32":
|
||||
switch goType.Kind() {
|
||||
case reflect.Int32:
|
||||
f.L1.Kind = pref.Sfixed32Kind
|
||||
f.L1.Kind = protoreflect.Sfixed32Kind
|
||||
case reflect.Uint32:
|
||||
f.L1.Kind = pref.Fixed32Kind
|
||||
f.L1.Kind = protoreflect.Fixed32Kind
|
||||
case reflect.Float32:
|
||||
f.L1.Kind = pref.FloatKind
|
||||
f.L1.Kind = protoreflect.FloatKind
|
||||
}
|
||||
case s == "fixed64":
|
||||
switch goType.Kind() {
|
||||
case reflect.Int64:
|
||||
f.L1.Kind = pref.Sfixed64Kind
|
||||
f.L1.Kind = protoreflect.Sfixed64Kind
|
||||
case reflect.Uint64:
|
||||
f.L1.Kind = pref.Fixed64Kind
|
||||
f.L1.Kind = protoreflect.Fixed64Kind
|
||||
case reflect.Float64:
|
||||
f.L1.Kind = pref.DoubleKind
|
||||
f.L1.Kind = protoreflect.DoubleKind
|
||||
}
|
||||
case s == "bytes":
|
||||
switch {
|
||||
case goType.Kind() == reflect.String:
|
||||
f.L1.Kind = pref.StringKind
|
||||
f.L1.Kind = protoreflect.StringKind
|
||||
case goType.Kind() == reflect.Slice && goType.Elem() == byteType:
|
||||
f.L1.Kind = pref.BytesKind
|
||||
f.L1.Kind = protoreflect.BytesKind
|
||||
default:
|
||||
f.L1.Kind = pref.MessageKind
|
||||
f.L1.Kind = protoreflect.MessageKind
|
||||
}
|
||||
case s == "group":
|
||||
f.L1.Kind = pref.GroupKind
|
||||
f.L1.Kind = protoreflect.GroupKind
|
||||
case strings.HasPrefix(s, "enum="):
|
||||
f.L1.Kind = pref.EnumKind
|
||||
f.L1.Kind = protoreflect.EnumKind
|
||||
case strings.HasPrefix(s, "json="):
|
||||
jsonName := s[len("json="):]
|
||||
if jsonName != strs.JSONCamelCase(string(f.L0.FullName.Name())) {
|
||||
@ -111,23 +111,23 @@ func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) p
|
||||
f.L1.IsPacked = true
|
||||
case strings.HasPrefix(s, "weak="):
|
||||
f.L1.IsWeak = true
|
||||
f.L1.Message = fdesc.PlaceholderMessage(pref.FullName(s[len("weak="):]))
|
||||
f.L1.Message = filedesc.PlaceholderMessage(protoreflect.FullName(s[len("weak="):]))
|
||||
case strings.HasPrefix(s, "def="):
|
||||
// The default tag is special in that everything afterwards is the
|
||||
// default regardless of the presence of commas.
|
||||
s, i = tag[len("def="):], len(tag)
|
||||
v, ev, _ := defval.Unmarshal(s, f.L1.Kind, evs, defval.GoTag)
|
||||
f.L1.Default = fdesc.DefaultValue(v, ev)
|
||||
f.L1.Default = filedesc.DefaultValue(v, ev)
|
||||
case s == "proto3":
|
||||
f.L0.ParentFile = fdesc.SurrogateProto3
|
||||
f.L0.ParentFile = filedesc.SurrogateProto3
|
||||
}
|
||||
tag = strings.TrimPrefix(tag[i:], ",")
|
||||
}
|
||||
|
||||
// The generator uses the group message name instead of the field name.
|
||||
// We obtain the real field name by lowercasing the group name.
|
||||
if f.L1.Kind == pref.GroupKind {
|
||||
f.L0.FullName = pref.FullName(strings.ToLower(string(f.L0.FullName)))
|
||||
if f.L1.Kind == protoreflect.GroupKind {
|
||||
f.L0.FullName = protoreflect.FullName(strings.ToLower(string(f.L0.FullName)))
|
||||
}
|
||||
return f
|
||||
}
|
||||
@ -140,38 +140,38 @@ func Unmarshal(tag string, goType reflect.Type, evs pref.EnumValueDescriptors) p
|
||||
// Depending on the context on how Marshal is called, there are different ways
|
||||
// through which that information is determined. As such it is the caller's
|
||||
// responsibility to provide a function to obtain that information.
|
||||
func Marshal(fd pref.FieldDescriptor, enumName string) string {
|
||||
func Marshal(fd protoreflect.FieldDescriptor, enumName string) string {
|
||||
var tag []string
|
||||
switch fd.Kind() {
|
||||
case pref.BoolKind, pref.EnumKind, pref.Int32Kind, pref.Uint32Kind, pref.Int64Kind, pref.Uint64Kind:
|
||||
case protoreflect.BoolKind, protoreflect.EnumKind, protoreflect.Int32Kind, protoreflect.Uint32Kind, protoreflect.Int64Kind, protoreflect.Uint64Kind:
|
||||
tag = append(tag, "varint")
|
||||
case pref.Sint32Kind:
|
||||
case protoreflect.Sint32Kind:
|
||||
tag = append(tag, "zigzag32")
|
||||
case pref.Sint64Kind:
|
||||
case protoreflect.Sint64Kind:
|
||||
tag = append(tag, "zigzag64")
|
||||
case pref.Sfixed32Kind, pref.Fixed32Kind, pref.FloatKind:
|
||||
case protoreflect.Sfixed32Kind, protoreflect.Fixed32Kind, protoreflect.FloatKind:
|
||||
tag = append(tag, "fixed32")
|
||||
case pref.Sfixed64Kind, pref.Fixed64Kind, pref.DoubleKind:
|
||||
case protoreflect.Sfixed64Kind, protoreflect.Fixed64Kind, protoreflect.DoubleKind:
|
||||
tag = append(tag, "fixed64")
|
||||
case pref.StringKind, pref.BytesKind, pref.MessageKind:
|
||||
case protoreflect.StringKind, protoreflect.BytesKind, protoreflect.MessageKind:
|
||||
tag = append(tag, "bytes")
|
||||
case pref.GroupKind:
|
||||
case protoreflect.GroupKind:
|
||||
tag = append(tag, "group")
|
||||
}
|
||||
tag = append(tag, strconv.Itoa(int(fd.Number())))
|
||||
switch fd.Cardinality() {
|
||||
case pref.Optional:
|
||||
case protoreflect.Optional:
|
||||
tag = append(tag, "opt")
|
||||
case pref.Required:
|
||||
case protoreflect.Required:
|
||||
tag = append(tag, "req")
|
||||
case pref.Repeated:
|
||||
case protoreflect.Repeated:
|
||||
tag = append(tag, "rep")
|
||||
}
|
||||
if fd.IsPacked() {
|
||||
tag = append(tag, "packed")
|
||||
}
|
||||
name := string(fd.Name())
|
||||
if fd.Kind() == pref.GroupKind {
|
||||
if fd.Kind() == protoreflect.GroupKind {
|
||||
// The name of the FieldDescriptor for a group field is
|
||||
// lowercased. To find the original capitalization, we
|
||||
// look in the field's MessageType.
|
||||
@ -189,10 +189,10 @@ func Marshal(fd pref.FieldDescriptor, enumName string) string {
|
||||
// The previous implementation does not tag extension fields as proto3,
|
||||
// even when the field is defined in a proto3 file. Match that behavior
|
||||
// for consistency.
|
||||
if fd.Syntax() == pref.Proto3 && !fd.IsExtension() {
|
||||
if fd.Syntax() == protoreflect.Proto3 && !fd.IsExtension() {
|
||||
tag = append(tag, "proto3")
|
||||
}
|
||||
if fd.Kind() == pref.EnumKind && enumName != "" {
|
||||
if fd.Kind() == protoreflect.EnumKind && enumName != "" {
|
||||
tag = append(tag, "enum="+enumName)
|
||||
}
|
||||
if fd.ContainingOneof() != nil {
|
||||
|
32
vendor/google.golang.org/protobuf/internal/encoding/text/decode.go
generated
vendored
32
vendor/google.golang.org/protobuf/internal/encoding/text/decode.go
generated
vendored
@ -8,7 +8,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"unicode/utf8"
|
||||
|
||||
@ -381,7 +380,7 @@ func (d *Decoder) currentOpenKind() (Kind, byte) {
|
||||
case '[':
|
||||
return ListOpen, ']'
|
||||
}
|
||||
panic(fmt.Sprintf("Decoder: openStack contains invalid byte %s", string(openCh)))
|
||||
panic(fmt.Sprintf("Decoder: openStack contains invalid byte %c", openCh))
|
||||
}
|
||||
|
||||
func (d *Decoder) pushOpenStack(ch byte) {
|
||||
@ -421,7 +420,7 @@ func (d *Decoder) parseFieldName() (tok Token, err error) {
|
||||
return Token{}, d.newSyntaxError("invalid field number: %s", d.in[:num.size])
|
||||
}
|
||||
|
||||
return Token{}, d.newSyntaxError("invalid field name: %s", errRegexp.Find(d.in))
|
||||
return Token{}, d.newSyntaxError("invalid field name: %s", errId(d.in))
|
||||
}
|
||||
|
||||
// parseTypeName parses Any type URL or extension field name. The name is
|
||||
@ -571,7 +570,7 @@ func (d *Decoder) parseScalar() (Token, error) {
|
||||
return tok, nil
|
||||
}
|
||||
|
||||
return Token{}, d.newSyntaxError("invalid scalar value: %s", errRegexp.Find(d.in))
|
||||
return Token{}, d.newSyntaxError("invalid scalar value: %s", errId(d.in))
|
||||
}
|
||||
|
||||
// parseLiteralValue parses a literal value. A literal value is used for
|
||||
@ -653,8 +652,29 @@ func consume(b []byte, n int) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
// Any sequence that looks like a non-delimiter (for error reporting).
|
||||
var errRegexp = regexp.MustCompile(`^([-+._a-zA-Z0-9\/]+|.)`)
|
||||
// errId extracts a byte sequence that looks like an invalid ID
|
||||
// (for the purposes of error reporting).
|
||||
func errId(seq []byte) []byte {
|
||||
const maxLen = 32
|
||||
for i := 0; i < len(seq); {
|
||||
if i > maxLen {
|
||||
return append(seq[:i:i], "…"...)
|
||||
}
|
||||
r, size := utf8.DecodeRune(seq[i:])
|
||||
if r > utf8.RuneSelf || (r != '/' && isDelim(byte(r))) {
|
||||
if i == 0 {
|
||||
// Either the first byte is invalid UTF-8 or a
|
||||
// delimiter, or the first rune is non-ASCII.
|
||||
// Return it as-is.
|
||||
i = size
|
||||
}
|
||||
return seq[:i:i]
|
||||
}
|
||||
i += size
|
||||
}
|
||||
// No delimiter found.
|
||||
return seq
|
||||
}
|
||||
|
||||
// isDelim returns true if given byte is a delimiter character.
|
||||
func isDelim(c byte) bool {
|
||||
|
6
vendor/google.golang.org/protobuf/internal/encoding/text/decode_number.go
generated
vendored
6
vendor/google.golang.org/protobuf/internal/encoding/text/decode_number.go
generated
vendored
@ -50,8 +50,10 @@ type number struct {
|
||||
|
||||
// parseNumber constructs a number object from given input. It allows for the
|
||||
// following patterns:
|
||||
// integer: ^-?([1-9][0-9]*|0[xX][0-9a-fA-F]+|0[0-7]*)
|
||||
// float: ^-?((0|[1-9][0-9]*)?([.][0-9]*)?([eE][+-]?[0-9]+)?[fF]?)
|
||||
//
|
||||
// integer: ^-?([1-9][0-9]*|0[xX][0-9a-fA-F]+|0[0-7]*)
|
||||
// float: ^-?((0|[1-9][0-9]*)?([.][0-9]*)?([eE][+-]?[0-9]+)?[fF]?)
|
||||
//
|
||||
// It also returns the number of parsed bytes for the given number, 0 if it is
|
||||
// not a number.
|
||||
func parseNumber(input []byte) number {
|
||||
|
4
vendor/google.golang.org/protobuf/internal/encoding/text/doc.go
generated
vendored
4
vendor/google.golang.org/protobuf/internal/encoding/text/doc.go
generated
vendored
@ -24,6 +24,6 @@
|
||||
// the Go implementation should as well.
|
||||
//
|
||||
// The text format is almost a superset of JSON except:
|
||||
// * message keys are not quoted strings, but identifiers
|
||||
// * the top-level value must be a message without the delimiters
|
||||
// - message keys are not quoted strings, but identifiers
|
||||
// - the top-level value must be a message without the delimiters
|
||||
package text
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user