- About this module
- Installation
- Usage
- Code of Conduct
- Working Language
- Support and Feedback
- How to Contribute
- Licensing
The config
module provides a set of tools to manage configurations in Go applications.
This module can be used to load configurations from different sources like environment variables and configuration files and bind them to a struct using the spf13/viper library. It also provides a way to validate the configuration.
To install, run:
go get github.com/lvlcn-t/go-kit/config
And import the package in your code:
import "github.com/lvlcn-t/go-kit/config"
The documentation for this module can be found on pkg.go.dev.
To see how to use this module, you can check the examples directory of the repository.
To validate a configuration, you can use the config.Validate
function. You can either implement the config.Validator
interface on the passed type or use the validate
tag on the struct fields.
type Config struct {
Host string `validate:"required"`
Port int `validate:"required,min=1024,max=65535"`
}
The following tags are available for validation:
Tag | Description | Example | Available Types |
---|---|---|---|
required |
The field must be set | validate:"required" |
any |
min |
The field must be greater than or equal to the specified value | validate:"min=10" |
cmp.Ordered , slices, arrays and maps |
max |
The field must be less than or equal to the specified value | validate:"max=10" |
cmp.Ordered , slices, arrays and maps |
len |
The field must have the specified length | validate:"len=10" |
string , slices, arrays, maps and channels |
eq |
The field must be equal to the specified value | validate:"eq=10" |
cmp.Ordered |
ne |
The field must not be equal to the specified value | validate:"ne=10" |
cmp.Ordered |
gt |
The field must be greater than the specified value | validate:"gt=10" |
cmp.Ordered |
lt |
The field must be less than the specified value | validate:"lt=10" |
cmp.Ordered |
gte |
The field must be greater than or equal to the specified value | validate:"gte=10" |
cmp.Ordered |
lte |
The field must be less than or equal to the specified value | validate:"lte=10" |
cmp.Ordered |
This project has adopted the Contributor Covenant in version 2.1 as our code of conduct. Please see the details in our CODE_OF_CONDUCT.md. All contributors must abide by the code of conduct.
We decided to apply English as the primary project language.
Consequently, all content will be made available primarily in English. We also ask all interested people to use English as the preferred language to create issues, in their code (comments, documentation, etc.) and when you send requests to us. The application itself and all end-user facing content will be made available in other languages as needed.
The following channels are available for discussions, feedback, and support requests:
Type | Channel |
---|---|
Issues |
Contribution and feedback is encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines. By participating in this project, you agree to abide by its Code of Conduct at all times.
Copyright (c) 2024 lvlcn-t.
Licensed under the MIT (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://www.mit.edu/~amini/LICENSE.md.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an " AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the LICENSE for the specific language governing permissions and limitations under the License.