relay

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

Relay Package

This package implements a service that receives GitHub webhook events from a Pub/Sub push subscription, enriches them with metadata, and publishes them to another Pub/Sub topic.

Purpose

To process raw webhook events and add useful attributes (like organization, repository, and enterprise IDs and names) before forwarding them. This allows for better filtering and routing of events downstream.

Files

  • config.go: Defines the configuration for the relay service (port, topic IDs, etc.).
  • config_test.go: Unit tests for the configuration logic.
  • enricher.go: Contains the core logic for parsing the raw GitHub event payload and extracting organization, repository, and enterprise information to create an EnrichedEvent. It also generates Pub/Sub message attributes.
  • relay.go: Contains the HTTP handler (handleRelay) that receives the Pub/Sub message, calls the enricher, and sends the enriched message to the target topic.
  • relay_test.go: Unit tests for the relay handler and enrichment logic.
  • server.go: Handles the HTTP server setup and routing for the relay service.

Design Patterns

  • Event Enrichment: Extracts key fields from a nested JSON payload and elevates them to top-level fields and message attributes, making downstream processing more efficient.
  • Push-to-Push Processing: Acts as a bridge between two Pub/Sub topics, triggered by a push subscription and publishing to another topic.

Documentation

Overview

Package relay contains the HTTP handler and logic for the relay service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port           string
	ProjectID      string
	RelayTopicID   string
	RelayProjectID string
	PubSubTimeout  time.Duration
}

Config defines the set over environment variables required for running this application.

func (*Config) ToFlags

func (cfg *Config) ToFlags(set *cli.FlagSet) *cli.FlagSet

ToFlags binds the config to the give cli.FlagSet and returns it.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate validates the service config after load.

type MessageEnricher

type MessageEnricher interface {
	Enrich(ctx context.Context, req []byte) ([]byte, map[string]string, error)
}

func NewDefaultMessageEnricher

func NewDefaultMessageEnricher() MessageEnricher

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server acts as a HTTP server for handling relay requests.

func NewServer

func NewServer(ctx context.Context, cfg *Config) (*Server, error)

NewServer creates a new instance of the Server.

func (*Server) Routes

func (s *Server) Routes(ctx context.Context) http.Handler

Routes creates a ServeMux of all of the routes that this Router supports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL