Created
April 29, 2020 10:19
-
-
Save itaysk/993329ef49a4fee26fbb57be6bc28e32 to your computer and use it in GitHub Desktop.
Embed file in Go using ELF section
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
package main | |
import ( | |
"debug/elf" | |
"fmt" | |
"os" | |
) | |
func main() { | |
selfPath, _ := os.Executable() | |
selfFile, _ := os.Open(selfPath) | |
selfElf, _ := elf.NewFile(selfFile) | |
var data []byte | |
for _, s := range selfElf.Sections { | |
if s.Name == "myfile" { | |
data, _ = s.Data() | |
} | |
} | |
fmt.Println(string(data)) | |
} |
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
build: | |
go build -o _main | |
objcopy --add-section myfile=myfile _main main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment