base

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 0 Imported by: 10

README

base

基础函数。

If

三元表达式。

fmt.Println(base.If(true, 1, 2))
fmt.Println(base.If(false, 1, 2))

// 1
// 2

[play]

Must

检查返回 error 是否为 nil,不是则 panic。

Must1

检查返回 error,为 nil 则返回1个值。

fmt.Println(base.Must1(1, nil))

// 1

[play]

Must2

检查返回 error,为 nil 则返回2个值。

fmt.Println(base.Must2(1, 2, nil))

// 1 2

[play]

Must3

检查返回 error,为 nil 则返回3个值。

fmt.Println(base.Must3(1, 2, 3, nil))

// 1 2 3

[play]

Param1

返回第1个参数。

fmt.Println(base.Param1(1, 2, 3, 4))

// 1

[play]

Param2

返回第2个参数。

fmt.Println(base.Param2(1, 2, 3, 4))

// 2

[play]

Param3

返回第3个参数。

fmt.Println(base.Param3(1, 2, 3, 4))

// 3

[play]

Documentation

Overview

Package base 基础函数.

Index

Examples

Constants

View Source
const (
	Three          = 3
	Five           = 5
	Six            = 6
	Seven          = 7
	Nine           = 9
	Ten            = 10
	Hundred        = 100
	Million        = 1e6
	HundredMillion = 1e8
	Billion        = 1e9
)
View Source
const (
	One = 1 << iota
	Two
	Four
	Eight
	Sixteen
	ThirtyTwo
	SixtyFour
	OneHundredTwentyEight
	TwoHundredFiftySix
	FiveHundredTwelve
	Kilo
)

Variables

This section is empty.

Functions

func If

func If[T any](condition bool, trueVal, falseVal T) T

If 三元表达式.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/base"
)

func main() {
	fmt.Println(base.If(true, 1, 2))
	fmt.Println(base.If(false, 1, 2))

}
Output:

1
2

func Must

func Must(err error)

Must error 必须是nil.

func Must1

func Must1[T any](t T, err error) T

Must1 1个返回值,error 必须是nil.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/base"
)

func main() {
	fmt.Println(base.Must1(1, nil))

}
Output:

1

func Must2

func Must2[T1, T2 any](t1 T1, t2 T2, err error) (T1, T2)

Must2 2个返回值, error 必须是nil.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/base"
)

func main() {
	fmt.Println(base.Must2(1, 2, nil))

}
Output:

1 2

func Must3

func Must3[T1, T2, T3 any](t1 T1, t2 T2, t3 T3, err error) (T1, T2, T3)

Must3 3个返回值, error 必须是nil.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/base"
)

func main() {
	fmt.Println(base.Must3(1, 2, 3, nil))

}
Output:

1 2 3

func Param1

func Param1[R any](r R, _ ...any) R

Param1 返回第1个参数.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/base"
)

func main() {
	fmt.Println(base.Param1(1, 2, 3, 4))

}
Output:

1

func Param2

func Param2[R any](_ any, r R, _ ...any) R

Param2 返回第2个参数.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/base"
)

func main() {
	fmt.Println(base.Param2(1, 2, 3, 4))

}
Output:

2

func Param3

func Param3[R any](_, _ any, r R, _ ...any) R

Param3 返回第3个参数.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/base"
)

func main() {
	fmt.Println(base.Param3(1, 2, 3, 4))

}
Output:

3

Types

This section is empty.

Jump to

Keyboard shortcuts

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