You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: LICENSE
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
Copyright 2023 Andrei Raven Merlescu
1
+
Copyright 2025 Andrei Raven Merlescu
2
2
3
3
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The Configurable package provides a simple and flexible way to handle configuration data in your Go projects. It allows you to define and manage various types of configuration variables, such as integers, strings, booleans, durations, and more. This package supports configuration parsing from JSON, YAML, and INI files, as well as environment variables.
5
+
The Configurable (`figs` as `cfigs`) package provides a simple and flexible way to handle configuration data in your Go projects. It allows you to define and manage various types of configuration variables, such as integers, strings, booleans, durations, and more. This package supports configuration parsing from JSON, YAML, and INI files, as well as environment variables.
6
6
7
7
## Installation
8
8
9
9
To use the Configurable package in your project, you need to have Go installed and set up. Then, you can install the package by running the following command in your terminal:
10
10
11
11
```shell
12
-
go get -u github.com/andreimerlescu/configurable
12
+
go get -u github.com/andreimerlescu/figs
13
13
```
14
14
15
15
## Usage
16
16
17
-
To use the Configurable package in your Go code, you need to import it:
17
+
To use **figs** package in your Go code, you need to import it:
18
18
19
19
```go
20
-
import"github.com/andreimerlescu/configurable"
20
+
import"github.com/andreimerlescu/figs"
21
21
```
22
22
23
23
### Creating a Configurable Instance
24
24
25
25
To get started, you need to create an instance of the Configurable struct by calling the `NewConfigurable()` function:
26
26
27
27
```go
28
-
config:=configurable.New()
28
+
cfigs:=figs.New()
29
29
```
30
30
31
31
### Defining Configuration Variables
32
32
33
33
The Configurable package provides several methods to define different types of configuration variables. Each method takes a name, default value, and usage description as parameters and returns a pointer to the respective variable:
34
34
35
35
```go
36
-
port:=config.NewInt("port", 8080, "The port number to listen on")
37
-
timeout:=config.NewDuration("timeout", time.Second * 5, "The timeout duration for requests")
You can load configuration data from JSON, YAML, and INI files using the `LoadFile()` method:
44
44
45
45
```go
46
-
err:=config.LoadFile("config.json")
46
+
err:=cfigs.ParseFile("config.json")
47
47
if err != nil {
48
48
// Handle error
49
49
}
@@ -56,10 +56,13 @@ The package automatically parses the file based on its extension. Make sure to p
56
56
The Configurable package also allows you to parse command-line arguments. Call the `Parse()` method to parse the arguments after defining your configuration variables:
57
57
58
58
```go
59
-
err:= config.Parse("")
60
-
if err != nil {
61
-
// Handle error
62
-
}
59
+
cfigs.Parse()
60
+
```
61
+
62
+
or
63
+
64
+
```go
65
+
cfigs.Load()
63
66
```
64
67
65
68
Passing an empty string to `Parse()` means it will only parse the command-line arguments and not load any file.
@@ -69,9 +72,9 @@ Passing an empty string to `Parse()` means it will only parse the command-line a
69
72
You can access the values of your configuration variables using the respective getter methods:
@@ -83,8 +86,7 @@ The Configurable package supports setting configuration values through environme
83
86
To generate a usage string with information about your configuration variables, use the `Usage()` method:
84
87
85
88
```go
86
-
usage:= config.Usage()
87
-
fmt.Println(usage)
89
+
fmt.Println(cfigs.Usage())
88
90
```
89
91
90
92
The generated usage string includes information about each configuration variable, including its name, default value, description, and the source from which it was set (flag, environment, JSON, YAML, or INI).
@@ -97,4 +99,4 @@ This package is distributed under the MIT License. See the [LICENSE](LICENSE) fi
97
99
98
100
Contributions to this package are welcome. If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
99
101
100
-
Enjoy using the Configurable package in your projects!
0 commit comments