zeus

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 5 Imported by: 0

README

zeus

The zeus package is a lightweight Go library for managing environment variables stored in a SQLite database. It provides functions to bootstrap a database connection, retrieve, set, clear, and list environment variables.

Installation

To use the zeus package, make sure you have Go installed on your machine. You can import the package into your Go project using the following command:

go get github.com/IsaqueGeraldo/zeus

Usage

Bootstrap

Before using the functions to manage environment variables, you need to establish a connection to the SQLite database:

package main

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

func main() {
	zeus.Bootstrap() // Initializes the database connection
}
Functions
Getenv(key string) (Environment, error)

Retrieves an environment variable by its key.

Parameters:

  • key: The key of the environment variable to retrieve.

Returns:

  • Environment: The environment variable if found.
  • error: An error if the key is not found or any other error occurs.

Example:

env, err := zeus.Getenv("MY_KEY")
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println("Value:", env.Value)
}
Setenv(key, value string) error

Sets or updates an environment variable in the database.

Parameters:

  • key: The key of the environment variable.
  • value: The value of the environment variable.

Returns:

  • error: An error if saving the variable fails.

Example:

err := zeus.Setenv("MY_KEY", "my_value")
if err != nil {
    fmt.Println(err)
}
Clearenv(key string) error

Removes an environment variable by its key.

Parameters:

  • key: The key of the environment variable to remove.

Returns:

  • error: An error if the key is not found or removal fails.

Example:

err := zeus.Clearenv("MY_KEY")
if err != nil {
    fmt.Println(err)
}
Environ() ([]Environment, error)

Lists all environment variables stored in the database.

Returns:

  • []Environment: A slice of all environment variables.
  • error: An error if the listing fails.

Example:

envs, err := zeus.Environ()
if err != nil {
    fmt.Println(err)
} else {
    for _, env := range envs {
        fmt.Printf("Key: %s, Value: %s\n", env.Key, env.Value)
    }
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap()

Bootstrap initializes the connection to the SQLite database

func Clearenv

func Clearenv(key string) error

Clearenv removes the environment variable for the given key

func Setenv

func Setenv(key, value string) error

Setenv sets a new environment variable with the given key and value

Types

type Environment

type Environment struct {
	Key   string `json:"key" gorm:"primaryKey"` // Unique key for the variable
	Value string `json:"value"`                 // Value associated with the key
}

Environment represents an environment variable with a key and value

func Environ

func Environ() ([]Environment, error)

Environ lists all environment variables

func Getenv

func Getenv(key string) (Environment, error)

Getenv retrieves the environment variable for the given key

Jump to

Keyboard shortcuts

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