odin

package module
v0.0.0-...-e29095b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 8 Imported by: 1

README

Odin

Odin is a lightweight Go package for managing environment variables within your Go applications. It provides functions to set, get, list, remove, clear, and rename environment variables stored in a SQLite database. Odin is designed to simplify the management of environment variables in your Go applications.

Features

  • Set an environment variable with a key and value.
  • Get the value of an environment variable by specifying its key.
  • List all environment variables.
  • Remove an environment variable by specifying its key.
  • Clear all environment variables.
  • Rename an environment variable.

Installation

To use Odin in your Go application, you can import it as follows:

import (
    "github.com/IsaqueGeraldo/odin"
)

Ensure that you have the package installed in your Go environment. You can install it using the following command:

go get github.com/IsaqueGeraldo/odin

Usage

Here's how you can use Odin in your Go application:

package main

import (
    "fmt"
    "github.com/IsaqueGeraldo/odin"
)

func main() {
    // Initialize the Odin package
    odin.Bootstrap()

    // Set an environment variable
    err := odin.Setenv("API_KEY", "my-secret-key")
    if err != nil {
        fmt.Println("Error setting environment variable:", err)
    }

    // Get the value of an environment variable
    value, err := odin.Getenv("API_KEY")
    if err != nil {
        fmt.Println("Error getting environment variable:", err)
    } else {
        fmt.Println("Value of environment variable 'API_KEY':", value)
    }

    // List all environment variables
    envs, err := odin.Environ()
    if err != nil {
        fmt.Println("Error listing environment variables:", err)
    } else {
        fmt.Println("Environment variables:")
        for _, env := range envs {
            fmt.Printf("%s=%s\n", env.Key, env.Value)
        }
    }

    // Remove an environment variable
    err = odin.Unsetenv("API_KEY")
    if err != nil {
        fmt.Println("Error removing environment variable:", err)
    }

    // Clear all environment variables
    err = odin.Clearenv()
    if err != nil {
        fmt.Println("Error clearing environment variables:", err)
    }

    // Rename an environment variable
    err = odin.RenameKey("oldKey", "newKey")
    if err != nil {
        fmt.Println("Error renaming environment variable:", err)
    }
}

This example demonstrates how to use Odin's functions to manage environment variables within your Go application.

License

Odin is released under the MIT License. See LICENSE for more information.


Feel free to contribute to this project or report any issues on GitHub.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap()

func Clearenv

func Clearenv() error

func Getenv

func Getenv(key string) (string, error)

func RenameKey

func RenameKey(oldKey, newKey string) error

func Setenv

func Setenv(key string, value string) error

func Unsetenv

func Unsetenv(key string) error

Types

type Environment

type Environment struct {
	ID        uint      `gorm:"primarykey" json:"id"`
	Key       string    `json:"key"`
	Value     string    `json:"value"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func Environ

func Environ() ([]Environment, error)

func Find

func Find(key string) ([]Environment, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL