mgsettings

package module
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

MGSettings

License

MGSettings é 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

go get github.com/profmugomes/mgsettings

🚀 Uso básico

Carregando configurações
import "github.com/profmugomes/mgsettings"

cfg, err := mgsettings.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"
  ]
}

🧩 Compatibilidade

  • Go 1.27.2+

👤 Autor

Murilo Gomes

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

📺 https://youtube.com/@profmugomes


License

Copyright (c) 2025-2026 Murilo Gomes <profmugomes.com.br>

Licensed under the MIT license.

All contributions to the MGSettings are subject to this license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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