cherryProfile

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 11 Imported by: 17

Documentation

Overview

Package cherryProfile provides profile configuration file loading and node config resolution for the Cherry framework.

Core responsibilities:

  • Load profile JSON config files (with include file merging)
  • Resolve per-node configuration (node identity, address, settings)
  • Provide type-safe config reading via the ProfileJSON interface

Note: this package uses package-level global state (cfg). Only one Application instance per process is supported. Multiple instances will overwrite each other's global config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug() bool

Debug returns whether debug mode is enabled.

func Env added in v1.3.0

func Env() string

Env returns the current environment name (e.g. "dev", "test", "prod").

func GetConfig added in v1.1.0

func GetConfig(path ...any) cfacade.ProfileJSON

GetConfig reads a sub-config from the global config tree at the given path. Path semantics match jsoniter.Get. Must be called after Init(), otherwise cfg.jsonConfig is nil and this will panic.

func GetNodeWithConfig added in v1.2.3

func GetNodeWithConfig(config *Config, nodeID string) (cfacade.INode, error)

GetNodeWithConfig searches the "node" section of the profile config for a node matching nodeID and returns it as an INode.

Matching logic (via findNodeID):

  1. Exact string match against the "node_id" field
  2. Regex match if the config value looks like a regex (^...$)
  3. Membership check if the config value is a JSON array of IDs

func Init

func Init(filePath, nodeID string) (cfacade.INode, error)

Init loads the profile config file and returns the configuration for the specified node.

filePath is the path to the profile JSON file, nodeID is the target node identifier.

Loading steps:

  1. Read the main profile config file
  2. Merge files referenced by the "include" field (include keys are overridden by the main config)
  3. Search the "node" section for a node matching nodeID

The returned INode provides the node's address, type, settings, etc. Also initializes the package-level global config (cfg) for use by Path, Name, Env, Debug, PrintLevel, and GetConfig.

func LoadNode added in v1.1.5

func LoadNode(nodeID string) (cfacade.INode, error)

LoadNode looks up a node from the already-loaded global config. Must be called after Init(); panics if cfg.jsonConfig is nil.

func Name

func Name() string

Name returns the profile config filename (e.g. "dev.json").

func Path added in v1.3.0

func Path() string

Path returns the absolute path to the profile config directory.

func PrintLevel added in v1.1.29

func PrintLevel() string

PrintLevel returns the cherry log output level (e.g. "debug", "info", "warn", "error").

Types

type Config

type Config struct {
	jsoniter.Any
}

Config wraps jsoniter.Any and provides type-safe config reading methods with default value support.

By embedding jsoniter.Any, Config inherits all native jsoniter methods (Get, ToString, ToBool, etc.) while adding typed getters with fallback defaults (GetString, GetBool, GetInt64, etc.) and an Unmarshal helper.

Note: because jsoniter.Any is embedded, callers can still use its native methods directly, which bypass Config's default-value logic. Prefer the typed getter methods defined on Config.

func LoadFile added in v1.4.16

func LoadFile(filePath, fileName string) (*Config, error)

LoadFile loads and merges profile config files.

Merge strategy:

  1. Read the main config file (fileName) into profileMaps
  2. Read files listed in the "include" field of the main config into includeMaps
  3. Merge includeMaps into rootMaps first, then merge profileMaps into rootMaps Keys in the main config override matching keys from include files (deep merge)

Returns the merged Config object.

func Wrap added in v1.1.29

func Wrap(val any) *Config

Wrap creates a Config from an arbitrary value by delegating to jsoniter.Wrap.

func (*Config) GetBool added in v1.1.29

func (p *Config) GetBool(path any, defaultVal ...bool) bool

GetBool reads a bool value at path. Returns defaultVal[0] if the path is missing or invalid; returns false if no default is provided.

func (*Config) GetConfig added in v1.1.29

func (p *Config) GetConfig(path ...any) cfacade.ProfileJSON

GetConfig returns a sub-config at the given path as a ProfileJSON. Path semantics match jsoniter.Get.

func (*Config) GetDuration added in v1.2.7

func (p *Config) GetDuration(path any, defaultVal ...time.Duration) time.Duration

GetDuration reads an integer value at path and casts it to time.Duration. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

IMPORTANT: the returned value is a raw time.Duration (nanoseconds). Callers must multiply by the intended unit, e.g.:

delay := config.GetDuration("reconnect_delay", 1) * time.Second

func (*Config) GetFloat32 added in v1.5.3

func (p *Config) GetFloat32(path any, defaultVal ...float32) float32

GetFloat32 reads a float32 value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) GetFloat64 added in v1.5.3

func (p *Config) GetFloat64(path any, defaultVal ...float64) float64

GetFloat64 reads a float64 value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) GetInt added in v1.1.29

func (p *Config) GetInt(path any, defaultVal ...int) int

GetInt reads an int value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) GetInt32 added in v1.1.29

func (p *Config) GetInt32(path any, defaultVal ...int32) int32

GetInt32 reads an int32 value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) GetInt64 added in v1.1.29

func (p *Config) GetInt64(path any, defaultVal ...int64) int64

GetInt64 reads an int64 value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) GetString added in v1.1.29

func (p *Config) GetString(path any, defaultVal ...string) string

GetString reads a string value at path. Returns defaultVal[0] if the path is missing or invalid; returns "" if no default is provided.

func (*Config) GetUint added in v1.5.3

func (p *Config) GetUint(path any, defaultVal ...uint) uint

GetUint reads a uint value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) GetUint32 added in v1.5.3

func (p *Config) GetUint32(path any, defaultVal ...uint32) uint32

GetUint32 reads a uint32 value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) GetUint64 added in v1.5.3

func (p *Config) GetUint64(path any, defaultVal ...uint64) uint64

GetUint64 reads a uint64 value at path. Returns defaultVal[0] if the path is missing or invalid; returns 0 if no default is provided.

func (*Config) Unmarshal added in v1.3.6

func (p *Config) Unmarshal(value any) error

Unmarshal deserializes the current config value into the given target. Returns the underlying jsoniter error if the value is invalid.

type Node added in v1.1.5

type Node struct {
	// contains filtered or unexported fields
}

Node is the concrete implementation of cfacade.INode. It holds a single cluster node's identity, network addresses, and per-node settings loaded from the profile config.

func (*Node) Address added in v1.1.5

func (n *Node) Address() string

Address returns the public listen address (for frontend nodes).

func (*Node) Enabled added in v1.1.5

func (n *Node) Enabled() bool

Enabled returns whether this node is enabled.

func (*Node) NodeID added in v1.3.19

func (n *Node) NodeID() string

NodeID returns the globally unique node identifier.

func (*Node) NodeType added in v1.1.5

func (n *Node) NodeType() string

NodeType returns the node type (e.g. "game", "gate", "map").

func (*Node) RpcAddress added in v1.1.5

func (n *Node) RpcAddress() string

RpcAddress returns the RPC listen address (reserved).

func (*Node) Settings added in v1.1.5

func (n *Node) Settings() cfacade.ProfileJSON

Settings returns the per-node settings subtree from the profile config.

func (*Node) String added in v1.1.5

func (n *Node) String() string

String returns a human-readable representation of the node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL