github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/app/bvto/vto.go (about)

     1  package bvto
     2  
     3  import "github.com/songzhibin97/gkit/tools/vto"
     4  
     5  // VoToDoFromPoint src must point
     6  func VoToDoFromPoint[DST any, SRC any](src SRC) (*DST, error) {
     7  	var zero DST
     8  	err := vto.VoToDo(&zero, src)
     9  	return &zero, err
    10  }
    11  
    12  // VoToDoFromNotPoint src must not point
    13  func VoToDoFromNotPoint[DST any, SRC any](src SRC) (*DST, error) {
    14  	var zero DST
    15  	err := vto.VoToDo(&zero, &src)
    16  	return &zero, err
    17  }
    18  
    19  // VoToDoPlusFromPoint src must point
    20  func VoToDoPlusFromPoint[DST any, SRC any](src SRC, parameters vto.ModelParameters) (*DST, error) {
    21  	var zero DST
    22  	err := vto.VoToDoPlus(&zero, src, parameters)
    23  	return &zero, err
    24  }
    25  
    26  // VoToDoPlusFromNotPoint src must not point
    27  func VoToDoPlusFromNotPoint[DST any, SRC any](src SRC, parameters vto.ModelParameters) (*DST, error) {
    28  	var zero DST
    29  	err := vto.VoToDoPlus(&zero, &src, parameters)
    30  	return &zero, err
    31  }
    32  
    33  // VoToDoListFromPoint src must point
    34  func VoToDoListFromPoint[DST any, SRC any](src []SRC) ([]*DST, error) {
    35  	zero := make([]*DST, 0, len(src))
    36  	for _, v := range src {
    37  		dv, err := VoToDoFromPoint[DST](v)
    38  		if err != nil {
    39  			return nil, err
    40  		}
    41  		zero = append(zero, dv)
    42  	}
    43  	return zero, nil
    44  }
    45  
    46  // VoToDoListFromNotPoint src must not point
    47  func VoToDoListFromNotPoint[DST any, SRC any](src []SRC) ([]*DST, error) {
    48  	zero := make([]*DST, 0, len(src))
    49  	for _, v := range src {
    50  		dv, err := VoToDoFromNotPoint[DST](v)
    51  		if err != nil {
    52  			return nil, err
    53  		}
    54  		zero = append(zero, dv)
    55  	}
    56  	return zero, nil
    57  }
    58  
    59  // VoToDoListPlusFromPoint src must point
    60  func VoToDoListPlusFromPoint[DST any, SRC any](src []SRC, parameters vto.ModelParameters) ([]*DST, error) {
    61  	zero := make([]*DST, 0, len(src))
    62  	for _, v := range src {
    63  		dv, err := VoToDoPlusFromPoint[DST](v, parameters)
    64  		if err != nil {
    65  			return nil, err
    66  		}
    67  		zero = append(zero, dv)
    68  	}
    69  	return zero, nil
    70  }
    71  
    72  // VoToDoListPlusFromNotPoint src must not point
    73  func VoToDoListPlusFromNotPoint[DST any, SRC any](src []SRC, parameters vto.ModelParameters) ([]*DST, error) {
    74  	zero := make([]*DST, 0, len(src))
    75  	for _, v := range src {
    76  		dv, err := VoToDoPlusFromNotPoint[DST](v, parameters)
    77  		if err != nil {
    78  			return nil, err
    79  		}
    80  		zero = append(zero, dv)
    81  	}
    82  	return zero, nil
    83  }