// gocyclo が警告: cyclomatic complexity 12 of func ParseConfig is high (> 10) funcParseConfig(data map[string]any) (*Config, error) { cfg := &Config{}
if v, ok := data["host"]; ok { // +1, +1 if s, ok := v.(string); ok { // +1, +1 cfg.Host = s } } if v, ok := data["port"]; ok { // +1, +1 if n, ok := v.(float64); ok { // +1, +1 cfg.Port = int(n) } } if v, ok := data["debug"]; ok { // +1, +1 if b, ok := v.(bool); ok { // +1, +1 cfg.Debug = b } } return cfg, nil }
funcgetStringOr(data map[string]any, key, fallback string)string { if v, ok := data[key]; ok { if s, ok := v.(string); ok { return s } } return fallback }