aboutsummaryrefslogtreecommitdiff
path: root/write.go
diff options
context:
space:
mode:
authorGravatar Grayson Koonce <grayson.koonce@gmail.com> 2016-10-12 11:04:26 -0700
committerGravatar GitHub <noreply@github.com> 2016-10-12 11:04:26 -0700
commitac8374fd17e30fca9a7773a2a6f690a7ea4d2ec9 (patch)
treee9a61adde4bc5eef80583f3e1d6f9379a20b4f99 /write.go
parentb80c4f3e920994823061eb05dc0a5bc3881ddb02 (diff)
downloadsally-ac8374fd17e30fca9a7773a2a6f690a7ea4d2ec9.tar.gz
sally-ac8374fd17e30fca9a7773a2a6f690a7ea4d2ec9.tar.zst
sally-ac8374fd17e30fca9a7773a2a6f690a7ea4d2ec9.zip
Rework as HTTP server (#15)
Diffstat (limited to '')
-rw-r--r--write.go94
1 files changed, 0 insertions, 94 deletions
diff --git a/write.go b/write.go
deleted file mode 100644
index 703b386..0000000
--- a/write.go
+++ /dev/null
@@ -1,94 +0,0 @@
-package main
-
-import (
- "bytes"
- "fmt"
- "html/template"
- "io/ioutil"
- "os"
- "path/filepath"
-)
-
-const (
- indexTplPath = "templates/index.tpl"
- packagesTplPath = "templates/package.tpl"
-)
-
-// Write takes a Config and produces a static html site to outDir
-func Write(c Config, outDir string) error {
- if err := os.MkdirAll(outDir, 0755); err != nil {
- return err
- }
- if err := writeIndex(c, outDir); err != nil {
- return err
- }
- if err := writePackages(c, outDir); err != nil {
- return err
- }
- return nil
-}
-
-func writeIndex(c Config, outDir string) error {
- tpl, err := Asset(indexTplPath)
- if err != nil {
- return err
- }
-
- t, err := template.New(filepath.Base(indexTplPath)).Parse(string(tpl))
- if err != nil {
- return err
- }
-
- buf := new(bytes.Buffer)
- if err := t.Execute(buf, c); err != nil {
- return err
- }
-
- err = ioutil.WriteFile(fmt.Sprintf("%s/index.html", outDir), buf.Bytes(), 0644)
- if err != nil {
- return err
- }
-
- fmt.Println(buf.String())
- return nil
-}
-
-func writePackages(c Config, outDir string) error {
- tpl, err := Asset(packagesTplPath)
- if err != nil {
- return err
- }
-
- t, err := template.New(filepath.Base(packagesTplPath)).Parse(string(tpl))
- if err != nil {
- return err
- }
-
- for name, pkg := range c.Packages {
- canonicalURL := fmt.Sprintf("%s/%s", c.URL, name)
- tpl := struct {
- Name string
- CanonicalURL string
- GodocURL string
- Package
- }{
- Name: name,
- CanonicalURL: canonicalURL,
- GodocURL: fmt.Sprintf("https://godoc.org/%s", canonicalURL),
- Package: pkg,
- }
-
- buf := new(bytes.Buffer)
- if err := t.Execute(buf, tpl); err != nil {
- return err
- }
-
- if err := ioutil.WriteFile(fmt.Sprintf("%s/%s.html", outDir, name), buf.Bytes(), 0644); err != nil {
- return err
- }
-
- fmt.Println(buf)
- }
-
- return nil
-}