utilities

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApiUrl = "https://endoflife.date/api/v1/"

Functions

func AnalyzeCacheProductsValidity added in v1.1.0

func AnalyzeCacheProductsValidity(cmd *cobra.Command)

func CheckCacheTimeAndUpdateGeneric added in v1.1.0

func CheckCacheTimeAndUpdateGeneric(modTime time.Time, maxAge time.Duration, cmd *cobra.Command)

CheckCacheTimeAndUpdateGeneric logs the cache mod time and updates the cache if older than maxAge using RefreshAllCaches.

func CreateDoNotEditFile added in v1.1.0

func CreateDoNotEditFile() error

CreateDoNotEditFile creates a DO_NOT_EDIT_ANYTHING file in the geol config directory to warn users not to edit anything there.

func EnsureCacheExistsGeneric added in v1.3.0

func EnsureCacheExistsGeneric(cachePath string, cmd *cobra.Command) (os.FileInfo, error)

ensureCacheExistsGeneric checks if the cache file exists, creates it if missing using RefreshAllCaches, and returns its FileInfo or an error.

func FetchAndSaveCategories added in v1.1.0

func FetchAndSaveCategories(cmd *cobra.Command) error

func FetchAndSaveProducts

func FetchAndSaveProducts(cmd *cobra.Command) error

func FetchAndSaveTags added in v1.1.0

func FetchAndSaveTags(cmd *cobra.Command) error

func GetAPIResponse

func GetAPIResponse(url string) (*http.Response, error)

GetAPIResponse performs an HTTP GET request to the given URL and returns the response if status is 200. The caller is responsible for closing the response body.

func GetCategoriesPath added in v1.1.0

func GetCategoriesPath() (string, error)

func GetProductsPath

func GetProductsPath() (string, error)

GetProductsPath returns the path to the products.json file in the user's config directory.

func GetTagsPath added in v1.1.0

func GetTagsPath() (string, error)

func InitLogger

func InitLogger(logLevel string)

func RefreshAllCaches added in v1.1.0

func RefreshAllCaches(cmd *cobra.Command)

RefreshAllCaches runs all cache refresh functions and exits with code 1 if any fail.

func RemoveFileIfExists

func RemoveFileIfExists(path string) error

RemoveFileIfExists removes the file at the given path if it exists. Returns nil if the file does not exist or is successfully removed.

func TodayDateString

func TodayDateString() string

TodayDateString retourne la date du jour au format YYYY-MM-DD

Types

type CategoriesFile added in v1.1.0

type CategoriesFile map[string]string

func GetCategoriesWithCacheRefresh added in v1.1.0

func GetCategoriesWithCacheRefresh(cmd *cobra.Command, categoriesPath string) (CategoriesFile, error)

GetCategoriesWithCacheRefresh tries to unmarshal categories from file, refreshes cache if needed, and returns the categories.

type Category added in v1.1.0

type Category struct {
	Name string `json:"name"`
	Uri  string `json:"uri"`
}

type Product

type Product struct {
	Name    string   `json:"name"`
	Aliases []string `json:"aliases"`
}

Product represents a product with its name and aliases from the API.

type ProductsFile

type ProductsFile struct {
	Products map[string][]string `json:"products"`
}

func GetProductsWithCacheRefresh

func GetProductsWithCacheRefresh(cmd *cobra.Command, productsPath string) (ProductsFile, error)

GetProductsWithCacheRefresh tries to unmarshal products from file, refreshes cache if needed, and returns the products.

type Tag added in v1.1.0

type Tag struct {
	Name string `json:"name"`
	Uri  string `json:"uri"`
}

type TagsFile added in v1.1.0

type TagsFile map[string]string

func GetTagsWithCacheRefresh added in v1.1.0

func GetTagsWithCacheRefresh(cmd *cobra.Command, tagsPath string) (TagsFile, error)

GetTagsWithCacheRefresh tries to unmarshal tags from file, refreshes cache if needed, and returns the tags.

Jump to

Keyboard shortcuts

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