github.com/vmpartner/bitmex@v1.1.0/tools/tools.go (about)

     1  package tools
     2  
     3  import (
     4  	"os"
     5  	"encoding/gob"
     6  )
     7  
     8  func CheckErr(err error) {
     9  	if err != nil {
    10  		panic(err)
    11  	}
    12  }
    13  
    14  func WriteGob(filePath string, object interface{}) error {
    15  	file, err := os.Create(filePath)
    16  	if err == nil {
    17  		encoder := gob.NewEncoder(file)
    18  		encoder.Encode(object)
    19  	}
    20  	file.Close()
    21  	return err
    22  }
    23  
    24  func ReadGob(filePath string, object interface{}) error {
    25  	file, err := os.Open(filePath)
    26  	if err == nil {
    27  		decoder := gob.NewDecoder(file)
    28  		err = decoder.Decode(object)
    29  	}
    30  	file.Close()
    31  	return err
    32  }