Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(conf_env): enhance environment variable loading for config #892

Merged
merged 3 commits into from
May 27, 2024

Conversation

qwqcode
Copy link
Member

@qwqcode qwqcode commented May 26, 2024

New Environment Variable documentation is published: https://artalk.js.org/guide/env.html

This PR includes:

  • Adding a mapping from environment variable names to configuration node paths by reading golang struct tags via reflect

    • Supports setting array variables using numeric index and space separators
  • Adding a configuration documentation generator

    • Parses YAML template configuration file comments to automatically generate environment variable documentation
  • Structured configuration file option metadata

    type OptionsMeta struct {
        Title      string   `json:"title" yaml:"title"`
        Desc       string   `json:"desc" yaml:"desc"`
        Type       string   `json:"type" yaml:"type"`
        Options    []string `json:"options" yaml:"options"`
        Env        string   `json:"env" yaml:"env"`
        Path       string   `json:"path" yaml:"path"`
        PathText   string   `json:"path_title" yaml:"path_title"`
        Default    any      `json:"default" yaml:"default"`
        IsRoot     bool     `json:"is_root" yaml:"is_root"`
        HasChild   bool     `json:"has_child" yaml:"has_child"`
        AllowsSet  bool     `json:"allows_edit" yaml:"allows_edit"`
        CommentRaw string   `json:"comment_raw" yaml:"comment_raw"`
    }
  • Optimizing deployment documentation

  • Solving the problem of configuring the frontend interface through environment variables

  • Implemented GetOptionsMetaData, GetEnvPathMapByModel, Unflatten functions

  • Improved numerous unit tests

related to #559 #573 #790 (comment)

fixes #875


Next optimization steps:

Hardcode the output results of GetOptionsMetaData into the code and generate them using go generate. This will avoid repeating the YAML configuration file parsing and reading reflect tags to obtain the confNodePaths => envName mapping table every time Artalk starts. (This has been implemented in 401cf5c)

Copy link

codecov bot commented May 27, 2024

Codecov Report

Attention: Patch coverage is 74.27885% with 107 lines in your changes are missing coverage. Please review.

Project coverage is 29.60%. Comparing base (d2161cc) to head (cbfc880).
Report is 1 commits behind head on master.

Files Patch % Lines
internal/config/meta/gen/main.go 0.00% 86 Missing ⚠️
internal/config/env_provider/provider.go 91.58% 6 Missing and 3 partials ⚠️
internal/config/meta/meta.go 95.72% 4 Missing and 1 partial ⚠️
internal/config/env_provider/unflatten.go 93.87% 2 Missing and 1 partial ⚠️
internal/config/meta/mapping.go 94.64% 2 Missing and 1 partial ⚠️
internal/config/base.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #892      +/-   ##
==========================================
+ Coverage   27.19%   29.60%   +2.41%     
==========================================
  Files         198      203       +5     
  Lines        8166     8575     +409     
==========================================
+ Hits         2221     2539     +318     
- Misses       5811     5898      +87     
- Partials      134      138       +4     
Flag Coverage Δ
go 29.60% <74.27%> (+2.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@qwqcode qwqcode merged commit 161ff8b into master May 27, 2024
8 checks passed
@qwqcode qwqcode deleted the fix/conf/env branch May 27, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker启动时,通过环境定义的管理员用户,不会自动创建
1 participant