Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created May 17, 2021 07:06
Show Gist options
  • Save lotusirous/0d5264c5f5639f1e966d7d61fcd15010 to your computer and use it in GitHub Desktop.
Save lotusirous/0d5264c5f5639f1e966d7d61fcd15010 to your computer and use it in GitHub Desktop.
Go embed read each file in a folder
package main
import (
"embed"
"fmt"
"log"
)
//go:embed ddl/*
var files embed.FS
func main() {
entries, err := files.ReadDir("ddl")
if err != nil {
log.Fatalln("read dir failed:", err)
}
for _, f := range entries {
if f.IsDir() {
continue
}
b, err := files.ReadFile("ddl/" + f.Name())
if err != nil {
log.Fatalln("read all failed:", err)
}
fmt.Println(string(b))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment