package secret
import "github.com/go-arrower/arrower/secret"
Package secret contains secrets to use in the application.
Its purpose is to easily deal with sensitive data
you want to keep from accidentally being exposed.
Code:play
Output: Code:play
Output:Example (AccidentalPrint)¶
package main
import (
"encoding/json"
"fmt"
"log/slog"
"os"
"github.com/go-arrower/arrower/alog"
"github.com/go-arrower/arrower/secret"
)
func main() {
secret := secret.New(secretPhrase)
obj := testStruct{Value: "val", Password: secret}
fmt.Println(secret)
fmt.Printf("%+v\n", secret)
fmt.Printf("%+v\n", obj)
fmt.Printf("%+v\n", &obj)
logger := getLogger()
logger.Info("", slog.Any("secret", secret))
b, _ := json.Marshal(obj)
fmt.Println(string(b))
}
func getLogger() *slog.Logger {
return alog.New(alog.WithHandler(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
if attr.Key == slog.TimeKey {
return slog.Attr{}
}
return attr
}})))
}
const secretPhrase = "this-should-be-secret"
type testStruct struct {
Value string `json:"value"`
Password secret.Secret `json:"password"`
}
******
******
{Value:val Password:******}
&{Value:val Password:******}
level=INFO msg="" secret=******
{"value":"val","password":"******"}
Example (UnsafeSecretAccess)¶
package main
import (
"fmt"
"unsafe"
"github.com/go-arrower/arrower/secret"
)
func main() {
secret := secret.New(secretPhrase)
// It is not completely possible to hide the access to the data.
// If you want stronger guarantees, consider encrypting the data.
ptrTof := unsafe.Pointer(&secret)
s := (**string)(ptrTof)
fmt.Println(**s)
}
const secretPhrase = "this-should-be-secret"
this-should-be-secret
Index ¶
Examples ¶
Types ¶
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret prevents accidentally exposing any data you did not want to expose by masking it.
func New ¶
func (Secret) MarshalJSON ¶
func (Secret) MarshalText ¶
func (Secret) Secret ¶
Secret returns the actual value of the Secret.
func (Secret) String ¶
func (*Secret) UnmarshalJSON ¶
func (*Secret) UnmarshalText ¶
Source Files ¶
- Version
- v0.0.0-20250311203644-ab26c1152cb4 (latest)
- Published
- Mar 11, 2025
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 1 week ago –
Tools for package owners.