Skip to content

load(options): support both global-level and messager-level options, and add new option LoadFunc#264

Merged
wenchy merged 13 commits intomasterfrom
refactor-load-options
Jul 15, 2025
Merged

load(options): support both global-level and messager-level options, and add new option LoadFunc#264
wenchy merged 13 commits intomasterfrom
refactor-load-options

Conversation

@Kybxd
Copy link
Copy Markdown
Collaborator

@Kybxd Kybxd commented Jul 7, 2025

@Kybxd Kybxd changed the title refactor: replace ReadFunc with LoadFunc, support messager-level LoadFunc refactor: replace ReadFunc with LoadFunc, support messager-level LoadFuncs Jul 7, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 7, 2025

Codecov Report

Attention: Patch coverage is 96.62921% with 3 lines in your changes missing coverage. Please review.

Project coverage is 71.55%. Comparing base (4b09f7c) to head (e3a551d).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
load/load.go 86.36% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
+ Coverage   71.28%   71.55%   +0.26%     
==========================================
  Files          83       84       +1     
  Lines       10342    10408      +66     
==========================================
+ Hits         7372     7447      +75     
+ Misses       2404     2394      -10     
- Partials      566      567       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Kybxd Kybxd force-pushed the refactor-load-options branch from 39c57f3 to d8718ad Compare July 7, 2025 08:58
Comment thread load/options.go Outdated
Comment thread load/options.go Outdated
Comment thread load/load.go Outdated
@wenchy wenchy changed the title refactor: replace ReadFunc with LoadFunc, support messager-level LoadFuncs refactor: replace ReadFunc with LoadFunc, support messager-level LoadFunc Jul 12, 2025
@wenchy wenchy changed the title refactor: replace ReadFunc with LoadFunc, support messager-level LoadFunc loader(BREAKING!): replace ReadFunc with LoadFunc, support messager-level LoadFunc Jul 12, 2025
@wenchy wenchy changed the title loader(BREAKING!): replace ReadFunc with LoadFunc, support messager-level LoadFunc load(options): support both global-level and messager-level options, and add new option LoadFunc Jul 12, 2025
Comment thread load/options.go
// Paths maps each messager name to a corresponding config file path.
// If specified, then the main messager will be parsed from the file
// directly, other than the specified load dir.
IgnoreUnknownFields *bool
Copy link
Copy Markdown
Member

@wenchy wenchy Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to use *bool to represent field presence? How about other programming languages, such as C++, C#, and TypeScript?

For example, tableau's C++ LoadOptions:
https://github.com/tableauio/loader/blob/7689f47671ae338338933970e251ac9c6ca31f5d/test/cpp-tableau-loader/src/protoconf/load.pc.h#L24-L42

Copy link
Copy Markdown
Member

@wenchy wenchy Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use std::optional<bool> (C++17 and later) is a good solution.
Refer https://en.cppreference.com/w/cpp/utility/optional.html)
Example:

#include <optional>

class MyClass {
public:
    std::optional<bool> flag;

    void print() {
        if (flag.has_value()) {
            std::cout << "Flag is present and is " << (flag.value() ? "true" : "false") << "\n";
        } else {
            std::cout << "Flag is not present\n";
        }
    }
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C#, the idiomatic way to represent the presence of a bool field (i.e., whether it has a value or not) is to use a nullable bool, which is bool?.

Explanation

bool can be either true or false.
bool? (nullable bool) can be true, false, or null.
null represents the absence of a value (field not set).

Example

class MyClass
{
    public bool? Flag { get; set; }

    public void Print()
    {
        if (Flag.HasValue)
        {
            Console.WriteLine($"Flag is present and is {Flag.Value}");
        }
        else
        {
            Console.WriteLine("Flag is not present");
        }
    }
}

Usage

var obj = new MyClass();

obj.Print();  // Output: Flag is not present

obj.Flag = true;
obj.Print();  // Output: Flag is present and is True

obj.Flag = false;
obj.Print();  // Output: Flag is present and is False

obj.Flag = null;
obj.Print();  // Output: Flag is not present

Summary
Use bool? (nullable bool) to represent a boolean field that may or may not be present.
null means "not present".
true or false means "present with that value".
This is the direct equivalent of C++'s std::optional<bool>.

@wenchy wenchy merged commit a7e914b into master Jul 15, 2025
9 checks passed
@wenchy wenchy deleted the refactor-load-options branch July 15, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

load(options): support both global-level and messager-level options

2 participants