fileload

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package fileload contains commonly used file loading functions. For human-created files (eg, config files), I'd suggest using TOML (https://github.com/BurntSushi/toml), specifically for comment support and improved readability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON[T any](filename string) (*T, error)

JSON reads a file at the given location and attempts to unmarshal it as JSON with the given type. The generic type adds more convenience so you can simplify file loading down to something like:

cfg, err := fileload.JSON[ServiceCfg]("cfg.json")
logging.FatalIfError(err, "loading service config")

ie, this saves you a line of explicitly declaring a var, because we'll declare it and return a pointer here.

func TOML

func TOML[T any](filename string) (*T, toml.MetaData, error)

TOML reads a file at the given location and attempts to unmarshal it as TOML with the given type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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