Documentation
¶
Overview ¶
Package watch provides the watch command for watching multiple live FC2 streams.
Index ¶
- Variables
- func ConfigReloader(ctx context.Context, configChan <-chan *Config, ...) error
- func LoginLoop(ctx context.Context, c *api.Client, jar PersistentCookieJar, ...)
- func ObserveConfig(ctx context.Context, filename string, configChan chan<- *Config)
- type Config
- type NotifierConfig
- type PersistentCookieJar
- type RateLimitAvoidance
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cli.Command{ Name: "watch", Usage: "Automatically download multiple Live FC2 streams.", Flags: []cli.Flag{ &cli.StringFlag{ Name: "config", Aliases: []string{"c"}, Required: true, Usage: `Config file path. (required)`, Destination: &configPath, }, &cli.StringFlag{ Name: "pprof.listen-address", Value: ":3000", Destination: &pprofListenAddress, Usage: "The address to listen on for pprof.", EnvVars: []string{"PPROF_LISTEN_ADDRESS"}, }, &cli.StringFlag{ Name: "cookie.encryption-secret", Value: "FC2_LIVE_DL_GO_COOKIE_ENCRYPTION_SECRET", Destination: &cookieEncryptionSecret, Usage: "A encryption secret to encrypt the cookies.", EnvVars: []string{"COOKIE_ENCRYPTION_SECRET"}, }, &cli.BoolFlag{ Name: "traces.export", Usage: "Enable traces push. (To configure the exporter, set the OTEL_EXPORTER_OTLP_ENDPOINT environment variable, see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/)", Value: false, Destination: &enableTracesExporting, EnvVars: []string{"OTEL_EXPORTER_OTLP_TRACES_ENABLED"}, }, &cli.BoolFlag{ Name: "metrics.export", Usage: "Enable metrics push. (To configure the exporter, set the OTEL_EXPORTER_OTLP_ENDPOINT environment variable, see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/). Note that a Prometheus path is already exposed at /metrics.", Value: false, Destination: &enableMetricsExporting, EnvVars: []string{"OTEL_EXPORTER_OTLP_METRICS_ENABLED"}, }, }, 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() { <-cleanChan cancel() }() prom, err := prometheus.New() if err != nil { log.Fatal().Err(err).Msg("failed to create prometheus exporter") } telOpts := []telemetry.Option{ telemetry.WithMetricReader(prom), } if enableMetricsExporting { metricExporter, err := otlpmetricgrpc.New(ctx) if err != nil { log.Fatal().Err(err).Msg("failed to create OTEL metric exporter") } telOpts = append(telOpts, telemetry.WithMetricExporter(metricExporter)) } if enableTracesExporting { traceExporter, err := otlptracegrpc.New(ctx) if err != nil { log.Fatal().Err(err).Msg("failed to create OTEL trace exporter") } telOpts = append(telOpts, telemetry.WithTraceExporter(traceExporter)) } shutdown, err := telemetry.SetupOTELSDK(ctx, telOpts..., ) if err != nil { log.Fatal().Err(err).Msg("failed to setup OTEL SDK") } defer func() { if err := shutdown(ctx); err != nil && !errors.Is(err, context.Canceled) { log.Error().Err(err).Msg("failed to shutdown OTEL SDK") } }() configChan := make(chan *Config) go ObserveConfig(ctx, configPath, configChan) go func() { http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { s := state.DefaultState.ReadState() enc := json.NewEncoder(w) enc.SetIndent("", " ") if err := enc.Encode(s); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } }) http.Handle("/metrics", promhttp.Handler()) 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, func(ctx context.Context, config *Config) { handleConfig(ctx, cCtx.App.Version, config) }) }, }
Command is the command for watching multiple live FC2 streams.
Functions ¶
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.
Types ¶
type Config ¶
type Config struct { CookiesImportFile string `yaml:"cookiesImportFile,omitempty"` CookiesRefreshDuration time.Duration `yaml:"cookiesRefreshDuration,omitempty"` CookiesFile string `yaml:"cookiesFile,omitempty"` Notifier NotifierConfig `yaml:"notifier,omitempty"` RateLimitAvoidance RateLimitAvoidance `yaml:"rateLimitAvoidance,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 ¶
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.
type PersistentCookieJar ¶
PersistentCookieJar is a CookieJar that persists the cookies to a file.
type RateLimitAvoidance ¶
RateLimitAvoidance is the configuration for the rate limit avoidance.
Click to show internal directories.
Click to hide internal directories.