util

package
v1.16.16 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterLog added in v1.15.6

func AfterLog()

func BeforeLog added in v1.15.6

func BeforeLog()

func BuildDataURL added in v1.16.8

func BuildDataURL(mimeType string, data []byte) string

BuildDataURL constructs a data URL string from MIME type and raw bytes. Example: "image/png", []byte -> "data:image/png;base64,iVBORw0KGgo..."

func Contains added in v1.15.6

func Contains(list []string, item string, ignoreCase bool) bool

func DecodeBase64String added in v1.16.8

func DecodeBase64String(data string) ([]byte, error)

DecodeBase64String decodes a base64 encoded string to raw bytes.

func DownloadAndExtractZip

func DownloadAndExtractZip(urlStr, destDir string) error

DownloadAndExtractZip downloads a zip file from the given URL and extracts it to the target directory. It creates the target directory if it doesn't exist. This function expects the zip file to contain a single root directory (like GitHub zips do) and extracts the *contents* of that root directory directly into destDir.

func EndWithNewline added in v1.15.6

func EndWithNewline(s string) bool

func Errorf added in v1.15.6

func Errorf(cmd *cobra.Command, format string, args ...interface{})

Errorf prints an error message to the command's designated error output stream.

func Errorln added in v1.15.6

func Errorln(cmd *cobra.Command, args ...interface{})

Errorln prints an error message with a newline to the command's error output stream.

func ExtractThinkTags added in v1.15.6

func ExtractThinkTags(content string) (thinking, cleaned string)

ExtractThinkTags extracts thinking content from <think>...</think> tags. Some providers (like MiniMax, some Qwen endpoints) embed reasoning content in <think> tags within the regular content field instead of using a separate reasoning_content field.

Returns:

  • thinking: the extracted thinking content (empty if no tags found)
  • cleaned: the content with <think> tags removed

func FormatMinutesSeconds added in v1.15.6

func FormatMinutesSeconds(d time.Duration) string

func GenerateTempFileName added in v1.15.6

func GenerateTempFileName() string

func GetBase64String added in v1.16.8

func GetBase64String(data []byte) string

GetBase64String returns the base64 encoded string of the given data.

func GetFileContent added in v1.15.6

func GetFileContent(filePath string) (string, error)

func GetGitHubZipURL

func GetGitHubZipURL(urlStr string) string

GetGitHubZipURL converts a GitHub repository clone URL to its zip archive download URL.

func GetSanitizeTitle added in v1.15.6

func GetSanitizeTitle(title string) string

func GetStringValue added in v1.15.6

func GetStringValue(data map[string]any, key string) string

Helper function to safely extract string values

func GetUserConfigDir added in v1.15.6

func GetUserConfigDir() string

func HasContent added in v1.15.6

func HasContent(s *string) bool

func HasGit

func HasGit() bool

HasGit checks if the git executable is available in the system PATH.

func InitLogger added in v1.15.6

func InitLogger()

func InjectThinkTags added in v1.15.12

func InjectThinkTags(content, thinking string) string

InjectThinkTags cleanly prepends reasoning logic wrapped in <think> tags to the primary content area. This is essential for officially preserving continuous "internal monologue" back to OpenRouter/DeepSeek instances within generic API clients that only accept a single `content` string.

func IsEmpty added in v1.16.10

func IsEmpty(s string) bool

func IsGitHubURL

func IsGitHubURL(urlStr string) bool

IsGitHubURL checks if the given URL is a standard GitHub repository URL.

func JoinFilePath added in v1.15.6

func JoinFilePath(dir string, filename string) string

func LogDebugf added in v1.16.16

func LogDebugf(format string, args ...interface{})

func LogDebugln added in v1.16.16

func LogDebugln(args ...interface{})

func LogErrorf added in v1.16.16

func LogErrorf(format string, args ...interface{})

func LogErrorln added in v1.16.16

func LogErrorln(args ...interface{})

func LogInfof added in v1.16.16

func LogInfof(format string, args ...interface{})

func LogInfoln added in v1.16.16

func LogInfoln(args ...interface{})

func LogSuccessf added in v1.16.16

func LogSuccessf(format string, args ...interface{})

func LogSuccessln added in v1.16.16

func LogSuccessln(args ...interface{})

func LogWarnf added in v1.16.16

func LogWarnf(format string, args ...interface{})

func LogWarnln added in v1.16.16

func LogWarnln(args ...interface{})

func MakeUserSubDir added in v1.15.6

func MakeUserSubDir(subparts ...string) string

func ParseDataURL added in v1.16.8

func ParseDataURL(dataURL string) (string, []byte, error)

ParseDataURL extracts the MIME type and base64-decoded raw bytes from a data URL string. Example: "data:image/png;base64,iVBORw0KGgo..." -> "image/png", []byte, nil

func Print added in v1.16.16

func Print(cmd *cobra.Command, args ...interface{})

Print formats and prints text to the command's designated standard output stream.

func Printf added in v1.16.16

func Printf(cmd *cobra.Command, format string, args ...interface{})

Printf formats and prints text to the command's designated standard output stream.

func Println added in v1.16.16

func Println(cmd *cobra.Command, args ...interface{})

Println prints text with a trailing newline to the command's designated standard output stream.

func RegisterLoggerHook added in v1.15.9

func RegisterLoggerHook(h LoggerHook)

RegisterLoggerHook registers a hook to be called before and after logging.

func SetLoggerLevel added in v1.15.6

func SetLoggerLevel(level log.Level)

func Successf added in v1.15.6

func Successf(cmd *cobra.Command, format string, args ...interface{})

Successf prints a success message to the command's output stream.

func Successln added in v1.15.6

func Successln(cmd *cobra.Command, args ...interface{})

Successln prints a success message with a newline to the command's output stream.

func TruncateString added in v1.15.6

func TruncateString(s string, maxLen int) string

Helper function to truncate strings with ellipsis

func ValidateResourceName added in v1.15.16

func ValidateResourceName(resourceType, name string) error

ValidateResourceName checks if the name is filesystem-safe.

func Warnf added in v1.15.6

func Warnf(cmd *cobra.Command, format string, args ...interface{})

Warnf prints a warning message to the command's designated error output stream.

func Warnln added in v1.15.6

func Warnln(cmd *cobra.Command, args ...interface{})

Warnln prints a warning message with a newline to the command's error output stream.

func WriteFileContent added in v1.16.9

func WriteFileContent(path, content string) error

Types

type LoggerHook added in v1.15.9

type LoggerHook interface {
	BeforeLog() bool // Returns true if indicator was active
	AfterLog(wasActive bool)
}

LoggerHook defines an interface for external components to intercept logging and handle UI-specific tasks like stopping/restarting indicators.

type ProgressWriter

type ProgressWriter struct {
	Total      int64
	Downloaded int64
}

ProgressWriter tracks the number of bytes written to it.

func (*ProgressWriter) Write

func (pw *ProgressWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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