Last active
October 11, 2024 07:13
-
-
Save suzuki-shunsuke/58961369fbe13c76b3052c6ddc0a3893 to your computer and use it in GitHub Desktop.
Example of 99designs/keyring https://github.com/aquaproj/aqua/issues/3068
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/99designs/keyring" | |
) | |
func main() { | |
if err := get(); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func get() error { | |
ring, err := keyring.Open(keyring.Config{ | |
ServiceName: "test-aquaproj-aqua", | |
}) | |
if err != nil { | |
return fmt.Errorf("open a key: %w", err) | |
} | |
item, err := ring.Get("GITHUB_TOKEN") | |
if err != nil { | |
return fmt.Errorf("set a key: %w", err) | |
} | |
fmt.Println("value:", string(item.Data)) | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/99designs/keyring" | |
) | |
func main() { | |
if err := set(); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func set() error { | |
ring, err := keyring.Open(keyring.Config{ | |
ServiceName: "test-aquaproj-aqua", | |
}) | |
if err != nil { | |
return fmt.Errorf("open a key: %w", err) | |
} | |
if err := ring.Set(keyring.Item{ | |
Key: "GITHUB_TOKEN", | |
Data: []byte("secret-bar"), | |
}); err != nil { | |
return fmt.Errorf("set a key: %w", err) | |
} | |
return nil | |
} |
It doesn't work without CGO on macOS.
CGO_ENABLED=0 go build -o bin/get-nocgo get.go
$ ./bin/get-nocgo
2024/10/11 16:12:22 set a key: No directory provided for file keyring
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's enough fast on macOS.