Skip to content

Instantly share code, notes, and snippets.

@wiless
Created April 6, 2020 11:16
Show Gist options
  • Save wiless/624cc1324e8ed3ecc9fd9e59ba7a3a50 to your computer and use it in GitHub Desktop.
Save wiless/624cc1324e8ed3ecc9fd9e59ba7a3a50 to your computer and use it in GitHub Desktop.
Read small icon files and covert to []byte variable to embed in go code
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
// Reads the input file (e.g. favicon.ico) and creates outputs variable=[...bytes].. build go files with the output for embeddineg ico impages
func main() {
f, _ := os.Open(os.Args[1])
data, _ := ioutil.ReadAll(f)
str := fmt.Sprintf("%d", data)
str = strings.ReplaceAll(str, " ", ",")
str = strings.ReplaceAll(str, "[", "{")
str = strings.ReplaceAll(str, "]", "}")
fmt.Println("package main\n var favicon=[]byte", str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment