61 lines
1.6 KiB
Markdown
61 lines
1.6 KiB
Markdown
# Go utility library
|
|
|
|

|
|
|
|
[](https://drone.yoorie.de/go-lib/util)
|
|
|
|
## 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
|
|
|
|
```bash
|
|
go get scm.yoorie.de/go-lib/util
|
|
```
|
|
|
|
## Example
|
|
|
|
```go
|
|
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
|