service

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package service implements the common utils function for daemon services.

To use the service package, import the package and its dependencies, as shown in the following example:

package main

import (
        _ "github.com/wabarc/wayback/ingress"
        "github.com/wabarc/wayback/service"
)

func main() {
        // Initialize services with configuration options and a context.
        opts := service.Options{}
        ctx := context.Background()
        err := service.Serve(ctx, opts)
        // ...
}

Index

Constants

View Source
const (
	CommandHelp     = "help"
	CommandMetrics  = "metrics"
	CommandPlayback = "playback"

	MsgWaybackRetrying = "wayback timeout, retrying."
	MsgWaybackTimeout  = "wayback timeout, please try later."
)

Variables

View Source
var ErrMissingURL = fmt.Errorf("URL no found")

Functions

func ExcludeURL added in v0.18.0

func ExcludeURL(urls []*url.URL, host string) (ex []*url.URL)

ExcludeURL removes URLs based on hostname; it is only available for multiple URLs. The URLs given should be de-duplicated advance.

func MatchURL

func MatchURL(opts *config.Options, s string) (urls []*url.URL)

MatchURL returns a slice string contains URLs extracted from the given string.

func Register added in v0.20.0

func Register(srv config.Flag, action SetupFunc)

Register registers a service instance's setup function and allows it to be called.

func Serve added in v0.20.0

func Serve(ctx context.Context, opts Options) (errs error)

Serve runs service in a separate goroutine.

func Shutdown added in v0.20.0

func Shutdown() (errs error)

Shutdown shuts down all services.

func UploadToDiscord added in v0.17.0

func UploadToDiscord(opts *config.Options, art reduxer.Artifact) (files []*discord.File)

UploadToDiscord composes files that share with Discord by a given artifact.

func UploadToSlack added in v0.17.0

func UploadToSlack(client *slack.Client, opts *config.Options, art reduxer.Artifact, channel, timestamp, caption string) (err error)

UploadToSlack upload files to channel and attach as a reply by the given artifact

func UploadToTelegram added in v0.17.0

func UploadToTelegram(opts *config.Options, art reduxer.Artifact, caption string) telegram.Album

UploadToTelegram composes files into an album by the given artifact.

func Wayback added in v0.18.0

func Wayback(ctx context.Context, opts *config.Options, urls []*url.URL, do doFunc) error

Wayback in a separate goroutine.

Types

type Module added in v0.20.0

type Module struct {
	Servicer

	Opts Options
	Flag config.Flag
}

Module is a struct embeds the Servicer interface and holds a pointer to Options.

type Option added in v0.19.0

type Option func(*Options)

Option is a function that modifies the provided Options instance.

func Config added in v0.19.0

func Config(c *config.Options) Option

Config returns an Option function that sets the Config field of Options.

func Pool added in v0.19.0

func Pool(p *pooling.Pool) Option

Pool returns an Option function that sets the Pool field of Options.

func Publish added in v0.19.0

func Publish(p *publish.Publish) Option

Publish returns an Option function that sets the Publish field of Options.

func Storage added in v0.19.0

func Storage(s *storage.Storage) Option

Storage returns an Option function that sets the Storage field of Options.

type Options added in v0.19.0

type Options struct {
	// Config holds the configuration options.
	Config *config.Options

	// Pool holds the connection pool to be used.
	Pool *pooling.Pool

	// Publish holds the publish service to be used.
	Publish *publish.Publish

	// Storage holds the storage service to be used.
	Storage *storage.Storage
}

Options represents the configuration for services.

func ParseOptions added in v0.19.0

func ParseOptions(opts ...Option) (o Options)

ParseOptions returns the Options instance with modifications applied using the provided Option functions.

type Servicer added in v0.20.0

type Servicer interface {
	// Serve serve a service.
	Serve() error

	// Shutdown shuts down service.
	Shutdown() error
}

Servicer is the interface that wraps Serve and Shutdown method.

Servicer serve several media platforms, e.g. Telegram, Discord, etc.

type SetupFunc added in v0.20.0

type SetupFunc func(context.Context, Options) (*Module, error)

SetupFunc is a function type that takes a pointer to a Options struct and returns a pointer to a Module struct.

Directories

Path Synopsis
Package discord implements the discord bot daemon service.
Package discord implements the discord bot daemon service.
Package httpd implements the tor network service.
Package httpd implements the tor network service.
Package mastodon implements the mastodon daemon service.
Package mastodon implements the mastodon daemon service.
Package matrix implements the matrix daemon service.
Package matrix implements the matrix daemon service.
Package relaychat implements the internet relay chat daemon service.
Package relaychat implements the internet relay chat daemon service.
Package slack implements the slack bot daemon service.
Package slack implements the slack bot daemon service.
Package telegram implements the telegram bot daemon service.
Package telegram implements the telegram bot daemon service.
Package twitter implements the twitter daemon service.
Package twitter implements the twitter daemon service.
Package xmpp implements the xmpp daemon service.
Package xmpp implements the xmpp daemon service.

Jump to

Keyboard shortcuts

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