Giter Site home page Giter Site logo

hook's Introduction

Hook

codecov

It is a package that send in one way term any payload to one or more targets. It works by subscription and scope.

subscribe a http target

package main

import (
    "context"
    "os"

    "github.com/w6d-io/hook"
    "github.com/w6d-io/x/logx"
)

type payload struct {
    Name string `json:"name"`
    Kind string `json:"kind"`
}

func main() {
    ctx := context.Background()
    log := logx.WithName(ctx, "Main")
    URL := "http://localhost:8080/test"
    // add a target for the payload for all scope
    if err := hook.Subscribe(ctx, URL, "test"); err != nil {
        log.Error(err, "Subscription failed", "target", URL)
        os.Exit(1)
    }
    kafka := "kafka://localhost:9092?topic=TEST&messagekey=msgid"
    // add a target for the payload for all scope
    if err := hook.Subscribe(ctx, kafka, ".*"); err != nil {
        log.Error(err, "Subscription failed", "target", kafka)
        os.Exit(1)
    }

    p := &payload{
        Name: "payload",
        Kind: "test",
    }
    // Send payload with test as scope the payload is send to http and kafka
    if err := hook.Send(ctx, p, "test"); err != nil {
        log.Error(err, "Send failed")
        os.Exit(1)
    }

    // Send payload with failed as scope. Only sends to kafka due to the scope
    if err := hook.Send(ctx, p, "failed"); err != nil {
        log.Error(err, "Send failed")
        os.Exit(1)
    }

}

The subscribe function gets the scope in regex format

hook's People

Contributors

david972 avatar py4mac avatar

Watchers

 avatar  avatar

hook's Issues

discussion : use the alert manager config

Why change the configuration by using the one of alert manager

route:
  # Main route
  routes:
    # This route allows dumping all events because it has no fields to match and no drop rules.
    - match:
      - receiver: dump
    # This starts another route, drops all the events in *test* namespaces and Normal events
    # for capturing critical events
    - drop:
      - namespace: "*test*"
      - type: "Normal"
      match:
      - receiver: "critical-events-queue"
    # This a final route for user messages
    - match:
        kind: "Pod|Deployment|ReplicaSet"
        labels:
          version: "dev"
        receiver: "slack"
receivers:
# See below for configuring the receivers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.