rese

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 3 Imported by: 0

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

rese

rese = res(ult) + e(rror) - Streamline Go error handling with elegant result extraction.

Transform verbose error checking into clean, expressive code.

Why rese?

Traditional Go error handling:

num, err := getNumber()
if err != nil {
    panic(err)
}

text, err := getText()
if err != nil {
    panic(err)
}

result := fmt.Sprintf("%s: %d", text, num)

With rese:

result := fmt.Sprintf("%s: %d", rese.V1(getText()), rese.V1(getNumber()))

Clean, concise, and safe!


CHINESE README

中文说明


Installation

go get github.com/yylego/rese

Quick Start

Basic Value Handling
// V series - Check error and return value
result := rese.V1(getValue())  // Returns value and panics when error is present
a, b := rese.V2(getTwoValues()) // Returns two values and panics when error is present
Pointer Validation
// P series - Check error AND ensure pointer is non-nil
ptr := rese.P1(getPointer())  // Returns non-nil pointer and panics when error/nil is present
Non-Zero Value Validation
// C series - Check error AND ensure value is non-zero
count := rese.C1(getCount())  // Returns non-zero value and panics when error/zero is present

Function Series Overview

rese provides multiple function series (0-9 parameters each) for different validation needs:

Series Purpose Example Usage
V (Value) Check error, return value(s) rese.V1(getValue())
P (Pointer) Check error + pointer non-nil rese.P1(getPointer())
C (Comparable) Check error + value non-zero rese.C1(getCount())
A (Array/Slice) Check error + slice has elements rese.A1(getItems())
M (Map) Check error + map has entries rese.M1(getMapping())
F (Function) Execute function + V series rese.F1(getValue)
R (Run pointer) Execute function + P series rese.R1(getPointer)
resb Subpackage (Boolean Results)

Handle (value, bool) return patterns:

Series Purpose Example Usage
resb.V Check bool, return value(s) resb.V1(getValue())
resb.P Check bool + pointer non-nil resb.P1(getPointer())
resb.C Check bool + value non-zero resb.C1(getCount())

Usage

Example 1: Value Series (V)
package main

import (
	"fmt"

	"github.com/yylego/rese"
)

// getValue simulates a function that returns a value with potential error
// Demonstrates error handling with V1 function
func getValue() (string, error) {
	return "success-result", nil
}

// getNumber simulates a function that returns a numeric value with potential error
// Used to demonstrate V1 with different data types
func getNumber() (int, error) {
	return 42, nil
}

// getTwoValues demonstrates function returning two values with potential error
// Shows V2 usage for multiple value extraction
func getTwoValues() (string, int, error) {
	return "data", 100, nil
}

func main() {
	// Example 1: Basic V1 usage - extracts value when no error
	// When error is present, V1 panics
	result := rese.V1(getValue())
	fmt.Println("Result:", result)

	// Example 2: V1 with numeric type
	// Demonstrates V1 works with different data types
	number := rese.V1(getNumber())
	fmt.Println("Number:", number)

	// Example 3: V2 usage - extracts two values when no error
	// Shows handling of multiple return values
	text, count := rese.V2(getTwoValues())
	fmt.Println("Text:", text, "Count:", count)

	// Example 4: Compact inline usage
	// Demonstrates clean code without intermediate variables
	message := fmt.Sprintf("Got %s with count %d", rese.V1(getValue()), rese.V1(getNumber()))
	fmt.Println(message)
}

⬆️ Source: Source

Example 2: Pointer Series (P)
package main

import (
	"fmt"

	"github.com/yylego/rese"
)

// Account represents a simple account data structure
// Used to demonstrate pointer validation with P1
type Account struct {
	Name string
	Age  int
}

// getAccount simulates fetching account data
// Returns pointer to Account with potential error
func getAccount() (*Account, error) {
	return &Account{Name: "Alice", Age: 30}, nil
}

// Config represents application configuration
// Used to demonstrate P series with different types
type Config struct {
	Host string
	Port int
}

// getConfig simulates fetching configuration
// Returns pointer to Config with potential error
func getConfig() (*Config, error) {
	return &Config{Host: "localhost", Port: 8080}, nil
}

// getTwoPointers demonstrates function returning two pointers with potential error
// Shows P2 usage for multiple pointer validation
func getTwoPointers() (*Account, *Config, error) {
	return &Account{Name: "Bob", Age: 25}, &Config{Host: "0.0.0.0", Port: 9090}, nil
}

func main() {
	// Example 1: Basic P1 usage - validates pointer is non-nil
	// Panics when error is present and when pointer is nil
	account := rese.P1(getAccount())
	fmt.Printf("Account: %s, Age: %d\n", account.Name, account.Age)

	// Example 2: P1 with different type
	// Demonstrates P1 works with various pointer types
	config := rese.P1(getConfig())
	fmt.Printf("Config: %s:%d\n", config.Host, config.Port)

	// Example 3: P2 usage - validates two pointers
	// Shows handling of multiple pointer return values
	acc, cfg := rese.P2(getTwoPointers())
	fmt.Printf("Account: %s, Config: %s:%d\n", acc.Name, cfg.Host, cfg.Port)

	// Example 4: Compact inline usage with pointer access
	// Demonstrates clean code without intermediate variables
	message := fmt.Sprintf("Account %s is %d years old", rese.P1(getAccount()).Name, rese.P1(getAccount()).Age)
	fmt.Println(message)
}

⬆️ Source: Source

Example 3: Multiple Series (resb, A, M)
package main

import (
	"fmt"

	"github.com/yylego/rese"
	"github.com/yylego/rese/resb"
)

// lookupValue simulates a map lookup operation
// Returns value with bool flag indicating success
func lookupValue(key string) (string, bool) {
	data := map[string]string{
		"name": "Alice",
		"city": "Shanghai",
		"role": "Engineer",
	}
	value, ok := data[key]
	return value, ok
}

// lookupNumber simulates retrieving a numeric value
// Returns number with bool flag indicating presence
func lookupNumber(key string) (int, bool) {
	data := map[string]int{
		"age":   30,
		"score": 95,
		"count": 100,
	}
	value, ok := data[key]
	return value, ok
}

// getAccountPointer simulates fetching account data with bool flag
// Returns pointer with bool flag instead of error
func getAccountPointer() (*struct{ Name string }, bool) {
	return &struct{ Name string }{Name: "Bob"}, true
}

// getItems demonstrates slice return with error
// Shows A1 usage for slice validation
func getItems() ([]string, error) {
	return []string{"apple", "banana", "orange"}, nil
}

// getScores demonstrates map return with error
// Shows M1 usage for map validation
func getScores() (map[string]int, error) {
	return map[string]int{"math": 95, "english": 88}, nil
}

func main() {
	// Example 1: resb.V1 usage - checks bool and returns value
	// Panics when bool is false
	name := resb.V1(lookupValue("name"))
	fmt.Println("Name:", name)

	// Example 2: resb.V1 with numeric type
	// Demonstrates resb works with different data types
	age := resb.V1(lookupNumber("age"))
	fmt.Println("Age:", age)

	// Example 3: resb.P1 usage - validates pointer and bool
	// Combines pointer check with bool validation
	account := resb.P1(getAccountPointer())
	fmt.Println("Account:", account.Name)

	// Example 4: A1 usage - validates slice has elements
	// Panics when error is present and when slice is nil/has no elements
	items := rese.A1(getItems())
	fmt.Println("Items:", items)

	// Example 5: M1 usage - validates map has entries
	// Panics when error is present and when map is nil/has no entries
	scores := rese.M1(getScores())
	fmt.Println("Scores:", scores)

	// Example 6: Compact inline usage with resb
	// Demonstrates clean map lookup without intermediate variables
	message := fmt.Sprintf("%s from %s works as %s",
		resb.V1(lookupValue("name")),
		resb.V1(lookupValue("city")),
		resb.V1(lookupValue("role")))
	fmt.Println(message)
}

⬆️ Source: Source


Examples

C Series - Comparable Value Validation

Check non-zero integer:

userID := rese.C1(getUserID())  // Returns 12345, panics if error or zero
fmt.Println("User ID:", userID)

Validate multiple comparable values:

id, status := rese.C2(getIDAndStatus())  // Both must be non-zero
A Series - Array/Slice Validation

Ensure slice has elements:

items := rese.A1(getItems())  // Returns []string{"apple", "banana", "orange"}
fmt.Println("Items:", items)
M Series - Map Validation

Ensure map has entries:

scores := rese.M1(getScores())  // Returns map[string]int{"math": 95, "english": 88}
fmt.Println("Scores:", scores)
F Series - Function Execution

Execute function and validate:

data := rese.F1(fetchData)  // Executes fetchData(), returns "data loaded"
fmt.Println(data)

Execute with multiple returns:

user, config := rese.F2(initialize)  // Executes and validates two values
Boolean Result Handling (resb)

Handle map lookup results:

value := resb.V1(lookupValue())  // Returns "found", panics if not found
fmt.Println("Value:", value)

Check bool flag:

config := resb.V1(m["key"])  // Panics if key doesn't exist

Complete Function Reference

V Series - Value Validation
Function Description
V1[T1](v1 T1, err) T1 Check error, return 1 value
V2[T1,T2](v1 T1, v2 T2, err) (T1,T2) Check error, return 2 values
V3 ~ V9 Check error, return 3-9 values

Note: For V0(err error) with no return value, consider using must package instead.

P Series - Pointer Validation
Function Description
P1[T1](v1 *T1, err) *T1 Check error + pointer non-nil, return 1 pointer
P2[T1,T2](v1 *T1, v2 *T2, err) (*T1,*T2) Check error + pointers non-nil, return 2 pointers
P3 ~ P9 Check error + pointers non-nil, return 3-9 pointers

Note: P0 is same as V0, use must package for simple error checking.

