File: generate.go

package info (click to toggle)
golang-github-cloudflare-redoctober 0.0~git20161017.0.78e9720-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 636 kB
  • sloc: sh: 65; makefile: 7
file content (36 lines) | stat: -rw-r--r-- 720 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// +build ignore

package main

import (
	"io"
	"os"
	"path/filepath"
)

// Reads static/index.html and saves as a constant in static.go
func main() {
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	out, err := os.Create(filepath.Join(wd, "static.go"))
	if err != nil {
		panic(err)
	}
	indexPath := filepath.Join(wd, "static", "index.html")

	out.Write([]byte("// This file is autogenerated; DO NOT EDIT DIRECTLY\n// See generate.go for more info\npackage main\n\nconst (\n"))
	out.Write([]byte("\tindexHtml = `"))
	f, err := os.Open(indexPath)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	if _, err := io.Copy(out, f); err != nil {
		panic(err)
	}

	out.Write([]byte("`\n"))
	out.Write([]byte(")\n"))
}