Initial commit

This commit is contained in:
2019-03-29 09:31:37 +04:00
commit d635cd55ef
75 changed files with 7807 additions and 0 deletions

21
vendor/github.com/kirsle/configdir/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 Noah Petherbridge
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

89
vendor/github.com/kirsle/configdir/README.md generated vendored Normal file
View File

@@ -0,0 +1,89 @@
# ConfigDir for Go
This library provides a cross platform means of detecting the system's
configuration directories so that your Go app can store config files in a
standard location. For Linux and other Unixes (BSD, etc.) this means using the
[Freedesktop.org XDG Base Directory Specification][1] (0.8), and for Windows
and macOS it uses their standard directories.
This is a simple no-nonsense module that just gives you the path names to do
with as you please. You can either get the bare root config path, or get a
path with any number of names suffixed onto it for vendor- or
application-specific namespacing.
For the impatient, the directories this library can return tend to be like
the following:
| | **System-wide Configuration** |
|---------|-----------------------------------------------------|
| Windows | `%PROGRAMDATA%` or `C:\ProgramData` |
| Linux | `$XDG_CONFIG_DIRS` or `/etc/xdg` |
| macOS | `/Library/Application Support` |
| | **User-level Configuration** |
| Windows | `%APPDATA%` or `C:\Users\%USER%\AppData\Roaming` |
| Linux | `$XDG_CONFIG_HOME` or `$HOME/.config` |
| macOS | `$HOME/Library/Application Support` |
| | **User-level Cache Folder** |
| Windows | `%LOCALAPPDATA%` or `C:\Users\%USER%\AppData\Local` |
| Linux | `$XDG_CACHE_HOME` or `$HOME/.cache` |
| macOS | `$HOME/Library/Caches` |
## Quick Start
```go
// A common use case is to get a private config folder for your app to
// place its settings files into, that are specific to the local user.
configPath := configdir.LocalConfig("my-app")
err := configdir.MakePath(configPath) // Ensure it exists.
if err != nil {
panic(err)
}
// Deal with a JSON configuration file in that folder.
configFile := filepath.Join(configPath, "settings.json")
type AppSettings struct {
Username string `json:"username"`
Password string `json:"password"`
}
var settings AppSettings
// Does the file not exist?
if _, err = os.Stat(configFile); os.IsNotExist(err) {
// Create the new config file.
settings = AppSettings{"MyUser", "MyPassword"}
fh, err := os.Create(configFile)
if err != nil {
panic(err)
}
defer fh.Close()
encoder := json.NewEncoder(fh)
encoder.Encode(&settings)
} else {
// Load the existing file.
fh, err := os.Open(configFile)
if err != nil {
panic(err)
}
defer fh.Close()
decoder := json.NewDecoder(fh)
decoder.Decode(&settings)
}
```
## Documentation
Package documentation is available at
<https://godoc.org/github.com/kirsle/configdir>
## Author
Noah Petherbridge, [@kirsle](https://github.com/kirsle)
## License
MIT
[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html
[2]: https://github.com/shibukawa/configdir

15
vendor/github.com/kirsle/configdir/config_darwin.go generated vendored Normal file
View File

@@ -0,0 +1,15 @@
package configdir
import "os"
var (
systemConfig []string
localConfig string
localCache string
)
func findPaths() {
systemConfig = []string{"/Library/Application Support"}
localConfig = os.Getenv("HOME") + "/Library/Application Support"
localCache = os.Getenv("HOME") + "/Library/Caches"
}

15
vendor/github.com/kirsle/configdir/config_windows.go generated vendored Normal file
View File

@@ -0,0 +1,15 @@
package configdir
import "os"
var (
systemConfig []string
localConfig string
localCache string
)
func findPaths() {
systemConfig = []string{os.Getenv("PROGRAMDATA")}
localConfig = os.Getenv("APPDATA")
localCache = os.Getenv("LOCALAPPDATA")
}

38
vendor/github.com/kirsle/configdir/config_xdg.go generated vendored Normal file
View File

@@ -0,0 +1,38 @@
// +build !windows,!darwin
package configdir
import (
"os"
"path/filepath"
"strings"
)
var (
systemConfig []string
localConfig string
localCache string
)
func findPaths() {
// System-wide configuration.
if os.Getenv("XDG_CONFIG_DIRS") != "" {
systemConfig = strings.Split(os.Getenv("XDG_CONFIG_DIRS"), ":")
} else {
systemConfig = []string{"/etc/xdg"}
}
// Local user configuration.
if os.Getenv("XDG_CONFIG_HOME") != "" {
localConfig = os.Getenv("XDG_CONFIG_HOME")
} else {
localConfig = filepath.Join(os.Getenv("HOME"), ".config")
}
// Local user cache.
if os.Getenv("XDG_CACHE_HOME") != "" {
localCache = os.Getenv("XDG_CACHE_HOME")
} else {
localCache = filepath.Join(os.Getenv("HOME"), ".cache")
}
}

82
vendor/github.com/kirsle/configdir/configdir.go generated vendored Normal file
View File

@@ -0,0 +1,82 @@
package configdir
import (
"os"
"path/filepath"
)
// VERSION is the semantic version number of the configdir library.
const VERSION = "0.1.0"
func init() {
findPaths()
}
// Refresh will rediscover the config paths, checking current environment
// variables again.
//
// This function is automatically called when the program initializes. If you
// change the environment variables at run-time, though, you may call the
// Refresh() function to reevaluate the config paths.
func Refresh() {
findPaths()
}
// SystemConfig returns the system-wide configuration paths, with optional path
// components added to the end for vendor/application-specific settings.
func SystemConfig(folder ...string) []string {
if len(folder) == 0 {
return systemConfig
}
var paths []string
for _, root := range systemConfig {
p := append([]string{root}, filepath.Join(folder...))
paths = append(paths, filepath.Join(p...))
}
return paths
}
// LocalConfig returns the local user configuration path, with optional
// path components added to the end for vendor/application-specific settings.
func LocalConfig(folder ...string) string {
if len(folder) == 0 {
return localConfig
}
return filepath.Join(localConfig, filepath.Join(folder...))
}
// LocalCache returns the local user cache folder, with optional path
// components added to the end for vendor/application-specific settings.
func LocalCache(folder ...string) string {
if len(folder) == 0 {
return localCache
}
return filepath.Join(localCache, filepath.Join(folder...))
}
// DefaultFileMode controls the default permissions on any paths created by
// using MakePath.
var DefaultFileMode = os.FileMode(0755)
// MakePath ensures that the full path you wanted, including vendor or
// application-specific components, exists. You can give this the output of
// any of the config path functions (SystemConfig, LocalConfig or LocalCache).
//
// In the event that the path function gives multiple answers, e.g. for
// SystemConfig, MakePath() will only attempt to create the sub-folders on
// the *first* path found. If this isn't what you want, you may want to just
// use the os.MkdirAll() functionality directly.
func MakePath(paths ...string) error {
if len(paths) >= 1 {
err := os.MkdirAll(paths[0], DefaultFileMode)
if err != nil {
return err
}
}
return nil
}

36
vendor/github.com/kirsle/configdir/doc.go generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/*
Package configdir provides a cross platform means of detecting the system's
configuration directories.
This makes it easy to program your Go app to store its configuration files in
a standard location relevant to the host operating system. For Linux and some
other Unixes (like BSD) this means following the Freedesktop.org XDG Base
Directory Specification 0.8, and for Windows and macOS it uses their standard
directories.
This is a simple no-nonsense module that just gives you the paths, with
optional components tacked on the end for vendor- or app-specific namespacing.
It also provides a convenience function to call `os.MkdirAll()` on the paths to
ensure they exist and are ready for you to read and write files in.
Standard Global Configuration Paths
* Linux: $XDG_CONFIG_DIRS or "/etc/xdg"
* Windows: %PROGRAMDATA% or "C:\\ProgramData"
* macOS: /Library/Application Support
Standard User-Specific Configuration Paths
* Linux: $XDG_CONFIG_HOME or "$HOME/.config"
* Windows: %APPDATA% or "C:\\Users\\%USER%\\AppData\\Roaming"
* macOS: $HOME/Library/Application Support
Standard User-Specific Cache Paths
* Linux: $XDG_CACHE_HOME or "$HOME/.cache"
* Windows: %LOCALAPPDATA% or "C:\\Users\\%USER%\\AppData\\Local"
* macOS: $HOME/Library/Caches
[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html
*/
package configdir