moonbitstack/moonzero/conf does not have a README file

    Refused

    pub(all) suberror Refused {
    Refused(String)
    }

    A config-loading failure (← go-zero's conf.Load errors): malformed JSON or YAML, a non-mapping root, a field of the wrong type, a required field with no value, or a value outside its options=/range= constraint, with a human-readable reason.

    Conf

    pub struct Conf {
    root : Map[String,
    Json
    ]
    }

    A loaded config document (← go-zero's conf.Load): a parsed mapping read through canonical keys and dotted paths, with the ,env=NAME override and the default= / options= / range= constraints go-zero spells as struct tags.

    A field that is absent and has no default is an error, and so is a value that violates its options= or range= constraint — a bad value never degrades into the default.

    Conf::at

    fn Conf::at(self : Conf, path : String) ->
    Json
    ?

    The value at a dotted path, or None if any segment is missing or a non-mapping is walked into.

    Conf::bool

    fn Conf::bool(self : Conf, path : String, default? : Bool, env? : String, also? : Array[String]) -> Bool raise Refused

    Read a Bool field, honouring env= and default=. true/false spelled as a string decode too, which is how an env override arrives.

    Conf::int

    fn Conf::int(self : Conf, path : String, default? : Int, range? : String, env? : String, also? : Array[String]) -> Int raise Refused

    Read an Int field, honouring env=, default= and range=. A fractional value is truncated toward zero after the range check.

    Conf::int64

    fn Conf::int64(self : Conf, path : String, default? : Int64, range? : String, env? : String, also? : Array[String]) -> Int64 raise Refused

    Read an Int64 field, honouring env=, default= and range=.

    Conf::list

    fn Conf::list(self : Conf, path : String) -> Array[Conf] raise Refused

    The list of sub-documents at path — the shape a []Struct config field takes, each element read back through the same constraint-checked accessors. An absent path is an empty list; a non-list, or a list holding anything but mappings, is an error.

    Conf::of_json

    Load a document from JSON. Raises Refused on malformed JSON or a non-object root.

    With vars, ${NAME} and $NAME in the text are replaced first (← go-zero's conf.UseEnv()); knobs says what an unset name becomes, an empty string by default as with Go's os.ExpandEnv.

    Conf::of_toml

    Load a document from TOML, the third format go-zero's conf.Load reads. Raises Refused on malformed TOML. vars and knobs are as for of_json.

    Conf::of_yaml

    Load a document from the YAML go-zero ships as etc/*.yaml. Raises Refused on malformed YAML or a non-mapping root. vars and knobs are as for of_json.

    Conf::string

    fn Conf::string(self : Conf, path : String, default? : String, options? : Array[String], env? : String, also? : Array[String]) -> String raise Refused

    Read a string field, honouring env=, default= and options=.

    Conf::strings

    fn Conf::strings(self : Conf, path : String, default? : Array[String], env? : String, also? : Array[String]) -> Array[String] raise Refused

    Read a string-list field, honouring env= and default=. An env override is comma-separated, since a shell variable carries one string.

    MiddlewaresConf

    pub(all) struct MiddlewaresConf {
    trace : Bool
    log : Bool
    prometheus : Bool
    max_conns : Bool
    breaker : Bool
    shedding : Bool
    timeout : Bool
    recover : Bool
    metrics : Bool
    max_bytes : Bool
    gunzip : Bool
    } derive(Eq,
    Debug
    )

    Which of go-zero's built-in layers the engine installs (← MiddlewaresConf). Every flag defaults to true, so an etc/*.yaml that says nothing about middleware still gets the whole chain.

    MiddlewaresConf::equal

    MiddlewaresConf::new

    fn MiddlewaresConf::new(trace? : Bool, log? : Bool, prometheus? : Bool, max_conns? : Bool, breaker? : Bool, shedding? : Bool, timeout? : Bool, recover? : Bool, metrics? : Bool, max_bytes? : Bool, gunzip? : Bool) -> MiddlewaresConf

    The full chain, which is what go-zero defaults to.

    MiddlewaresConf::not_equal

    fn MiddlewaresConf::not_equal(x : MiddlewaresConf, y : MiddlewaresConf) -> Bool

    PrivateKeyConf

    pub(all) struct PrivateKeyConf {
    fingerprint : String
    key_file : String
    } derive(Eq,
    Debug
    )

    One signing key the request-signature check would verify against (← rest.PrivateKeyConf).

    PrivateKeyConf::equal

    PrivateKeyConf::not_equal

    fn PrivateKeyConf::not_equal(x : PrivateKeyConf, y : PrivateKeyConf) -> Bool

    RestConf

    pub(all) struct RestConf {
    service : ServiceConf
    cert_file : String
    key_file : String
    verbose : Bool
    max_conns : Int
    max_bytes : Int
    cpu_threshold : Int64
    signature : SignatureConf
    middlewares : MiddlewaresConf
    trace_ignore_paths : Array[String]
    }

    A REST service's configuration (← go-zero's rest.RestConf), embedding ServiceConf the way go-zero's does. The name, bind address and request timeout live on that embedded config — host(), port() and timeout_ms() read them — and everything else here is RestConf's own.

    max_bytes is an Int where go-zero uses int64: it is compared against a request's Content-Length, and its own range= tag caps it at 32 MiB.

    RestConf::from_json

    fn RestConf::from_json(src : String) -> RestConf raise Refused

    Load a RestConf from a JSON config string, with the same semantics as from_yaml.

    RestConf::from_yaml

    fn RestConf::from_yaml(src : String) -> RestConf raise Refused

    Load a RestConf from the YAML go-zero ships as etc/*.yaml. Keys are matched canonically, MOONZERO_* env variables override the file, and a value outside its options=/range= constraint is an error.

    Name and Port carry no default, exactly as in go-zero: a rest service that does not say who it is or where to listen fails to load.

    RestConf::host

    fn RestConf::host(self : RestConf) -> String

    The address the service binds.

    RestConf::new

    fn RestConf::new(service? : ServiceConf, cert_file? : String, key_file? : String, verbose? : Bool, max_conns? : Int, max_bytes? : Int, cpu_threshold? : Int64, signature? : SignatureConf, middlewares? : MiddlewaresConf, trace_ignore_paths? : Array[String]) -> RestConf

    A REST config with go-zero's defaults: no TLS, not verbose, 10000 connections, a 1 MiB body cap, a 90% CPU shed threshold, and the full middleware chain.

    RestConf::port

    fn RestConf::port(self : RestConf) -> Int

    The port the service binds.

    RestConf::timeout_ms

    fn RestConf::timeout_ms(self : RestConf) -> Int

    The per-request timeout budget in milliseconds; 0 disables it.

    RestConf::tls

    fn RestConf::tls(self : RestConf) -> Bool

    Whether a certificate and its key are both named.

    This library assembles an application, not a socket: the object it builds is handed to a host, and the host is what terminates TLS. These two paths are carried here so that host reads them from the same document as everything else — and a document that names only one of them is refused at load rather than leaving the service listening in the clear while its operator believes otherwise.

    RpcClientConf

    pub(all) struct RpcClientConf {
    target : String
    endpoints : Array[String]
    timeout_ms : Int
    non_block : Bool
    middlewares : RpcClientMiddlewaresConf
    } derive(Eq,
    Debug
    ,
    FromJson
    )

    zRPC client configuration (← go-zero's RpcClientConf): where a service is — a direct Target, a list of Endpoints, or a name the discovery layer resolves — plus the call timeout and which interceptors run.

    RpcClientConf::equal

    RpcClientConf::from_json

    fn RpcClientConf::from_json(src : String) -> RpcClientConf raise Refused

    Load an RpcClientConf from a JSON config string, filling omitted fields from the new() defaults.

    RpcClientConf::from_yaml

    fn RpcClientConf::from_yaml(src : String) -> RpcClientConf raise Refused

    Load an RpcClientConf from a YAML config string.

    RpcClientConf::new

    fn RpcClientConf::new(target? : String, endpoints? : Array[String], timeout_ms? : Int, non_block? : Bool, middlewares? : RpcClientMiddlewaresConf) -> RpcClientConf

    A client config with a 2s call timeout and the full interceptor chain.

    RpcClientConf::not_equal

    fn RpcClientConf::not_equal(x : RpcClientConf, y : RpcClientConf) -> Bool

    RpcClientMiddlewaresConf

    pub(all) struct RpcClientMiddlewaresConf {
    trace : Bool
    log : Bool
    prometheus : Bool
    breaker : Bool
    timeout : Bool
    } derive(Eq,
    Debug
    ,
    FromJson
    )

    Which of the zRPC client's interceptors are installed (← RpcClientMiddlewaresConf). Five, and all on by default.

    RpcClientMiddlewaresConf::equal

    RpcClientMiddlewaresConf::new

    fn RpcClientMiddlewaresConf::new(trace? : Bool, log? : Bool, prometheus? : Bool, breaker? : Bool, timeout? : Bool) -> RpcClientMiddlewaresConf

    The full client chain.

    RpcClientMiddlewaresConf::not_equal

    RpcServerConf

    pub(all) struct RpcServerConf {
    name : String
    host : String
    port : Int
    timeout_ms : Int
    cpu_threshold : Int64
    cpu_threshold_overload : Int64
    auth : Bool
    health : Bool
    middlewares : RpcServerMiddlewaresConf
    } derive(Eq,
    Debug
    ,
    FromJson
    )

    zRPC server configuration (← go-zero's RpcServerConf): the service name, the address it listens on, a per-call timeout in milliseconds (0 disables it), the two CPU thresholds, whether peers must authenticate, and which interceptors run.

    The registry block of the reference implementation's conf is modelled by the discovery layer instead; everything transport-facing is here.

    RpcServerConf::equal

    RpcServerConf::from_json

    fn RpcServerConf::from_json(src : String) -> RpcServerConf raise Refused

    Load an RpcServerConf from a JSON config string, filling omitted fields from the new() defaults — the lenient loader matching the reference implementation's ,optional/,default= config tags.

    RpcServerConf::from_yaml

    fn RpcServerConf::from_yaml(src : String) -> RpcServerConf raise Refused

    Load an RpcServerConf from a YAML config string, with the same default-filling semantics as from_json.

    RpcServerConf::new

    fn RpcServerConf::new(name? : String, host? : String, port? : Int, timeout_ms? : Int, cpu_threshold? : Int64, cpu_threshold_overload? : Int64, auth? : Bool, health? : Bool, middlewares? : RpcServerMiddlewaresConf) -> RpcServerConf

    Build an RPC server config with the reference implementation's defaults: the family's rpc port, a 2s timeout, 90% CPU as the shed threshold and 95% as the overload threshold.

    RpcServerConf::not_equal

    fn RpcServerConf::not_equal(x : RpcServerConf, y : RpcServerConf) -> Bool

    RpcServerMiddlewaresConf

    pub(all) struct RpcServerMiddlewaresConf {
    trace : Bool
    recover : Bool
    stat : Bool
    prometheus : Bool
    breaker : Bool
    shedding : Bool
    timeout : Bool
    auth : Bool
    } derive(Eq,
    Debug
    ,
    FromJson
    )

    Which of the zRPC server's own interceptors are installed (← go-zero's RpcServerMiddlewaresConf). All eight default to on; a service narrows the chain from its config rather than from code.

    RpcServerMiddlewaresConf::equal

    RpcServerMiddlewaresConf::new

    fn RpcServerMiddlewaresConf::new(trace? : Bool, recover? : Bool, stat? : Bool, prometheus? : Bool, breaker? : Bool, shedding? : Bool, timeout? : Bool, auth? : Bool) -> RpcServerMiddlewaresConf

    The full server chain, which is what the reference implementation defaults to.

    RpcServerMiddlewaresConf::not_equal

    ServiceConf

    pub(all) struct ServiceConf {
    name : String
    host : String
    port : Int
    timeout_ms : Int
    log_level :
    LogLevel

    } derive(Eq,
    FromJson
    )

    Service configuration (← go-zero's ServiceConf): the service name, its bind address, a request timeout, and the log level. timeout_ms is the per-request budget in milliseconds; 0 disables the deadline.

    ServiceConf::equal

    fn ServiceConf::equal(ServiceConf, ServiceConf) -> Bool

    ServiceConf::from_json

    fn ServiceConf::from_json(src : String) -> ServiceConf raise Refused

    Load a ServiceConf from a JSON config string, applying go-zero-style defaults for every omitted field (an empty {} yields exactly ServiceConf::new()). This is the lenient loader mirroring go-zero's conf.Load with ,optional/,default= struct tags: unlike the strict derived FromJson — reachable via @json.from_json and requiring every field present — a partial config is filled from the same defaults new() uses.

    Keys are matched canonically, so go-zero's Name/Host/Port/Timeout and moonzero's own timeout_ms/log_level spellings all load.

    Raises Refused on malformed JSON, a non-object root, a field of the wrong type, or a log level outside debug|info|error|severe.

    ServiceConf::from_yaml

    fn ServiceConf::from_yaml(src : String) -> ServiceConf raise Refused

    Load a ServiceConf from a YAML config string — the format go-zero actually ships (etc/*.yaml) — with the same lenient, default-filling semantics as from_json: an empty document yields exactly ServiceConf::new(), and each omitted field falls back to its new() default. The YAML is parsed by the self-built yaml_parse (block mappings, nesting, sequences, scalars, comments) into a Json object, then decoded by the shared field reader — so JSON and YAML configs agree field-for-field.

    Raises Refused on malformed YAML, a non-mapping root, a field of the wrong type, or a log level outside debug|info|error|severe.

    ServiceConf::new

    fn ServiceConf::new(name? : String, host? : String, port? : Int, timeout_ms? : Int, log_level? :
    LogLevel
    ) -> ServiceConf

    Build a config with sensible defaults (0.0.0.0:12000, 3s timeout, info).

    ServiceConf::not_equal

    fn ServiceConf::not_equal(x : ServiceConf, y : ServiceConf) -> Bool

    SignatureConf

    pub(all) struct SignatureConf {
    strict : Bool
    expiry_ms : Int64
    private_keys : Array[PrivateKeyConf]
    } derive(Eq,
    Debug
    )

    Request-signature settings (← rest.SignatureConf): whether an unsigned or badly-signed request is refused outright, how long a signature stays valid, and the keys it is checked against.

    moonzero loads and validates this config — a strict service with no keys is refused at assembly, as go-zero's ErrSignatureConfig does — but ships no content-signature layer to consume it.

    SignatureConf::equal

    SignatureConf::new

    fn SignatureConf::new(strict? : Bool, expiry_ms? : Int64, private_keys? : Array[PrivateKeyConf]) -> SignatureConf

    Signature settings that verify nothing: not strict, go-zero's one-hour expiry, no keys.

    SignatureConf::not_equal

    fn SignatureConf::not_equal(x : SignatureConf, y : SignatureConf) -> Bool

    canonical_key

    fn canonical_key(key : String) -> String

    go-zero's canonical form for a config key (← the WithCanonicalKeyFunc that conf.Load installs): lowercased, with _ and - dropped. Every lookup compares on this form, so MaxBytes, maxBytes, max_bytes and max-bytes all name one field — which is what lets a genuine go-zero etc/*.yaml, whose keys are all PascalCase, load into a config instead of silently yielding defaults.

    port

    let port : Int

    The default port a moonzero service listens on.

    12000 is the family's number, not go-zero's 8888: every example, every document and every local run in this ecosystem points at the same place, and on a development machine 8888 is somebody else's already.

    rpc_port

    let rpc_port : Int

    The default port the zRPC server listens on.

    gRPC shares 12000 with HTTP wherever one listener carries both, but a moonzero process binds RestEngine and RpcServer separately — two listeners cannot hold one port — so the second takes the next number.