package comm

import "go_dreamfactory/lego/sys/log"

type ResultStruct[T any] struct {
	Result T
	Err    error
}

func Result[T any](result T, err error) *ResultStruct[T] {
	return &ResultStruct[T]{Result: result, Err: err}
}

func (this *ResultStruct[T]) Unwrap() T {
	if this.Err != nil {
		log.Errorf("%v", this.Err)
	}
	return this.Result
}

func (this *ResultStruct[T]) UnwrapOr(ret T) T {
	if this.Err != nil {
		return ret
	}

	return this.Result
}