C Series - Comparable Validation
Function Description
C1[T1 comparable](v1 T1, err) T1 Check error + value non-zero, return 1 value
C2[T1,T2 comparable](v1 T1, v2 T2, err) (T1,T2) Check error + values non-zero, return 2 values
C3 ~ C9 Check error + values non-zero, return 3-9 values

Note: C0 is same as V0, use must package for simple error checking.

A Series - Array/Slice Validation
Function Description
A1[T1](v1 []T1, err) []T1 Check error + slice has elements, return 1 slice
A2[T1,T2](v1 []T1, v2 []T2, err) ([]T1,[]T2) Check error + slices have elements, return 2 slices
A3 ~ A9 Check error + slices have elements, return 3-9 slices

Note: A0 is same as V0, use must package for simple error checking.

M Series - Map Validation
Function Description
M1[K1,V1](m1 map[K1]V1, err) map[K1]V1 Check error + map has entries, return 1 map
M2[K1,K2,V1,V2](m1 map[K1]V1, m2 map[K2]V2, err) (map[K1]V1, map[K2]V2) Check error + maps have entries, return 2 maps
M3 ~ M9 Check error + maps have entries, return 3-9 maps

Note: M0 is same as V0, use must package for simple error checking.

F Series - Function Execution (Value)
Function Description
F1[T1](run func() (T1, error)) T1 Execute function, apply V1 validation
F2[T1,T2](run func() (T1, T2, error)) (T1,T2) Execute function, apply V2 validation
F3 ~ F9 Execute function, apply V3-V9 validation

Note: F0 is same as V0, use must package for simple error checking.

R Series - Function Execution (Pointer)
Function Description
R1[T1](run func() (*T1, error)) *T1 Execute function, apply P1 validation
R2[T1,T2](run func() (*T1, *T2, error)) (*T1,*T2) Execute function, apply P2 validation
R3 ~ R9 Execute function, apply P3-P9 validation

Note: R0 is same as V0, use must package for simple error checking.


resb Package - Boolean Result Handling

The resb subpackage handles functions that return (value, bool) instead of (value, error).

Common Use Cases
// Map lookup - returns (value, bool)
func lookupConfig(key string) (string, bool) {
    cfg := map[string]string{"host": "localhost", "port": "8080"}
    return cfg[key]
}


// Using resb.V1 to handle (value, bool) results
config := resb.V1(lookupConfig("host"))      // Panics if key not found

Explore more error handling packages in this ecosystem:

Advanced Packages
  • must - Must-style assertions with rich type support and detailed error context
  • rese - Result extraction with panic, focused on safe value unwrapping (this project)
Foundation Packages
  • done - Simple, focused error handling with method chaining
  • sure - Generates code that creates custom validation methods

Each package targets different use cases, from quick prototyping to production systems with comprehensive error handling.


📄 License

MIT License. See LICENSE.


🤝 Contributing

Contributions are welcome! Report bugs, suggest features, and contribute code:

  • 🐛 Found a mistake? Open an issue on GitHub with reproduction steps
  • 💡 Have a feature idea? Create an issue to discuss the suggestion
  • 📖 Documentation confusing? Report it so we can improve
  • 🚀 Need new features? Share the use cases to help us understand requirements
  • Performance issue? Help us optimize through reporting slow operations
  • 🔧 Configuration problem? Ask questions about complex setups
  • 📢 Follow project progress? Watch the repo to get new releases and features
  • 🌟 Success stories? Share how this package improved the workflow
  • 💬 Feedback? We welcome suggestions and comments

🔧 Development

New code contributions, follow this process:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/rese.git).
  3. Navigate: Navigate to the cloned project (cd rese)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and follow Go code style conventions
  7. Documentation: Update documentation to support client-facing changes and use significant commit messages
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.


🌟 Support

Welcome to contribute to this project via submitting merge requests and reporting issues.

Project Support:

  • Give GitHub stars if this project helps you
  • 🤝 Share with teammates and (golang) programming friends
  • 📝 Write tech blogs about development tools and workflows - we provide content writing support
  • 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene

Have Fun Coding with this package! 🎉🎉🎉


GitHub Stars

starring

Documentation

Overview

Package rese: Result extraction with error handling - Streamline Go error handling patterns Transform verbose error checking into clean, expressive code with type-safe generic functions Provides multiple function series (V, P, C, A) for different validation scenarios Each series supports 0-9 parameters with error checking and value validation

rese: 结果提取与错误处理 - 简化 Go 错误处理模式 将冗长的错误检查转换为简洁、富有表现力的类型安全泛型函数代码 提供多个函数系列(V、P、C、A)用于不同的验证场景 每个系列支持 0-9 个参数,带有错误检查和值验证

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func A0

func A0(err error)

A0 checks error and panics if present Use github.com/yylego/must package for A0 scenario

A0 检查错误,如果存在则 panic A0 场景建议使用 github.com/yylego/must 包

func A1

func A1[T1 any](v1 []T1, err error) []T1

A1 checks error and validates slice has elements, returns single slice Panics on error and panics when slice is nil/has no elements

A1 检查错误并验证切片有元素,返回单个切片 当有错误时 panic,当切片为 nil/无元素时 panic

func A2

func A2[T1, T2 any](v1 []T1, v2 []T2, err error) ([]T1, []T2)

A2 checks error and slices have elements, returns two slices Panics on error and panics when some slice is nil/has no elements

A2 检查错误和切片非空,返回两个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func A3

func A3[T1, T2, T3 any](v1 []T1, v2 []T2, v3 []T3, err error) ([]T1, []T2, []T3)

A3 checks error and slices have elements, returns three slices Panics on error and panics when some slice is nil/has no elements

A3 检查错误和切片非空,返回三个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func A4

func A4[T1, T2, T3, T4 any](v1 []T1, v2 []T2, v3 []T3, v4 []T4, err error) ([]T1, []T2, []T3, []T4)

A4 checks error and slices have elements, returns 4 slices Panics on error and panics when some slice is nil/has no elements

A4 检查错误和切片非空,返回 4 个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func A5

func A5[T1, T2, T3, T4, T5 any](v1 []T1, v2 []T2, v3 []T3, v4 []T4, v5 []T5, err error) ([]T1, []T2, []T3, []T4, []T5)

A5 checks error and slices have elements, returns five slices Panics on error and panics when some slice is nil/has no elements

A5 检查错误和切片非空,返回五个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func A6

func A6[T1, T2, T3, T4, T5, T6 any](v1 []T1, v2 []T2, v3 []T3, v4 []T4, v5 []T5, v6 []T6, err error) ([]T1, []T2, []T3, []T4, []T5, []T6)

A6 checks error and slices have elements, returns six slices Panics on error and panics when some slice is nil/has no elements

A6 检查错误和切片非空,返回六个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func A7

func A7[T1, T2, T3, T4, T5, T6, T7 any](v1 []T1, v2 []T2, v3 []T3, v4 []T4, v5 []T5, v6 []T6, v7 []T7, err error) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7)

A7 checks error and slices have elements, returns seven slices Panics on error and panics when some slice is nil/has no elements

A7 检查错误和切片非空,返回七个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func A8

func A8[T1, T2, T3, T4, T5, T6, T7, T8 any](v1 []T1, v2 []T2, v3 []T3, v4 []T4, v5 []T5, v6 []T6, v7 []T7, v8 []T8, err error) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8)

A8 checks error and slices have elements, returns eight slices Panics on error and panics when some slice is nil/has no elements

A8 检查错误和切片非空,返回八个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func A9

func A9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](v1 []T1, v2 []T2, v3 []T3, v4 []T4, v5 []T5, v6 []T6, v7 []T7, v8 []T8, v9 []T9, err error) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9)

A9 checks error and slices have elements, returns nine slices Panics on error and panics when some slice is nil/has no elements

A9 检查错误和切片非空,返回九个切片 当有错误时 panic,当某个切片为 nil/无元素时 panic

func C0

func C0(err error)

C0 checks error and panics if present Use github.com/yylego/must package for C0 scenario

C0 检查错误,如果存在则 panic C0 场景建议使用 github.com/yylego/must 包

func C1

func C1[T1 comparable](v1 T1, err error) T1

C1 checks error and value non-zero, returns single comparable value Panics on error and panics when value is zero

C1 检查错误和值非零,返回单个可比较值 当有错误时 panic,当值为零时 panic

func C2

func C2[T1, T2 comparable](v1 T1, v2 T2, err error) (T1, T2)

C2 checks error and values non-zero, returns two comparable values Panics on error and panics when some value is zero

C2 检查错误和值非零,返回两个可比较值 当有错误时 panic,当某个值为零时 panic

func C3

func C3[T1, T2, T3 comparable](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)

C3 checks error and values non-zero, returns three comparable values Panics on error and panics when some value is zero

C3 检查错误和值非零,返回三个可比较值 当有错误时 panic,当某个值为零时 panic

func C4

func C4[T1, T2, T3, T4 comparable](v1 T1, v2 T2, v3 T3, v4 T4, err error) (T1, T2, T3, T4)

C4 checks error and values non-zero, returns 4 comparable values Panics on error and panics when some value is zero

C4 检查错误和值非零,返回 4 个可比较值 当有错误时 panic,当某个值为零时 panic

func C5

func C5[T1, T2, T3, T4, T5 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, err error) (T1, T2, T3, T4, T5)

C5 checks error and values non-zero, returns five comparable values Panics on error and panics when some value is zero

C5 检查错误和值非零,返回五个可比较值 当有错误时 panic,当某个值为零时 panic

func C6

func C6[T1, T2, T3, T4, T5, T6 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, err error) (T1, T2, T3, T4, T5, T6)

C6 checks error and values non-zero, returns six comparable values Panics on error and panics when some value is zero

C6 检查错误和值非零,返回六个可比较值 当有错误时 panic,当某个值为零时 panic

