Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda