config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config manages application configuration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureEnvFile

func EnsureEnvFile() error

EnsureEnvFile creates the .env file if it doesn't exist

func GetCFHandle

func GetCFHandle() string

GetCFHandle returns the configured CF handle

func GetEnvFilePath

func GetEnvFilePath() (string, error)

GetEnvFilePath returns the path to the .env file

func GetWorkspacePath

func GetWorkspacePath() string

GetWorkspacePath returns the workspace path

func Init

func Init(workspacePath string) error

Init initializes the configuration

func MigrateFromLegacy

func MigrateFromLegacy() (bool, error)

MigrateFromLegacy migrates config from ~/.dsaprep to ~/.cf Returns true if migration was performed

func SaveCredentials

func SaveCredentials(creds *Credentials) error

SaveCredentials saves credentials to the .env file

func Set

func Set(key string, value interface{}) error

Set updates a configuration value

func SetCFHandle

func SetCFHandle(handle string) error

SetCFHandle sets the CF handle

func SetDailyGoal

func SetDailyGoal(goal int) error

SetDailyGoal sets the daily goal

func SetDifficulty

func SetDifficulty(min, max int) error

SetDifficulty sets the difficulty range

func SetWorkspacePath

func SetWorkspacePath(path string) error

SetWorkspacePath sets the workspace path

Types

type Config

type Config struct {
	// Codeforces settings
	CFHandle string `mapstructure:"cf_handle"`

	// Practice settings
	Difficulty DifficultyRange `mapstructure:"difficulty"`
	DailyGoal  int             `mapstructure:"daily_goal"`

	// Paths
	WorkspacePath string `mapstructure:"workspace_path"`
}

Config holds the application configuration

func Get

func Get() *Config

Get returns the global configuration

type Credentials

type Credentials struct {
	// API authentication
	APIKey    string
	APISecret string
	CFHandle  string

	// Session cookies (extracted from browser)
	JSESSIONID string // JSESSIONID cookie for CF session
	CE7Cookie  string // 39ce7 cookie for CF session

	// Cloudflare bypass
	CFClearance        string // cf_clearance cookie value
	CFClearanceExpires int64  // Unix timestamp when cf_clearance expires
	CFClearanceUA      string // User-Agent tied to cf_clearance (MUST match)
}

Credentials holds CF API and cookie-based web credentials

func LoadCredentials

func LoadCredentials() (*Credentials, error)

LoadCredentials loads credentials from the .env file

func (*Credentials) CFClearanceExpiresIn

func (c *Credentials) CFClearanceExpiresIn() time.Duration

CFClearanceExpiresIn returns time until cf_clearance expires (negative if expired)

func (*Credentials) GetCFClearanceStatus

func (c *Credentials) GetCFClearanceStatus() string

GetCFClearanceStatus returns a human-readable status string

func (*Credentials) HasHandle

func (c *Credentials) HasHandle() bool

HasHandle returns true if CF handle is set

func (*Credentials) HasSessionCookies

func (c *Credentials) HasSessionCookies() bool

HasSessionCookies returns true if session cookies are set

func (*Credentials) IsAPIConfigured

func (c *Credentials) IsAPIConfigured() bool

IsAPIConfigured returns true if API credentials are set

func (*Credentials) IsCFClearanceValid

func (c *Credentials) IsCFClearanceValid() bool

IsCFClearanceValid returns true if cf_clearance cookie is set and not expired

func (*Credentials) IsReadyForSubmission

func (c *Credentials) IsReadyForSubmission() bool

IsReadyForSubmission returns true if we have everything needed to submit Requires: cf_clearance (valid) + session cookies + handle

func (*Credentials) SetCFClearance

func (c *Credentials) SetCFClearance(clearance, userAgent string, expiresAt time.Time)

SetCFClearance sets the cf_clearance cookie with expiration and User-Agent

type DifficultyRange

type DifficultyRange struct {
	Min int `mapstructure:"min"`
	Max int `mapstructure:"max"`
}

DifficultyRange represents min/max difficulty

Jump to

Keyboard shortcuts

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