config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 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

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

Types

type Config

type Config struct {
	Server string `json:"server,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