ini

package module
v0.0.0-...-0ba8c4b Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 5 Imported by: 0

README ¶

go-ini 🚀

go-ini is a Go package tailored for manipulation, reading, and writing of INI files. This package is specifically designed to be compliant with Magic Software's "Magic.ini" format.

Magic fun img

Go Reference

💡 Features

  • Magic Software Compliance: Adheres to the "Magic.ini" format specifications.
  • Load and Parse: Efficiently reads INI files.
  • Write and Update: Capable of writing updates to existing INI files or creating new ones.
  • Section and Key Extraction: Extract sections and keys from INI content with ease.
  • Value Translation: Translate values based on translatable sections.

🛠 Usage

🔧 Installation

To install the package, use:

go get github.com/devzolo/go-ini
Basic Usage
package main

import (
  "fmt"

  "github.com/devzolo/go-ini"
)

func main() {
  cfg := ini.NewMagicIni()
  err := cfg.LoadIni("path/to/your/magic.ini")
  if err != nil {
    panic(err)
  }
  value := cfg.Get("SomeSection", "SomeKey")
  fmt.Println(value)
}

📚 Documentation

📄 MagicIni Structure

Represents a structured format of an INI file compliant with the "Magic.ini" standards. It houses the parsed data, the currently parsed section, and the section with translatable strings.

🛠 Primary Methods
  • NewMagicIni(): Creates and returns a new MagicIni instance.
  • LoadIni(path string): Reads and parses an INI file, particularly "Magic.ini", from the specified path.
  • LoadAdditionalIni(path string): Loads an additional INI file from the specified path, merging its contents with the existing data.
  • Get(section string, key string): Fetches a value for a specific section and key.
  • Translate(str string): Translates placeholders in the provided string using the corresponding strings from the TranslatableSection.

Documentation ¶

Overview ¶

Package ini provides structures and methods for parsing and managing INI files with special enhancements.

Index ¶

Constants ¶

View Source
const DEFAULT_TRANSLATABLE_SECTION = "MAGIC_LOGICAL_NAMES"

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type MagicIni ¶

type MagicIni struct {
	Ini map[string]map[string]string // Parsed INI content organized as Section -> Key -> Value.

	TranslatableSection string              // Specifies the section containing translatable strings.
	SectionsOrder       []string            // Maintains the order of sections as they appear in the INI file.
	KeysOrder           map[string][]string // Maintains the order of keys within sections.
	// contains filtered or unexported fields
}

MagicIni represents the structured content of an INI file. It provides functionalities for parsing, modifying, and saving INI content.

func NewMagicIni ¶

func NewMagicIni() *MagicIni

NewMagicIni initializes a new MagicIni instance with default values. By default, it sets the translatable section as "MAGIC_LOGICAL_NAMES".

func (*MagicIni) Get ¶

func (ini *MagicIni) Get(section string, key string) string

Get fetches the value associated with a given key within a specified section.

func (*MagicIni) GetSectionKeys ¶

func (ini *MagicIni) GetSectionKeys(section string) []string

GetSectionKeys retrieves all key names from a specified section.

func (*MagicIni) GetSections ¶

func (ini *MagicIni) GetSections() []string

ParseKeyValue processes a single key-value pair line.

func (*MagicIni) LoadAdditionalIni ¶

func (ini *MagicIni) LoadAdditionalIni(path string) error

LoadAdditionalIni merges content from another INI file into the current instance. Useful for layering configurations or adding supplemental data.

func (*MagicIni) LoadIni ¶

func (ini *MagicIni) LoadIni(path string) error

LoadIni reads and parses the content of the INI file located at the specified path.

func (*MagicIni) Parse ¶

func (ini *MagicIni) Parse(source string)

ParseSection handles the parsing of a section declaration line.

func (*MagicIni) ParseKeyValue ¶

func (ini *MagicIni) ParseKeyValue(line string)

ParseKeyValue processes a single key-value pair line.

func (*MagicIni) ParseSection ¶

func (ini *MagicIni) ParseSection(line string)

ParseSection handles the parsing of a section declaration line.

func (*MagicIni) ParseSectionInlineKeyValue ¶

func (ini *MagicIni) ParseSectionInlineKeyValue(line string)

ParseSectionInlineKeyValue handles special case sections where a key-value pair is declared inline.

func (*MagicIni) Save ¶

func (ini *MagicIni) Save(path string) error

ParseSection handles the parsing of a section declaration line.

func (*MagicIni) Set ¶

func (ini *MagicIni) Set(section string, key string, value string)

Set assigns a value to a key within a specific section.

func (*MagicIni) Translate ¶

func (ini *MagicIni) Translate(str string) string

Translate attempts to replace placeholders in a string with their corresponding translations from the TranslatableSection.

Jump to

Keyboard shortcuts

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