Skip to content

Commit

Permalink
Merge pull request #48 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
feature(yaml): save yaml and open yaml file
  • Loading branch information
Matrix-X authored Sep 8, 2022
2 parents a8dfb2e + 1d274a8 commit 82ea1de
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
34 changes: 34 additions & 0 deletions object/yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package object

import (
"gopkg.in/yaml.v3"
"io/fs"
"io/ioutil"
)

func SaveYMLFile(yamlObject interface{}, savePath string, perm fs.FileMode) (err error) {

data, err := yaml.Marshal(&yamlObject)
if err != nil {
return err
}

err = ioutil.WriteFile(savePath, data, perm)
if err != nil {
return err
}

return err
}

func OpenYMLFile(yamlFile string, yamlObject interface{}) (err error) {

yamlFileData, err := ioutil.ReadFile(yamlFile)
if err != nil {
return err
}

err = yaml.Unmarshal(yamlFileData, yamlObject)

return err
}
36 changes: 36 additions & 0 deletions os/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package os

import (
"io"
"os"
)

// https://www.golangprograms.com/files-directories-examples.html

func CopyFile(src string, dst string) (err error) {

fin, err := os.Open(src)
if err != nil {
return err
}
defer fin.Close()

fOut, err := os.Create(dst)
if err != nil {
return err
}
defer fOut.Close()

_, err = io.Copy(fOut, fin)

if err != nil {
return err
}

return err
}

func MoveFile(src string, dst string) (err error) {
err = os.Rename(src, dst)
return err
}

0 comments on commit 82ea1de

Please sign in to comment.