func C7

func C7[T1, T2, T3, T4, T5, T6, T7 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, err error) (T1, T2, T3, T4, T5, T6, T7)

C7 checks error and values non-zero, returns seven comparable values Panics on error and panics when some value is zero

C7 检查错误和值非零,返回七个可比较值 当有错误时 panic,当某个值为零时 panic

func C8

func C8[T1, T2, T3, T4, T5, T6, T7, T8 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, err error) (T1, T2, T3, T4, T5, T6, T7, T8)

C8 checks error and values non-zero, returns eight comparable values Panics on error and panics when some value is zero

C8 检查错误和值非零,返回八个可比较值 当有错误时 panic,当某个值为零时 panic

func C9

func C9[T1, T2, T3, T4, T5, T6, T7, T8, T9 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, err error) (T1, T2, T3, T4, T5, T6, T7, T8, T9)

C9 checks error and values non-zero, returns nine comparable values Panics on error and panics when some value is zero

C9 检查错误和值非零,返回九个可比较值 当有错误时 panic,当某个值为零时 panic

func F0

func F0(run func() error)

F0 executes function and checks error, applying V0 validation Use github.com/yylego/must package for F0 scenario

F0 执行函数并检查错误,应用 V0 验证 F0 场景建议使用 github.com/yylego/must 包

func F1

func F1[T1 any](run func() (T1, error)) T1

F1 executes function and checks the result, applying V1 validation Returns single value from function and panics when error is present

F1 执行函数并检查结果,应用 V1 验证 返回函数的单个值,当有错误时 panic

func F2

func F2[T1, T2 any](run func() (T1, T2, error)) (T1, T2)

F2 executes function and checks the result, applying V2 validation Returns two values from function and panics when error is present

F2 执行函数并检查结果,应用 V2 验证 返回函数的两个值,当有错误时 panic

func F3

func F3[T1, T2, T3 any](run func() (T1, T2, T3, error)) (T1, T2, T3)

F3 executes function and checks the result, applying V3 validation Returns three values from function and panics when error is present

F3 执行函数并检查结果,应用 V3 验证 返回函数的三个值,当有错误时 panic

func F4

func F4[T1, T2, T3, T4 any](run func() (T1, T2, T3, T4, error)) (T1, T2, T3, T4)

F4 executes function and checks the result, applying V4 validation Returns 4 values from function and panics when error is present

F4 执行函数并检查结果,应用 V4 验证 返回函数的 4 个值,当有错误时 panic

func F5

func F5[T1, T2, T3, T4, T5 any](run func() (T1, T2, T3, T4, T5, error)) (T1, T2, T3, T4, T5)

F5 executes function and checks the result, applying V5 validation Returns 5 values from function and panics when error is present

F5 执行函数并检查结果,应用 V5 验证 返回函数的 5 个值,当有错误时 panic

func F6

func F6[T1, T2, T3, T4, T5, T6 any](run func() (T1, T2, T3, T4, T5, T6, error)) (T1, T2, T3, T4, T5, T6)

F6 executes function and checks the result, applying V6 validation Returns 6 values from function and panics when error is present

F6 执行函数并检查结果,应用 V6 验证 返回函数的 6 个值,当有错误时 panic

func F7

func F7[T1, T2, T3, T4, T5, T6, T7 any](run func() (T1, T2, T3, T4, T5, T6, T7, error)) (T1, T2, T3, T4, T5, T6, T7)

F7 executes function and checks the result, applying V7 validation Returns 7 values from function and panics when error is present

F7 执行函数并检查结果,应用 V7 验证 返回函数的 7 个值,当有错误时 panic

func F8

func F8[T1, T2, T3, T4, T5, T6, T7, T8 any](run func() (T1, T2, T3, T4, T5, T6, T7, T8, error)) (T1, T2, T3, T4, T5, T6, T7, T8)

F8 executes function and checks the result, applying V8 validation Returns 8 values from function and panics when error is present

F8 执行函数并检查结果,应用 V8 验证 返回函数的 8 个值,当有错误时 panic

func F9

func F9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](run func() (T1, T2, T3, T4, T5, T6, T7, T8, T9, error)) (T1, T2, T3, T4, T5, T6, T7, T8, T9)

F9 executes function and checks the result, applying V9 validation Returns 9 values from function and panics when error is present

F9 执行函数并检查结果,应用 V9 验证 返回函数的 9 个值,当有错误时 panic

func M0

func M0(err error)

M0 checks error and panics if present Use github.com/yylego/must package for M0 scenario

M0 检查错误,如果存在则 panic M0 场景建议使用 github.com/yylego/must 包

func M1

func M1[K1 comparable, V1 any](m1 map[K1]V1, err error) map[K1]V1

M1 checks error and map has entries, returns single map Panics when error is present and when map is nil/has no entries

M1 检查错误和映射有条目,返回单个映射 当有错误时 panic,当映射为 nil/无条目时 panic

func M2

