Skip to content

Commit 736fc39

Browse files
committed
docs: add section about custom stores to README
1 parent 9932bf9 commit 736fc39

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,35 @@ VAR4="default_value_for_unset"
7676

7777
Please note that it used `%q` to print empty strings, as `%s` would not print anything.
7878

79+
## Custom Stores
80+
81+
Envlang is designed to be extensible through a `store.Store` interface, allowing you to connect to any data source for your environment variables. This provides the flexibility to fetch variables from databases, cloud services, or any other configuration management system.
82+
83+
### Implementing a New Store
84+
85+
To create a custom store, you need to implement the `store.Store` interface:
86+
87+
```go
88+
package store
89+
90+
type Store interface {
91+
ImportList([]string)
92+
ImportMap(map[string]string)
93+
Get(string) (*string, bool)
94+
Put(string, *string)
95+
Remove(string) bool
96+
ExportMap() map[string]*string
97+
}
98+
```
99+
100+
By implementing these methods, you can define how Envlang interacts with your chosen backend.
101+
102+
### Example: Redis Store
103+
104+
Envlang includes a ready-to-use Redis store as an example of a custom implementation. It allows you to use a Redis instance as a backend for storing and retrieving environment variables.
105+
106+
You can find the implementation in the `store/redis` directory. This serves as a practical guide for building your own custom stores.
107+
79108
## Shell Parameter Expansion
80109

81110
Envlang supports a comprehensive set of POSIX shell parameter expansion operators:

0 commit comments

Comments
 (0)