package io import ( "fmt" "os" "gitlab.com/urkob/go-cert-gen/pkg/io" ) type writer struct { dirPath string } func (w writer) WriteFile(filename string, data []byte) (string, error) { if w.dirPath == "" { return "", fmt.Errorf("export directory cannot be empty") } if err := os.MkdirAll(w.dirPath, 0o755); err != nil { return "", err } outputPath := w.dirPath + "/" + filename if err := os.WriteFile(outputPath, data, 0o600); err != nil { return "", err } return outputPath, nil } func NewWriter(dirPath string) io.WriterIface { return &writer{ dirPath: dirPath, } }