func M2[K1, K2 comparable, V1, V2 any](m1 map[K1]V1, m2 map[K2]V2, err error) (map[K1]V1, map[K2]V2)

M2 checks error and maps have entries, returns two maps Panics when error is present and when some map is nil/has no entries

M2 检查错误和映射有条目,返回两个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func M3

func M3[K1, K2, K3 comparable, V1, V2, V3 any](m1 map[K1]V1, m2 map[K2]V2, m3 map[K3]V3, err error) (map[K1]V1, map[K2]V2, map[K3]V3)

M3 checks error and maps have entries, returns three maps Panics when error is present and when some map is nil/has no entries

M3 检查错误和映射有条目,返回三个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func M4

func M4[K1, K2, K3, K4 comparable, V1, V2, V3, V4 any](m1 map[K1]V1, m2 map[K2]V2, m3 map[K3]V3, m4 map[K4]V4, err error) (map[K1]V1, map[K2]V2, map[K3]V3, map[K4]V4)

M4 checks error and maps have entries, returns 4 maps Panics when error is present and when some map is nil/has no entries

M4 检查错误和映射有条目,返回 4 个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func M5

func M5[K1, K2, K3, K4, K5 comparable, V1, V2, V3, V4, V5 any](m1 map[K1]V1, m2 map[K2]V2, m3 map[K3]V3, m4 map[K4]V4, m5 map[K5]V5, err error) (map[K1]V1, map[K2]V2, map[K3]V3, map[K4]V4, map[K5]V5)

M5 checks error and maps have entries, returns 5 maps Panics when error is present and when some map is nil/has no entries

M5 检查错误和映射有条目,返回 5 个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func M6

func M6[K1, K2, K3, K4, K5, K6 comparable, V1, V2, V3, V4, V5, V6 any](m1 map[K1]V1, m2 map[K2]V2, m3 map[K3]V3, m4 map[K4]V4, m5 map[K5]V5, m6 map[K6]V6, err error) (map[K1]V1, map[K2]V2, map[K3]V3, map[K4]V4, map[K5]V5, map[K6]V6)

M6 checks error and maps have entries, returns 6 maps Panics when error is present and when some map is nil/has no entries

M6 检查错误和映射有条目,返回 6 个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func M7

func M7[K1, K2, K3, K4, K5, K6, K7 comparable, V1, V2, V3, V4, V5, V6, V7 any](m1 map[K1]V1, m2 map[K2]V2, m3 map[K3]V3, m4 map[K4]V4, m5 map[K5]V5, m6 map[K6]V6, m7 map[K7]V7, err error) (map[K1]V1, map[K2]V2, map[K3]V3, map[K4]V4, map[K5]V5, map[K6]V6, map[K7]V7)

M7 checks error and maps have entries, returns 7 maps Panics when error is present and when some map is nil/has no entries

M7 检查错误和映射有条目,返回 7 个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func M8

func M8[K1, K2, K3, K4, K5, K6, K7, K8 comparable, V1, V2, V3, V4, V5, V6, V7, V8 any](m1 map[K1]V1, m2 map[K2]V2, m3 map[K3]V3, m4 map[K4]V4, m5 map[K5]V5, m6 map[K6]V6, m7 map[K7]V7, m8 map[K8]V8, err error) (map[K1]V1, map[K2]V2, map[K3]V3, map[K4]V4, map[K5]V5, map[K6]V6, map[K7]V7, map[K8]V8)

M8 checks error and maps have entries, returns 8 maps Panics when error is present and when some map is nil/has no entries

M8 检查错误和映射有条目,返回 8 个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func M9

func M9[K1, K2, K3, K4, K5, K6, K7, K8, K9 comparable, V1, V2, V3, V4, V5, V6, V7, V8, V9 any](m1 map[K1]V1, m2 map[K2]V2, m3 map[K3]V3, m4 map[K4]V4, m5 map[K5]V5, m6 map[K6]V6, m7 map[K7]V7, m8 map[K8]V8, m9 map[K9]V9, err error) (map[K1]V1, map[K2]V2, map[K3]V3, map[K4]V4, map[K5]V5, map[K6]V6, map[K7]V7, map[K8]V8, map[K9]V9)

M9 checks error and maps have entries, returns 9 maps Panics when error is present and when some map is nil/has no entries

M9 检查错误和映射有条目,返回 9 个映射 当有错误时 panic,当某个映射为 nil/无条目时 panic

func P0

func P0(err error)

P0 checks error and panics if present Use github.com/yylego/must package for P0 scenario

P0 检查错误,如果存在则 panic P0 场景建议使用 github.com/yylego/must 包

func P1

func P1[T1 any](v1 *T1, err error) *T1

P1 checks error and validates pointer is non-nil, returns single pointer Panics when error is present and when pointer is nil

P1 检查错误并验证指针非 nil,返回单个指针 当有错误时 panic,当指针为 nil 时 panic

func P2

func P2[T1, T2 any](v1 *T1, v2 *T2, err error) (*T1, *T2)

