blusettings

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 3 Imported by: 0

README

BluSettings

BluSettings é uma biblioteca leve em Go para gerenciamento simples de configurações persistentes, utilizando arquivos JSON armazenados automaticamente no diretório do usuário ou em um caminho customizado.

Ideal para aplicações CLI, desktop ou serviços que precisam salvar preferências sem dependências externas.


✨ Recursos

  • 💾 Persistência automática em arquivo config.json
  • 🏠 Suporte a diretório padrão no Home do usuário (~/.appname)
  • 📁 Suporte a caminho customizado
  • 🧩 API simples para tipos comuns
    • string
    • int
    • bool
    • []string
  • 🔄 Fallback automático para valores padrão
  • 📦 Baseado apenas na biblioteca padrão do Go

📦 Instalação

Extrair o arquivo zip e armazenar no seu projeto, pode ser em uma pasta de biblioteca separada.


🚀 Uso básico

Carregando configurações
import "github.com/bluiceoficial/blusettings"

cfg, err := blusettings.Load("meuapp", true)
if err != nil {
	log.Fatal(err)
}

Isso criará automaticamente:

~/.meuapp/config.json

✍️ Salvando valores

cfg.SetString("username", "joao")
cfg.SetInt("port", 8080)
cfg.SetBool("dark_mode", true)
cfg.SetStringSlice("languages", []string{"pt", "en"})

cfg.Save()

📖 Lendo valores com fallback

user := cfg.GetString("username", "guest")
port := cfg.GetInt("port", 3000)
dark := cfg.GetBool("dark_mode", false)
langs := cfg.GetStringSlice("languages", []string{"en"})

Se a chave não existir, o valor padrão será retornado.


🧠 Como funciona

  • As configurações são armazenadas internamente como json.RawMessage
  • Cada valor é serializado individualmente
  • O arquivo só é gravado quando Save() é chamado
  • Tipos são preservados automaticamente

🧩 Estrutura do arquivo gerado

{
  "username": "joao",
  "port": 8080,
  "dark_mode": true,
  "languages": [
    "pt",
    "en"
  ]
}

👤 Autor

Murilo Gomes Julio

🔗 https://www.bluice.com.br

📺 https://youtube.com/@bluiceoficial


License

Copyright (c) 2026 Murilo Gomes Julio

Licensed under the MIT license.

All contributions to the BluSettings are subject to this license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BLUSETTINGS

type BLUSETTINGS struct {
	// contains filtered or unexported fields
}

func Load

func Load(nameApp string, defaultPathHome bool) (*BLUSETTINGS, error)

func (*BLUSETTINGS) GetBool

func (m *BLUSETTINGS) GetBool(key string, def bool) bool

func (*BLUSETTINGS) GetInt

func (m *BLUSETTINGS) GetInt(key string, def int) int

func (*BLUSETTINGS) GetString

func (m *BLUSETTINGS) GetString(key string, def string) string

func (*BLUSETTINGS) GetStringSlice

func (m *BLUSETTINGS) GetStringSlice(key string, def []string) []string

func (*BLUSETTINGS) Save

func (m *BLUSETTINGS) Save() error

func (*BLUSETTINGS) SetBool

func (m *BLUSETTINGS) SetBool(key string, value bool)

func (*BLUSETTINGS) SetInt

func (m *BLUSETTINGS) SetInt(key string, value int)

func (*BLUSETTINGS) SetString

func (m *BLUSETTINGS) SetString(key, value string)

func (*BLUSETTINGS) SetStringSlice

func (m *BLUSETTINGS) SetStringSlice(key string, value []string)

Jump to

Keyboard shortcuts

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