util/README.md

63 lines
1.6 KiB
Markdown
Raw Normal View History

2023-03-08 09:06:55 +00:00
<div style="text-align:left"><img src="https://www.yoorie.de/img/favicon_32.png"/></div>
# Go utility library
[![Build Status](https://drone.yoorie.de/api/badges/go-lib/util/status.svg)](https://drone.yoorie.de/go-lib/util)
## Project Description
2023-03-08 09:06:55 +00:00
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"))
}
```
2023-03-08 09:06:55 +00:00
---
Copyright &copy; 2023 yoorie.de