Skip to content

proposal: os: Add SysConfigDir() Function #63858

@nnzv

Description

@nnzv

Abstract

This proposal suggests adding a new function, SysConfigDir(), to the os package in the Go standard library. This function will help Go applications find the default directory for system-wide configuration data in a consistent way across different operating systems.

Background

Right now, os package has a function called UserConfigDir() that's good for getting the directory for user-specific configuration data. But there's no similar function for getting the directory for system-wide configuration data. Many Go apps need this to store configuration files that should be shared among all users on a system.

Proposal

I propose adding a new function, SysConfigDir(), to the os package. This function will return the directory path for system-wide configuration data. It will work the same way on all supported operating systems, just like UserConfigDir(). The way it works will be different depending on the operating system, following the conventions of that system.

Rationale

Here's why we need to add SysConfigDir():

  1. Consistency: Having a standard way to get the system-wide configuration directory makes things simpler for developers. It keeps things the same no matter which operating system you're on.

  2. Best Practices: It encourages developers to follow the best practices for managing configuration. It guides them to use the right directories and avoid problems like hardcoded paths or conflicts.

  3. User-Friendly: Just like UserConfigDir(), SysConfigDir() gives developers an easy way to find system-wide configuration directories, even on systems with different ways of doing things.

Compatibility

Adding SysConfigDir() won't mess up existing code. It's a new feature that we're adding to the os package, so it doesn't affect anything that's already there.

Implementation

Here's how we'll make SysConfigDir() work:

  1. Figure out which operating system you're using (like Windows, Unix, Plan9).
  2. Use the right way to find the system-wide configuration directory based on how that operating system does things.
  3. Give you the directory path, or return error if couldn't figure it out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions