mustmap

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package mustmap provides map-specific assertion utilities with panic-on-failure semantics Implements type-safe map validation functions using Go generics and standard maps package Supports comparison operations, length validation, and element existence checking on map types Integrates with zap structured logging to provide detailed context when assertions are not met

mustmap 提供 map 特定的断言工具,带 panic-on-failure 语义 使用 Go 泛型和标准 maps 包实现类型安全的 map 验证函数 支持 map 类型的比较操作、长度验证和元素存在性检查 与 zap 结构化日志集成,当断言不满足时提供详细上下文

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff added in v0.0.17

func Diff[K, V comparable](a, b map[K]V)

Diff compares two maps to ensure distinction. If matching, it panics. Diff 比较两个 map 是否不相等,如果相等,则触发 panic。

func Different added in v0.0.16

func Different[K, V comparable](a, b map[K]V)

Different compares two maps to ensure distinction. If matching, it panics. Different 比较两个 map 是否不相等,如果相等,则触发 panic。

func Equals

func Equals[K, V comparable](a, b map[K]V)

Equals compares two maps matching. If not matching, it panics. Equals 比较两个 map 是否相等,如果不相等,则触发 panic。

func Get

func Get[K, V comparable](a map[K]V, key K) V

Get func get value of element from the map. If the element does not exist, it panics. Get 根据给定的键从 map 中检索值,如果键不存在,则触发 panic。

func Have

func Have[K comparable, V any](a map[K]V) map[K]V

Have checks if a map is non-vacant. If vacant, it panics. Have 检查一个 map 是否非空,如果为空,则触发 panic。

func Len

func Len[K comparable, V any](a map[K]V, n int)

Len checks if the length of a map matches n. If not, it panics. Len 是 Length 的简写版本,检查一个 map 的长度是否等于 n,如果不等,则触发 panic。

func Length

func Length[K comparable, V any](a map[K]V, n int)

Length checks if the length of a map matches n. If not, it panics. Length 检查一个 map 的长度是否等于 n,如果不等,则触发 panic。

func Nice

func Nice[K comparable, V any](a map[K]V) map[K]V

Nice checks if a map is non-vacant and returns it. If vacant, it panics. Nice 检查一个 map 是否非空并返回它,如果为空,则触发 panic。

func None added in v0.0.10

func None[K comparable, V any](a map[K]V)

None ensures the map is vacant, panics if not. None 确保 map 内容为空,若有元素则 panic。

func Zero added in v0.0.23

func Zero[K comparable, V any](a map[K]V)

Zero ensures the map is vacant, panics if contains entries. Zero 确保 map 为空,若有条目则触发 panic。

Types

This section is empty.

Jump to

Keyboard shortcuts

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