github.com/christoph-karpowicz/db_mediator@v0.0.0-20210207102849-61a28a1071d8/internal/server/synch/result.go (about)

     1  package synch
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  const (
     8  	SIMULATION_DIR = "./simulation/"
     9  	LOGS_DIR       = "./log/"
    10  )
    11  
    12  type Result struct {
    13  	Message    string      `json:"message"`
    14  	Operations []operation `json:"operations"`
    15  	path       string
    16  }
    17  
    18  func (r *Result) OperationsToJSON() string {
    19  	operationsJSON, err := json.MarshalIndent(r.Operations, "", "	")
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  	return string(operationsJSON)
    24  }
    25  
    26  func (r *Result) operationsToJSONSlice() []string {
    27  	operationsToJSON := make([]string, 0)
    28  	for _, operation := range r.Operations {
    29  		operationJSON := operation.toJSON()
    30  		// return false, &SynchReportError{SynchName: r.synch.GetConfig().Name, ErrMsg: err.Error()}
    31  		operationsToJSON = append(operationsToJSON, string(operationJSON))
    32  	}
    33  	return operationsToJSON
    34  }
    35  
    36  func (r *Result) setSimulationPath(fileName string) {
    37  	r.path = SIMULATION_DIR + fileName
    38  }
    39  
    40  func (r *Result) setLogPath(fileName string) {
    41  	r.path = LOGS_DIR + fileName
    42  }