config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config manages CLI configuration and credentials.

Stores config and credentials per-server under the user's config directory (~/.config/life-ustc on Linux/Mac). Credentials are written atomically with 0600 permissions.

Index

Constants

View Source
const (
	AppName       = "life-ustc"
	DefaultServer = "https://life-ustc.tiankaima.dev"
)

Variables

This section is empty.

Functions

func Dir

func Dir() string

Dir returns the configuration directory, creating it if needed.

func GetDefaultServer

func GetDefaultServer() string

GetDefaultServer returns the server URL using this precedence:

  1. LIFE_USTC_SERVER environment variable
  2. Config file server field
  3. Built-in DefaultServer

The --server flag overrides all of these at the command level.

func GetSchoolPrograms added in v0.2.0

func GetSchoolPrograms() []string

func IsTokenExpired

func IsTokenExpired(cred *Credential) bool

func RemoveCredentials

func RemoveCredentials(server string) (bool, error)

func SaveConfig

func SaveConfig(cfg *Config) error

func SaveCredentials

func SaveCredentials(server string, cred *Credential) error

func SetDefaultServer

func SetDefaultServer(server string) error

func SetSchoolPrograms added in v0.2.0

func SetSchoolPrograms(programs []string) error

Types

type Config

type Config struct {
	Server         string   `json:"server,omitempty"`
	SchoolPrograms []string `json:"schoolPrograms,omitempty"`
}

func LoadConfig

func LoadConfig() (*Config, error)

type Credential

type Credential struct {
	ClientID     string  `json:"client_id"`
	AccessToken  string  `json:"access_token"`
	RefreshToken string  `json:"refresh_token,omitempty"`
	TokenType    string  `json:"token_type"`
	ExpiresAt    float64 `json:"expires_at"`
	Scope        string  `json:"scope,omitempty"`
	Resource     string  `json:"resource,omitempty"`
}

func LoadCredentials

func LoadCredentials(server string) (*Credential, error)

Jump to

Keyboard shortcuts

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