"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/cliv2/internal/utils/file.go" (20 Feb 2024, 298 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package utils
    2 
    3 import (
    4     "bufio"
    5     "os"
    6 )
    7 
    8 func WriteToFile(filePath string, data string) error {
    9     file, err := os.Create(filePath)
   10     if err != nil {
   11         return err
   12     }
   13 
   14     defer file.Close()
   15 
   16     w := bufio.NewWriter(file)
   17     _, err = w.WriteString(data)
   18     if err != nil {
   19         return err
   20     }
   21 
   22     return w.Flush()
   23 }