-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add contributing guidelines and refactor config & utility funct…
…ions - Introduced .github/CONTRIBUTING.md for contribution guidelines. - Updated AppConfig to use configfx.BaseConfig in pkg/app/config.go. - Implemented LoadConfig function to initialize configuration in pkg/app/mod.go. - Added ConfigLoader, env, and json parsers in pkg/bliss/configfx package. - Refactored NewConfig to return pointer in pkg/bliss/httpfx/config.go. - Renamed helper functions in pkg/bliss/lib for consistency. - Extracted environment handling to pkg/bliss/lib/env.go. - Introduced pkg/bliss/lib/paths.go for path handling utilities. - Updated test cases to align with refactored environment functions.
- Loading branch information
Showing
17 changed files
with
275 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Contributing to [golang-service-template](./) | ||
|
||
👍🎉 First off, thanks for taking the time to contribute! 🎉👍 | ||
|
||
The following is a set of guidelines for contributing to | ||
`golang-service-template` and its packages, which are hosted in GitHub. These | ||
are mostly guidelines, not strict rules. Use your best judgment and feel free to | ||
propose changes to this document in a pull request. | ||
|
||
## What Should I Know Before I Get Started? | ||
|
||
### Code of Conduct | ||
|
||
This project and everyone participating in it is governed by the | ||
[@eser/directives](https://github.com/eser/stack/blob/dev/pkg/%40eser/directives/README.md). | ||
By participating, you are expected to uphold this code. Please report | ||
unacceptable behavior as in specified in the link. | ||
|
||
### Technical Requirements | ||
|
||
Just familiarity with Golang and Git. | ||
|
||
### Conventions | ||
|
||
Using existing precommit hooks should be fine for now. Please ensure your | ||
submissions are formatted accordingly. | ||
|
||
### Design Decisions | ||
|
||
Before making significant changes, please open a new issue to discuss the | ||
proposed changes and its design first. | ||
|
||
## How Can I Contribute? | ||
|
||
### Ways to Contribute | ||
|
||
It is publicly open for any contribution. Here are some ideas you can begin | ||
from: | ||
|
||
- Reporting bugs | ||
- Suggesting enhancements and new features | ||
- Implementing performance improvements | ||
- Improving documentation | ||
- Submitting bug fixes | ||
- Linking to your golang-service-template project | ||
|
||
## Creating an Issue | ||
|
||
- Check the | ||
[GitHub Issues](https://github.com/eser/golang-service-template/issues) first | ||
to avoid duplicating an existing issue. | ||
- Use the issue tracker to ask questions, report problems or for discussion | ||
related to the project. | ||
|
||
## Submitting a Pull Request | ||
|
||
- Adhere to | ||
[@eser/directives](https://github.com/eser/stack/blob/dev/pkg/%40eser/directives/README.md) | ||
- Fork the repo | ||
- Make your changes in a new branch | ||
- Provide tests for your changes, particularly for new features or fixes | ||
- Push changes to your own fork | ||
- Submit a pull request, linking it to the relevant issue. If an issue does not | ||
exist, create one before submission. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package configfx | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/eser/go-service/pkg/bliss/configfx/envparser" | ||
"github.com/eser/go-service/pkg/bliss/configfx/jsonparser" | ||
"github.com/eser/go-service/pkg/bliss/lib" | ||
) | ||
|
||
const ( | ||
tagConf = "conf" | ||
) | ||
|
||
var ErrNotStruct = errors.New("not a struct") | ||
|
||
type ConfigLoader struct{} | ||
|
||
type ConfigMeta struct { | ||
Name string | ||
Type reflect.Type | ||
Children *[]ConfigMeta | ||
} | ||
|
||
func (dcl *ConfigLoader) TryLoadEnv(m *map[string]string) error { | ||
env := lib.EnvGetCurrent() | ||
filenames := lib.EnvAwareFilenames(env, ".env") | ||
|
||
err := envparser.TryParseFiles(m, filenames...) | ||
if err != nil { | ||
return err //nolint:wrapcheck | ||
} | ||
|
||
lib.EnvOverrideVariables(m) | ||
|
||
return nil | ||
} | ||
|
||
func (dcl *ConfigLoader) TryLoadJson(m *map[string]any) error { | ||
env := lib.EnvGetCurrent() | ||
filenames := lib.EnvAwareFilenames(env, "config.json") | ||
|
||
err := jsonparser.TryParseFiles(m, filenames...) | ||
if err != nil { | ||
return err //nolint:wrapcheck | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func reflectMeta(r reflect.Value) (*[]ConfigMeta, error) { | ||
result := []ConfigMeta{} | ||
|
||
if r.Kind() != reflect.Struct { | ||
return nil, ErrNotStruct | ||
} | ||
|
||
for i := range r.NumField() { | ||
fieldType := r.Type().Field(i) | ||
|
||
if fieldType.Anonymous { | ||
children, err := reflectMeta(r.Field(i)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
result = append(result, *children...) | ||
|
||
continue | ||
} | ||
|
||
tag, ok := fieldType.Tag.Lookup(tagConf) | ||
if !ok { | ||
continue | ||
} | ||
|
||
result = append(result, ConfigMeta{ | ||
Name: tag, | ||
Type: fieldType.Type, | ||
}) | ||
} | ||
|
||
return &result, nil | ||
} | ||
|
||
func (dcl *ConfigLoader) LoadMeta(i any) (*ConfigMeta, error) { | ||
r := reflect.ValueOf(i).Elem() | ||
children, err := reflectMeta(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ConfigMeta{ | ||
Name: "root", | ||
Children: children, | ||
}, nil | ||
} | ||
|
||
func (dcl *ConfigLoader) Load(i any) error { | ||
meta, err := dcl.LoadMeta(i) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, child := range *meta.Children { | ||
fmt.Printf("fieldName: %s fieldType: %s\n", child.Name, child.Type.Name()) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.