P2 checks error and validates pointers non-nil, returns two pointers Panics when error is present and when some pointer is nil

P2 检查错误并验证指针非 nil,返回两个指针 当有错误时 panic,当某个指针为 nil 时 panic

func P3

func P3[T1, T2, T3 any](v1 *T1, v2 *T2, v3 *T3, err error) (*T1, *T2, *T3)

P3 checks error and validates pointers non-nil, returns three pointers Panics when error is present and when some pointer is nil

P3 检查错误并验证指针非 nil,返回三个指针 当有错误时 panic,当某个指针为 nil 时 panic

func P4

func P4[T1, T2, T3, T4 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, err error) (*T1, *T2, *T3, *T4)

P4 checks error and validates pointers non-nil, returns 4 pointers Panics when error is present and when some pointer is nil

P4 检查错误并验证指针非 nil,返回 4 个指针 当有错误时 panic,当某个指针为 nil 时 panic

func P5

func P5[T1, T2, T3, T4, T5 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, err error) (*T1, *T2, *T3, *T4, *T5)

P5 checks error and validates pointers non-nil, returns 5 pointers Panics when error is present and when some pointer is nil

P5 检查错误并验证指针非 nil,返回 5 个指针 当有错误时 panic,当某个指针为 nil 时 panic

func P6

func P6[T1, T2, T3, T4, T5, T6 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, err error) (*T1, *T2, *T3, *T4, *T5, *T6)

P6 checks error and validates pointers non-nil, returns 6 pointers Panics when error is present and when some pointer is nil

P6 检查错误并验证指针非 nil,返回 6 个指针 当有错误时 panic,当某个指针为 nil 时 panic

func P7

func P7[T1, T2, T3, T4, T5, T6, T7 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, v7 *T7, err error) (*T1, *T2, *T3, *T4, *T5, *T6, *T7)

P7 checks error and validates pointers non-nil, returns 7 pointers Panics when error is present and when some pointer is nil

P7 检查错误并验证指针非 nil,返回 7 个指针 当有错误时 panic,当某个指针为 nil 时 panic

func P8

func P8[T1, T2, T3, T4, T5, T6, T7, T8 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, v7 *T7, v8 *T8, err error) (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8)

P8 checks error and validates pointers non-nil, returns 8 pointers Panics when error is present and when some pointer is nil

P8 检查错误并验证指针非 nil,返回 8 个指针 当有错误时 panic,当某个指针为 nil 时 panic

func P9

func P9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, v7 *T7, v8 *T8, v9 *T9, err error) (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9)

P9 checks error and validates pointers non-nil, returns 9 pointers Panics when error is present and when some pointer is nil

P9 检查错误并验证指针非 nil,返回 9 个指针 当有错误时 panic,当某个指针为 nil 时 panic

func R0

func R0(run func() error)

R0 executes function and checks error, applying P0 validation Use github.com/yylego/must package for R0 scenario

R0 执行函数并检查错误,应用 P0 验证 R0 场景建议使用 github.com/yylego/must 包

func R1

func R1[T1 any](run func() (*T1, error)) *T1

R1 executes function and checks the result with pointer validation, applying P1 validation Returns single non-nil pointer from function and panics when error/nil is present

R1 执行函数并检查结果和指针验证,应用 P1 验证 返回函数的单个非 nil 指针,当有错误/nil 时 panic

func R2

func R2[T1, T2 any](run func() (*T1, *T2, error)) (*T1, *T2)

R2 executes function and checks the result with pointer validation, applying P2 validation Returns two non-nil pointers from function and panics when error/nil is present

R2 执行函数并检查结果和指针验证,应用 P2 验证 返回函数的两个非 nil 指针,当有错误/nil 时 panic

func R3

func R3[T1, T2, T3 any](run func() (*T1, *T2, *T3, error)) (*T1, *T2, *T3)

R3 executes function and checks the result with pointer validation, applying P3 validation Returns three non-nil pointers from function and panics when error/nil is present

R3 执行函数并检查结果和指针验证,应用 P3 验证 返回函数的三个非 nil 指针,当有错误/nil 时 panic

func R4

func R4[T1, T2, T3, T4 any](run func() (*T1, *T2, *T3, *T4, error)) (*T1, *T2, *T3, *T4)

R4 executes function and checks the result with pointer validation, applying P4 validation Returns 4 non-nil pointers from function and panics when error/nil is present

R4 执行函数并检查结果和指针验证,应用 P4 验证 返回函数的 4 个非 nil 指针,当有错误/nil 时 panic

func R5

func R5[T1, T2, T3, T4, T5 any](run func() (*T1, *T2, *T3, *T4, *T5, error)) (*T1, *T2, *T3, *T4, *T5)

R5 executes function and checks the result with pointer validation, applying P5 validation Returns 5 non-nil pointers from function and panics when error/nil is present

R5 执行函数并检查结果和指针验证,应用 P5 验证 返回函数的 5 个非 nil 指针,当有错误/nil 时 panic

