-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from ArtisanCloud/develop
feature(yaml): save yaml and open yaml file
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |