configurator

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

Configurator

Saves Golang Structs into Filesystem.

Install
go get gitlab.com/mmorgenstern/configurator
Usage
package main

import (
	"fmt"
	"gitlab.com/mmorgenstern/configurator"
	"io/fs"
	"os"
	"path"
)

// define the structure of the Configuration Object
type Config struct {
	Name string `json:"name"`
}

// Implement the GetLocation Function from the IConfig Interface that returns the
// Path of the Config File
func (c *Config) GetLocation() string {
	return path.Join(os.TempDir(), "testprogram", "config.json")
}

// Implement the GetFileMode Function to define the Rights that saved with the File
func (c *Config) GetFileMode() fs.FileMode {
	return 0755
}

func main() {
	// create a Instance of the Configuration you want
	cfg := Config{Name: "test"}
	// get a Config Writer to write the Config
	w := configurator.NewConfigWriter()
	// get a Config Reader to read the written Config
	r := configurator.NewConfigReader()

	// write the instance of Config
	err := w.Write(&cfg)
	if err != nil {
		panic(err)
	}
	// read the Config from Filesystem into the given Reference Instance
	err = r.Read(&cfg)
	if err != nil {
		panic(err)
	}
	println(fmt.Sprintf("%v", cfg))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigReader

type ConfigReader struct{}

func NewConfigReader

func NewConfigReader() *ConfigReader

func (*ConfigReader) Read

func (r *ConfigReader) Read(o IConfig) error

type ConfigWriter

type ConfigWriter struct{}

func NewConfigWriter

func NewConfigWriter() *ConfigWriter

func (*ConfigWriter) Write

func (w *ConfigWriter) Write(o IConfig) error

type IConfig

type IConfig interface {
	GetLocation() string
	GetFileMode() fs.FileMode
}

type IConfigReader

type IConfigReader interface {
	Read(o IConfig) error
}

type IConfigWriter

type IConfigWriter interface {
	Write(o IConfig) error
}

Jump to

Keyboard shortcuts

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