utils

package
v0.0.0-...-5e78f26 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError

func HandleError(ctx context.Context, err error, message string)

HandleError はエラーを処理し、追加情報を記録する関数です

func HandleErrorWithCaller

func HandleErrorWithCaller(ctx context.Context, err error, message string, caller int)

func LoadEnv

func LoadEnv() error

func OptionalMarshalToPtr

func OptionalMarshalToPtr[T encoding.TextMarshaler, U any](
	isSet bool,
	value T,
	convert func(string) U,
) *U

MarshalToPtr conditionがtrueの場合に、valueをmarshalしてポインタを返す

func ParseIPNet

func ParseIPNet(ipStr string) net.IPNet

ParseIPNet IPアドレス文字列をnet.IPNetに変換

func ToNullableSQL

func ToNullableSQL[O any](v any) O

ToNullableSQL ポインタ型をsql.NullXXX型に変換する code:

str := lo.ToPtr("example")
nullStr := utils.ToNullableSQL[sql.NullString](str) // sql.NullString{String: "example", Valid: true}
str = nil
nullStr = utils.ToNullableSQL[sql.NullString](str) // sql.NullString{Valid: false}
num := 29
nullNum := utils.ToNullableSQL[sql.NullInt32](num) // sql.NullInt32{Int32: 29, Valid: true}

func ToOpt

func ToOpt[O any](v any) O

ToOpt ポインタ型をoas.OptXXX型に変換する code:

str := lo.ToPtr("example")
optStr := utils.ToOpt[oas.OptString](str) // oas.OptString{Value: "example", Set: true}
str = nil
optStr = utils.ToOpt[oas.OptString](str) // oas.OptString{Set: false}
num := 29
optNum := utils.ToOpt[oas.OptInt](num) // oas.OptInt{Value: 29, Set: true}

func ToOptNil

func ToOptNil[O any](v any) O

func ToPtrIf

func ToPtrIf[T any](condition bool, value T) *T

ToPtrIf conditionがtrueの場合にポインタを返す 変換元がsql.NullXXXのように、Validフィールドを持つような場合にの使用する。 単純なポインタ変換には、lo.ToPtrを使用すること。 code:

// ok
num := sql.NullInt32{Int32: 29, Valid: true}
ptrNum := utils.ToPtrIf(num.Valid, num.Int32) // *int32 (29)
num = sql.NullInt32{Valid: false}
nilNum := utils.ToPtrIf(false, num.Int32) // nil
// bad
num := lo.ToPtr(10) // *int
nilNum := utils.ToPtrIf(num != nil, *num) // panic

func ToPtrIfNotNullFunc

func ToPtrIfNotNullFunc[T any](nullFlag bool, getValue func() *T) *T

func ToPtrIfNotNullValue deprecated

func ToPtrIfNotNullValue[T any](nullFlag bool, value T) *T

Deprecated: utils.ToPtrIf を使用すること ToPtrIfNotNullValue の場合は、nullFlagがtrueの場合にnilを返す

Types

type ErrorInfo

type ErrorInfo struct {
	Err      error
	File     string
	Line     int
	Function string
}

ErrorInfo はエラーに関する追加情報を保持する構造体です

Jump to

Keyboard shortcuts

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