mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
feat: add path
This commit is contained in:
parent
391f82e2f0
commit
5125125257
@ -22,7 +22,8 @@ var (
|
||||
type (
|
||||
Publisher struct {
|
||||
l *zap.Logger
|
||||
url string
|
||||
host string
|
||||
path string
|
||||
client *http.Client
|
||||
marshalMessageFunc PublisherMarshalMessageFunc
|
||||
closed bool
|
||||
@ -36,10 +37,11 @@ type (
|
||||
// ~ Constructor
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
func NewPublisher(l *zap.Logger, url string, opts ...PublisherOption) *Publisher {
|
||||
func NewPublisher(l *zap.Logger, host string, opts ...PublisherOption) *Publisher {
|
||||
inst := &Publisher{
|
||||
l: l,
|
||||
url: url,
|
||||
host: host,
|
||||
path: "/g/collect",
|
||||
client: http.DefaultClient,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
@ -52,6 +54,12 @@ func NewPublisher(l *zap.Logger, url string, opts ...PublisherOption) *Publisher
|
||||
// ~ Options
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
func PublisherWithPath(v string) PublisherOption {
|
||||
return func(o *Publisher) {
|
||||
o.path = v
|
||||
}
|
||||
}
|
||||
|
||||
func PublisherWithClient(v *http.Client) PublisherOption {
|
||||
return func(o *Publisher) {
|
||||
o.client = v
|
||||
@ -92,7 +100,7 @@ func (p *Publisher) Publish(topic string, messages ...*message.Message) error {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(msg.Context(), http.MethodPost, fmt.Sprintf("%s?%s", p.url, mpv2.EncodeValues(values)), body)
|
||||
req, err := http.NewRequestWithContext(msg.Context(), http.MethodPost, fmt.Sprintf("%s%s?%s", p.host, p.path, mpv2.EncodeValues(values)), body)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create request")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user