Sign in

    moonbitstack/moonzero/conf does not have a README file

    ConfigError

    pub(all) suberror ConfigError {
    ConfigError(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 ConfigError

    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 ConfigError

    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 ConfigError

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

    Conf::list

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

    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

    fn Conf::of_json(src : String) -> Conf raise ConfigError

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

    Conf::of_yaml

    fn Conf::of_yaml(src : String) -> Conf raise ConfigError

    Load a document from the YAML go-zero ships as etc/*.yaml. Raises ConfigError on malformed YAML or a non-mapping root.

    Conf::string

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

    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 ConfigError

    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 ConfigError

    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 ConfigError

    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 TLS is configured — go-zero serves HTTPS once both files are named.

    RpcServerConf

    pub(all) struct RpcServerConf {
    name : String
    host : String
    port : Int
    timeout_ms : Int
    } derive(Eq,
    Debug
    ,
    FromJson
    )

    zRPC server configuration (← go-zero's zrpc.RpcServerConf): the service name, the address it listens on, and a per-call timeout in milliseconds (0 disables it). The registry/etcd fields of go-zero's conf are modelled by the separate discovery layer; this is the transport-facing core.

    RpcServerConf::equal

    RpcServerConf::from_json

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

    Load an RpcServerConf from a JSON config string, filling omitted fields from the new() defaults — the lenient loader matching go-zero's ,optional/,default= config tags. Keys are matched canonically, so go-zero's Name/Host/Port/Timeout load as readily as moonzero's own timeout_ms.

    RpcServerConf::from_yaml

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

    Load an RpcServerConf from a YAML config string (self-built yaml_parse), with the same default-filling semantics as from_json.

    RpcServerConf::new

    fn RpcServerConf::new(name? : String, host? : String, port? : Int, timeout_ms? : Int) -> RpcServerConf

    Build an RPC server config with go-zero-style defaults (0.0.0.0:8080, 2s timeout).

    RpcServerConf::not_equal

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

    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 ConfigError

    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 ConfigError 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 ConfigError

    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 ConfigError 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.