Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
go - copy relative folder using embed

I am using our go library (it could be changed if necessary) with a folder named "devops", which contains nested content.

in the library, I copy the devops folder with his content, to another folder.

this is the copy function:

func CopyDirectory(scrDir, dest string) error { // scrDir = devops
entries, err := ioutil.ReadDir(scrDir)
if err != nil {
    return err
}
for _, entry := range entries {
    sourcePath := filepath.Join(scrDir, entry.Name())
    destPath := filepath.Join(dest, entry.Name())

    fileInfo, err := os.Stat(sourcePath)
    fmt.Println(fileInfo)
    if err != nil {
        return err
    }

    stat, ok := fileInfo.Sys().(*syscall.Stat_t)
    if !ok {
        return fmt.Errorf("failed to get raw syscall.Stat_t data for '%s'", sourcePath)
    }

    switch fileInfo.Mode() & os.ModeType {
    case os.ModeDir:
        if err := CreateIfNotExists(destPath, 0755); err != nil { // CreateIfNotExists is a internal function
            return err
        }
        if err := CopyDirectory(sourcePath, destPath); err != nil { // CopyDirectory is a internal function
            return err
        }
    case os.ModeSymlink:
        if err := CopySymLink(sourcePath, destPath); err != nil { // CopySymLink is a internal function
            return err
        }
    default:
        if err := Copy(sourcePath, destPath); err != nil { // Copy is a internal function
            return err
        }
    }

    if err := os.Lchown(destPath, int(stat.Uid), int(stat.Gid)); err != nil {
        return err
    }

    isSymlink := entry.Mode()&os.ModeSymlink != 0
    if !isSymlink {
        if err := os.Chmod(destPath, entry.Mode()); err != nil {
            return err
        }
    }
}
return nil

}

the library runs well as self-running, but when I use it from another project, it tries to copy the devops folder from the project path, and of course, fails.

I tried doing it with embed pkg, but the code fails when calling

fileInfo.Sys().(*syscall.Stat_t)

with an error that doesn't give any details.

this is the my code:

//go:embed devops
var f embed.FS
...

dir, _ := f.ReadDir("devops")

for _, entry := range dir { 
    fileInfo, _ := entry.Info()

    err, ok := fileInfo.Sys().(*syscall.Stat_t)
    if !ok {
        println(err) // prints 0x0
    }
}

How to solve it?

P.S. the code runs in Linux OS.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!