Go library for deserializing secrets from various sources (plain text, environment variables, or files) with support for multiple encodings.
- Plain text secrets: Direct string values
- Environment variable secrets: Read from environment with optional encoding
- File-based secrets: Read from files with support for:
- Full file content
- INI format with key extraction
- JSON format with path-based key extraction (e.g.,
key1.[0].nested)
- Base64 encoding support: Automatically decode base64-encoded secrets
- Automatic JSON deserialization: Works seamlessly with
encoding/json
go get github.com/mia-platform/secret-go- For detailed documentation, including JSON Schema and API details, see Documentation.
- For comprehensive usage examples, see Examples.
Here is a simple example of how to use secret-go with a plain text secret:
package main
import (
"encoding/json"
"fmt"
"github.com/mia-platform/secret-go/secret"
)
type Config struct {
APIKey secret.Secret `json:"api_key"`
}
func main() {
jsonData := `{"api_key": "my-secret-value"}`
var config Config
if err := json.Unmarshal([]byte(jsonData), &config); err != nil {
panic(err)
}
fmt.Println(config.APIKey.Read()) // "my-secret-value"
}