Skip to content
Snippets Groups Projects
Select Git revision
  • feature/v1.3.60
  • develop default protected
  • main protected
  • release/v1.0.7
  • release/v1.0.0
  • feature/v0.9.5
  • release/v0.6.2
  • hotfix/v0.5.7
  • release/v0.5.6
  • release/v0.5.5
  • hotfix/v0.5.4
  • hotfix/v0.5.3
  • hotfix/v0.5.2
  • release/v0.5.1
  • hotfix/v0.5.0
  • hotfix/v0.4.9
  • hotfix/v0.4.8
  • hotfix/v0.4.7
  • release/v0.4.6
  • hotfix/v0.4.5
  • v1.3.55
  • v1.3.52
  • v1.3.50
  • v1.3.45
  • v1.3.42
  • v1.3.41
  • v1.3.40
  • v1.3.38
  • v1.3.37
  • v1.3.36
  • v1.3.35
  • v1.3.34
  • v1.3.33
  • v1.3.32
  • v1.3.31
  • v1.3.30
  • v1.3.29
  • v1.3.28
  • v1.3.27
  • v1.3.26
40 results

ResultModel.go

  • Md. Alim Ul Karim's avatar
    3dcda42c
    Merge branch 'feature/enhancements-v3' into 'develop' · 3dcda42c
    Md. Alim Ul Karim authored
    JsonResult -> Json, JsonResultsCollection
    
    ## Introduction
    
    JsonResult -> Json, JsonResultsCollection features added, now jsonResult can be saved into or marshal into bytes. JsonResult can be collected as JsonResultsCollection, it can also be marshalled
    
    ## Sample Code
    
    ```go
    items := &[]string{
    		"00",
    		"01",
    		"02",
    		"03",
    		"04",
    		"05",
    		"06",
    		"07",
    		"08",
    		"09",
    		"10",
    		"11",
    		"12",
    	}
    
    	// collectionPtr := corestr.NewCollectionPtrUsingStrings(items, 0)
    	collection := corestr.NewCollectionUsingStrings(items, false)
    	jsonResults := corejson.NewResultsCollectionUsingJsoners(1, collection)
    	jsonResultFromResults := jsonResults.Json()
    
    	fmt.Println(jsonResultFromResults.JsonString())
    
    	res2 := corejson.EmptyResultsCollection()
    
    	res2.ParseInjectUsingJson(jsonResultFromResults)
    
    	fmt.Println(res2.Json().JsonString())
    	collect2 := corestr.EmptyCollection()
    
    	// res2.InjectIntoAt(0, collect2)
    	res2.UnmarshalAt(0, collect2)
    
    	fmt.Println(collect2)
    ```
    
    ## Output
    
    ```notes
    {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]}
    {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]}
    
    	- 00
    	- 01
    	- 02
    	- 03
    	- 04
    	- 05
    	- 06
    	- 07
    	- 08
    	- 09
    	- 10
    	- 11
    	- 12
    
    Process finished with exit code 0
    
    ```
    
    See merge request !39
    3dcda42c
    History
    Merge branch 'feature/enhancements-v3' into 'develop'
    Md. Alim Ul Karim authored
    JsonResult -> Json, JsonResultsCollection
    
    ## Introduction
    
    JsonResult -> Json, JsonResultsCollection features added, now jsonResult can be saved into or marshal into bytes. JsonResult can be collected as JsonResultsCollection, it can also be marshalled
    
    ## Sample Code
    
    ```go
    items := &[]string{
    		"00",
    		"01",
    		"02",
    		"03",
    		"04",
    		"05",
    		"06",
    		"07",
    		"08",
    		"09",
    		"10",
    		"11",
    		"12",
    	}
    
    	// collectionPtr := corestr.NewCollectionPtrUsingStrings(items, 0)
    	collection := corestr.NewCollectionUsingStrings(items, false)
    	jsonResults := corejson.NewResultsCollectionUsingJsoners(1, collection)
    	jsonResultFromResults := jsonResults.Json()
    
    	fmt.Println(jsonResultFromResults.JsonString())
    
    	res2 := corejson.EmptyResultsCollection()
    
    	res2.ParseInjectUsingJson(jsonResultFromResults)
    
    	fmt.Println(res2.Json().JsonString())
    	collect2 := corestr.EmptyCollection()
    
    	// res2.InjectIntoAt(0, collect2)
    	res2.UnmarshalAt(0, collect2)
    
    	fmt.Println(collect2)
    ```
    
    ## Output
    
    ```notes
    {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]}
    {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]}
    
    	- 00
    	- 01
    	- 02
    	- 03
    	- 04
    	- 05
    	- 06
    	- 07
    	- 08
    	- 09
    	- 10
    	- 11
    	- 12
    
    Process finished with exit code 0
    
    ```
    
    See merge request !39
ResultModel.go 561 B
package corejson

import "gitlab.com/evatix-go/core/constants"

type ResultModel struct {
	Bytes    *[]byte
	Error    string
	HasError bool
}

func NewModel(result *Result) *ResultModel {
	if result == nil {
		return &ResultModel{
			Bytes: &[]byte{},
			Error: constants.EmptyString,
		}
	}

	model := &ResultModel{}

	return transpileResultToModel(result, model)
}

func NewFromModel(model *ResultModel) *Result {
	if model == nil {
		return &Result{
			Bytes: nil,
			Error: nil,
		}
	}

	result := &Result{}

	return transpileModelToResult(model, result)
}