-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: hanpengfei01 <[email protected]>
- Loading branch information
Showing
18 changed files
with
954 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package client | ||
|
||
import ( | ||
"bytes" | ||
"crypto/tls" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/baetyl/baetyl-go/v2/context" | ||
"github.com/baetyl/baetyl-go/v2/errors" | ||
"github.com/baetyl/baetyl-go/v2/http" | ||
"github.com/baetyl/baetyl-go/v2/mqtt" | ||
"github.com/baetyl/baetyl-go/v2/utils" | ||
) | ||
|
||
type HTTPClient struct { | ||
cli *http.Client | ||
address string | ||
} | ||
|
||
func NewHTTPClient(ctx context.Context, cfg *mqtt.ClientConfig) (Client, error) { | ||
options := http.NewClientOptions() | ||
options.Address = cfg.Address | ||
if strings.HasPrefix(cfg.Address, "https") { | ||
var tlsCfg *tls.Config | ||
var err error | ||
if cfg.CA == "" || cfg.Cert == "" || cfg.Key == "" { | ||
cert := ctx.SystemConfig().Certificate | ||
cert.InsecureSkipVerify = true | ||
tlsCfg, err = utils.NewTLSConfigClient(cert) | ||
} else { | ||
tlsCfg, err = utils.NewTLSConfigClient(utils.Certificate{ | ||
CA: cfg.CA, | ||
Cert: cfg.Cert, | ||
Key: cfg.Key, | ||
InsecureSkipVerify: cfg.InsecureSkipVerify, | ||
}) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
options.TLSConfig = tlsCfg | ||
} | ||
cli := http.NewClient(options) | ||
return &HTTPClient{ | ||
cli: cli, | ||
address: cfg.Address, | ||
}, nil | ||
} | ||
|
||
func (h *HTTPClient) SendOrDrop(method string, pkt *mqtt.Publish) error { | ||
header := map[string]string{"Content-Type": "application/json"} | ||
res, err := h.cli.SendUrl(strings.ToUpper(method), fmt.Sprintf("%s%s", h.address, pkt.Message.Topic), bytes.NewReader(pkt.Message.Payload), header) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
if res.StatusCode != 200 { | ||
return errors.New(res.Status) | ||
} | ||
return nil | ||
} | ||
|
||
func (h *HTTPClient) SendPubAck(pkt mqtt.Packet) error { | ||
return nil | ||
} | ||
|
||
func (h *HTTPClient) Start(obs mqtt.Observer) { | ||
return | ||
} | ||
|
||
func (h *HTTPClient) ResetClient(cfg *mqtt.ClientConfig) { | ||
return | ||
} | ||
|
||
func (h *HTTPClient) SetReconnectCallback(callback mqtt.ReconnectCallback) { | ||
return | ||
} | ||
|
||
// Close closes client | ||
func (h *HTTPClient) Close() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,58 @@ | ||
module github.com/baetyl/baetyl-rule/v2 | ||
|
||
go 1.13 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/256dpi/gomqtt v0.14.3 | ||
github.com/baetyl/baetyl-broker/v2 v2.0.1-rc3 | ||
github.com/baetyl/baetyl-go/v2 v2.2.4-0.20220114042103-4ba035e5dfb7 | ||
github.com/baetyl/baetyl-go/v2 v2.2.4-0.20220507105142-99d4addbb3bf | ||
github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87 | ||
github.com/stretchr/testify v1.6.1 | ||
github.com/valyala/fasthttp v1.9.0 | ||
) | ||
|
||
require ( | ||
github.com/256dpi/mercury v0.2.0 // indirect | ||
github.com/containerd/containerd v1.3.4 // indirect | ||
github.com/creasty/defaults v1.4.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/docker/distribution v2.7.1+incompatible // indirect | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.4.0 // indirect | ||
github.com/dsnet/compress v0.0.1 // indirect | ||
github.com/gogo/protobuf v1.3.1 // indirect | ||
github.com/golang/protobuf v1.3.2 // indirect | ||
github.com/golang/snappy v0.0.1 // indirect | ||
github.com/gorilla/websocket v1.4.1 // indirect | ||
github.com/jinzhu/copier v0.1.0 // indirect | ||
github.com/jpillora/backoff v1.0.0 // indirect | ||
github.com/klauspost/compress v1.8.2 // indirect | ||
github.com/klauspost/cpuid v1.2.1 // indirect | ||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect | ||
github.com/mholt/archiver v3.1.1+incompatible // indirect | ||
github.com/nwaples/rardecode v1.1.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.0.1 // indirect | ||
github.com/pierrec/lz4 v2.5.2+incompatible // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/sirupsen/logrus v1.6.0 // indirect | ||
github.com/ulikunitz/xz v0.5.7 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect | ||
go.etcd.io/bbolt v1.3.4 // indirect | ||
go.uber.org/atomic v1.6.0 // indirect | ||
go.uber.org/multierr v1.5.0 // indirect | ||
go.uber.org/zap v1.16.0 // indirect | ||
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect | ||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect | ||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect | ||
google.golang.org/grpc v1.25.1 // indirect | ||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect | ||
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect | ||
gopkg.in/validator.v2 v2.0.0-20191107172027-c3144fdedc21 // indirect | ||
gopkg.in/yaml.v2 v2.2.8 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect | ||
k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d // indirect | ||
k8s.io/klog v0.3.1 // indirect | ||
) |
Oops, something went wrong.