utils

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 5 Imported by: 5

README

Go Utils package

Available utilities

GetExecutablePath

Returns the path of the current executable.

SafeJoinPaths

Joins two given paths and applies the correct path separator.

StringToInt

Converts a string to an int, and if the conversion fails uses the provided default value.

LoadJSONFromFile

Loads a JSON file from a given path and populates the given model with the JSON file's contents.

WriteJSONToFile

Writes a given model as JSON string to a given path.

ParseConfig

Reads a config.json file from the same directory as the executable and parses its JSON to the given model.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExecutablePath

func GetExecutablePath() (string, error)

GetExecutablePath gets the path of the current executable.

func LoadJSONFromFile added in v1.2.0

func LoadJSONFromFile(path string, model interface{}) error

LoadJSONFromFile loads a JSON file from `path` and populated the given `model`.

func ParseConfig

func ParseConfig(model interface{}) error

ParseConfig reads a `config.json` file on the same directory as the executable and parses its JSON to the given model.

func SafeJoinPaths

func SafeJoinPaths(path1, path2 string) string

SafeJoinPaths joins `path1` and `path2` and applies the correct separator.

func StringToInt

func StringToInt(str string, defaultValue int) int

StringToInt converts a string to an int, and if the conversion fails, it uses the `defaultValue`.

func WriteJSONToFile added in v1.3.0

func WriteJSONToFile(path string, model interface{}) error

WriteJSONToFile writes the given `model` struct as JSON to the file at `path`

Types

This section is empty.

Jump to

Keyboard shortcuts

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