v1.7.1 Latest Latest

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 24 Imported by: 0



Package watch provides the watch command for watching multiple live FC2 streams.



This section is empty.


View Source
var Command = &cli.Command{
	Name:  "watch",
	Usage: "Automatically download multiple Live FC2 streams.",
	Flags: []cli.Flag{
			Name:        "config",
			Aliases:     []string{"c"},
			Required:    true,
			Usage:       `Config file path. (required)`,
			Destination: &configPath,
			Name:        "pprof.listen-address",
			Value:       ":3000",
			Destination: &pprofListenAddress,
	Action: func(cCtx *cli.Context) error {
		ctx, cancel := context.WithCancel(cCtx.Context)

		cleanChan := make(chan os.Signal, 1)
		signal.Notify(cleanChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
		go func() {

		configChan := make(chan *Config)
		go ObserveConfig(ctx, configPath, configChan)

		go func() {
			http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
				s := state.DefaultState.ReadState()
				b, err := json.MarshalIndent(s, "", "  ")
				if err != nil {
					http.Error(w, err.Error(), http.StatusInternalServerError)
				_, err = w.Write(b)
				if err != nil {
					http.Error(w, err.Error(), http.StatusInternalServerError)
			log.Info().Str("listenAddress", pprofListenAddress).Msg("listening")
			if err := http.ListenAndServe(pprofListenAddress, nil); err != nil {
				log.Fatal().Err(err).Msg("fail to serve http")
			log.Fatal().Msg("http server stopped")

		return ConfigReloader(ctx, configChan, handleConfig)

Command is the command for watching multiple live FC2 streams.


func ConfigReloader

func ConfigReloader(
	ctx context.Context,
	configChan <-chan *Config,
	handleConfig func(ctx context.Context, config *Config),
) error

ConfigReloader reloads the config when a new one is detected.

func ObserveConfig added in v1.6.4

func ObserveConfig(ctx context.Context, filename string, configChan chan<- *Config)

ObserveConfig watches the config file for changes and sends the new config to the configChan.


type Config

type Config struct {
	Notifier      NotifierConfig                `yaml:"notifier,omitempty"`
	DefaultParams fc2.OptionalParams            `yaml:"defaultParams,omitempty"`
	Channels      map[string]fc2.OptionalParams `yaml:"channels,omitempty"`

Config is the configuration for the watch command.

type NotifierConfig added in v1.1.0

type NotifierConfig struct {
	Enabled                    bool     `yaml:"enabled,omitempty"`
	IncludeTitleInMessage      bool     `yaml:"includeTitleInMessage,omitempty"`
	NoPriority                 bool     `yaml:"noPriority,omitempty"`
	URLs                       []string `yaml:"urls,omitempty"`
	notify.NotificationFormats `yaml:"notificationFormats,omitempty"`

NotifierConfig is the configuration for the notifier.

Jump to

Keyboard shortcuts

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