func R6

func R6[T1, T2, T3, T4, T5, T6 any](run func() (*T1, *T2, *T3, *T4, *T5, *T6, error)) (*T1, *T2, *T3, *T4, *T5, *T6)

R6 executes function and checks the result with pointer validation, applying P6 validation Returns 6 non-nil pointers from function and panics when error/nil is present

R6 执行函数并检查结果和指针验证,应用 P6 验证 返回函数的 6 个非 nil 指针,当有错误/nil 时 panic

func R7

func R7[T1, T2, T3, T4, T5, T6, T7 any](run func() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, error)) (*T1, *T2, *T3, *T4, *T5, *T6, *T7)

R7 executes function and checks the result with pointer validation, applying P7 validation Returns 7 non-nil pointers from function and panics when error/nil is present

R7 执行函数并检查结果和指针验证,应用 P7 验证 返回函数的 7 个非 nil 指针,当有错误/nil 时 panic

func R8

func R8[T1, T2, T3, T4, T5, T6, T7, T8 any](run func() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, error)) (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8)

R8 executes function and checks the result with pointer validation, applying P8 validation Returns 8 non-nil pointers from function and panics when error/nil is present

R8 执行函数并检查结果和指针验证,应用 P8 验证 返回函数的 8 个非 nil 指针,当有错误/nil 时 panic

func R9

func R9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](run func() (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9, error)) (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9)

R9 executes function and checks the result with pointer validation, applying P9 validation Returns 9 non-nil pointers from function and panics when error/nil is present

R9 执行函数并检查结果和指针验证,应用 P9 验证 返回函数的 9 个非 nil 指针,当有错误/nil 时 panic

func V0

func V0(err error)

V0 checks error and panics if present Use github.com/yylego/must package for V0 scenario

V0 检查错误,如果存在则 panic V0 场景建议使用 github.com/yylego/must 包

func V1

func V1[T1 any](v1 T1, err error) T1

V1 checks error and returns single value Panics when error is present and returns the value when not

V1 检查错误并返回单个值 当有错误时 panic,没有错误时返回值

func V2

func V2[T1, T2 any](v1 T1, v2 T2, err error) (T1, T2)

V2 checks error and returns two values Panics when error is present and returns the values when not

V2 检查错误并返回两个值 当有错误时 panic,没有错误时返回值

func V3

func V3[T1, T2, T3 any](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)

V3 checks error and returns three values Panics when error is present and returns the values when not

V3 检查错误并返回三个值 当有错误时 panic,没有错误时返回值

func V4

func V4[T1, T2, T3, T4 any](v1 T1, v2 T2, v3 T3, v4 T4, err error) (T1, T2, T3, T4)

V4 checks error and returns 4 values Panics when error is present and returns the values when not

V4 检查错误并返回 4 个值 当有错误时 panic,没有错误时返回值

func V5

func V5[T1, T2, T3, T4, T5 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, err error) (T1, T2, T3, T4, T5)

V5 checks error and returns 5 values Panics when error is present and returns the values when not

V5 检查错误并返回 5 个值 当有错误时 panic,没有错误时返回值

func V6

func V6[T1, T2, T3, T4, T5, T6 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, err error) (T1, T2, T3, T4, T5, T6)

V6 checks error and returns 6 values Panics when error is present and returns the values when not

V6 检查错误并返回 6 个值 当有错误时 panic,没有错误时返回值

func V7

func V7[T1, T2, T3, T4, T5, T6, T7 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, err error) (T1, T2, T3, T4, T5, T6, T7)

V7 checks error and returns 7 values Panics when error is present and returns the values when not

V7 检查错误并返回 7 个值 当有错误时 panic,没有错误时返回值

func V8

func V8[T1, T2, T3, T4, T5, T6, T7, T8 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, err error) (T1, T2, T3, T4, T5, T6, T7, T8)

V8 checks error and returns 8 values Panics when error is present and returns the values when not

V8 检查错误并返回 8 个值 当有错误时 panic,没有错误时返回值

func V9

func V9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, err error) (T1, T2, T3, T4, T5, T6, T7, T8, T9)

V9 checks error and returns 9 values Panics when error is present and returns the values when not

V9 检查错误并返回 9 个值 当有错误时 panic,没有错误时返回值

Types

This section is empty.

Directories

Path Synopsis
internal
demos/demo1x command
demos/demo2x command
demos/demo3x command
Package resb: Boolean result handling - Streamline functions that return (value, bool) patterns Transform map lookups and value checks with ok-pattern into clean, panic-on-false validation Provides V, P, C series for handling (value, bool) results with type-safe generic functions Each series supports 0-9 parameters with bool checking and value validation
Package resb: Boolean result handling - Streamline functions that return (value, bool) patterns Transform map lookups and value checks with ok-pattern into clean, panic-on-false validation Provides V, P, C series for handling (value, bool) results with type-safe generic functions Each series supports 0-9 parameters with bool checking and value validation

Jump to

Keyboard shortcuts

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