util/README.md

1.6 KiB

Go utility library

yoorie.de logo

Build Status

Project Description

This repository provides a small, cross-platform utility package for Go projects. It focuses on common helpers that are often reimplemented in multiple services, such as file checks, safe path joining for URL-like strings, and OS-specific configuration directory handling.

The package is intentionally lightweight and easy to reuse in CLI tools, daemons, and backend services.

Included Utilities

  • FileExists(fileName string) bool
    • Returns whether a file exists on disk.
  • JoiningSlash(elem ...string) string
    • Joins path segments with exactly one slash between elements.
  • GetGlobalConfigurationDirectory(appname string) string
    • Returns an operating-system-specific global configuration directory.
    • Linux and macOS: /etc/<appname>
    • Windows: %APPDATA%\\<appname>
  • GetGlobalConfigurationFile(appname string, file string) string
    • Builds a full path to a config file inside the global config directory.
  • IsSuperUser() bool
    • Detects whether the current process runs with elevated privileges.

Installation

go get scm.yoorie.de/go-lib/util

Example

package main

import (
 "fmt"

 "scm.yoorie.de/go-lib/util"
)

func main() {
 if util.FileExists("config.yaml") {
  fmt.Println("config file found")
 }

 fmt.Println(util.JoiningSlash("/api", "v1", "users"))
 fmt.Println(util.GetGlobalConfigurationFile("myapp", "config.yaml"))
}

Copyright © 2026 yoorie.de