https://github.com/plumber-cd/go-credentials
Cross Platform Go Credentials Provider
https://github.com/plumber-cd/go-credentials
credentials go golang keychain keyring
Last synced: 6 months ago
JSON representation
Cross Platform Go Credentials Provider
- Host: GitHub
- URL: https://github.com/plumber-cd/go-credentials
- Owner: plumber-cd
- License: apache-2.0
- Created: 2022-05-22T04:56:37.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-19T21:22:22.000Z (over 2 years ago)
- Last Synced: 2025-03-11T21:48:47.896Z (over 1 year ago)
- Topics: credentials, go, golang, keychain, keyring
- Language: Go
- Homepage:
- Size: 52.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-credentials
Cross Platform Go Credentials Provider
This simple library provides common interface for working with credentials.
By default it uses the following interfaces:
- MacOS: https://github.com/keybase/go-keychain
- Linux: https://github.com/keybase/dbus
- Windows: https://github.com/danieljoos/wincred
You can substitute it with your own interface per platform.
# Example
```go
package main
import (
"fmt"
"github.com/plumber-cd/go-credentials"
)
func main() {
domain := &credentials.Domain{
Service: "My App Name",
AccessGroup: "github.com/plumber-cd/go-credentials", // Define some unique for your app instance value
}
if err := credentials.SetDomain(domain); err != nil {
panic(err)
}
if err := err = credentials.Create("http://example.com", "", "password"); err != nil {
panic(err)
}
name, secret, err := credentials.Retrieve("http://example.com")
if err != nil {
panic(err)
}
fmt.Printf("Name: %s\n", name)
fmt.Printf("Secret: %s\n", secret)
if err := credentials.Update("http://example.com", "new title", "new password"); err != nil {
panic(err)
}
if err := credentials.Delete("http://example.com"); err {
panic(err)
}
}
```
# Custom provider
You need to create new `struct` than implements `credentials.Provider` interface. Somewhere in your app, you then will need to:
```go
package main
import "github.com/plumber-cd/go-credentials"
func init() {
credentials.Current = &MyCustomProvider{}
}
```
That's it. All other code that is using this same library - will now use your custom provider instead of default.