Skip to content

Repository files navigation

Secret-Go

Go library for deserializing secrets from various sources (plain text, environment variables, or files) with support for multiple encodings.

Features

  • 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

Installation

go get github.com/mia-platform/secret-go

Documentation & Examples

  • For detailed documentation, including JSON Schema and API details, see Documentation.
  • For comprehensive usage examples, see Examples.

Quick Start

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"
}

About

A small Go library for representing secrets in JSON configs and resolving them at load time from plain values, environment variables, or files, with optional base64 decoding and safe redacted string output.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages