update, rewrite to be static

This commit is contained in:
Paul R. Tagliamonte 2019-08-12 17:46:36 -04:00
parent 9500cd3864
commit ffbd20d78a
3 changed files with 322 additions and 76 deletions

View file

@ -1,9 +0,0 @@
FROM golang:1
ADD . /gorepos
WORKDIR /gorepos
RUN go get -d .
RUN go build ./...
CMD /gorepos/gorepos

85
main.go
View file

@ -5,11 +5,12 @@ import (
"encoding/json"
"fmt"
"html/template"
"io"
"io/ioutil"
"net/http"
"os"
"path"
)
// {{{ Package Struct
type Package struct {
Repo string
Path string
@ -17,30 +18,7 @@ type Package struct {
Url string
}
func (p Package) GetRoutes() (ret []string) {
ret = append(ret, p.Path)
for _, pkg := range p.Packages {
ret = append(ret, p.Path+"/"+pkg)
}
return
}
// }}}
// {{{ JSON Functions
func writePage(w http.ResponseWriter, data string, code int) error {
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
w.WriteHeader(code)
w.Write([]byte(data))
return nil
}
func writePageError(w http.ResponseWriter, message string, code int) error {
return writePage(w, message, code)
}
func writePageGo(w http.ResponseWriter, path string, pkg Package, code int) error {
func writePage(w io.Writer, path string, pkg Package) error {
t, err := template.ParseFiles("template.html")
if err != nil {
return err
@ -51,13 +29,11 @@ func writePageGo(w http.ResponseWriter, path string, pkg Package, code int) erro
if err != nil {
return err
}
return writePage(w, page.String(), code)
_, err = io.Copy(w, &page)
return err
}
// }}}
// {{{ Config Functions
func loadConfig() (ret []Package, err error) {
content, err := ioutil.ReadFile("packages.json")
if err != nil {
@ -67,41 +43,38 @@ func loadConfig() (ret []Package, err error) {
return
}
func loadRoutes(packages []Package) (routes map[string]Package) {
routes = map[string]Package{}
for _, pkg := range packages {
for _, route := range pkg.GetRoutes() {
routes[route] = pkg
}
}
return
}
// }}}
func main() {
mux := http.NewServeMux()
packages, err := loadConfig()
if err != nil {
fmt.Errorf("%s\n", err)
return
}
routes := loadRoutes(packages)
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
route := req.URL.Path
var err error
if val, ok := routes[route]; ok {
err = writePageGo(w, "pault.ag"+val.Path, val, 200)
} else {
err = writePageError(w, ":(", 404)
namespace := "pault.ag"
for _, pkg := range packages {
packages := pkg.Packages
packages = append(packages, "")
for _, subpackage := range packages {
pkgpath := path.Join(namespace, pkg.Path)
root := path.Join(".", pkg.Path, subpackage)
if err := os.MkdirAll(root, 0755); err != nil {
fmt.Errorf("%s\n", err)
return
}
fd, err := os.Create(path.Join(root, "index.html"))
if err != nil {
writePageError(w, fmt.Sprintf("error: %v", err), 400)
fmt.Errorf("%s\n", err)
return
}
defer fd.Close()
writePage(fd, pkgpath, pkg)
fd.Close()
}
}
})
http.ListenAndServe(":8000", mux)
}
// vim: foldmethod=marker

View file

@ -1,11 +1,293 @@
[
{"Repo": "https://github.com/paultag/go-debian.git",
{
"Packages": [
"control",
"dependency",
"internal",
"version",
"changelog",
"hashio",
"deb"
],
"Path": "/go/debian",
"Packages": ["control", "dependency", "internal", "version"],
"Url": "https://github.com/paultag/go-debian"},
{"Repo": "https://github.com/paultag/go-topsort.git",
"Path": "/go/topsort",
"Repo": "https://github.com/paultag/go-debian",
"Url": "https://github.com/paultag/go-debian"
},
{
"Packages": [
"acl",
"ca",
"client",
"pb",
"policy",
"server",
"store",
"utils",
"version"
],
"Path": "/go/cybercom",
"Repo": "https://github.com/paultag/cybercom",
"Url": "https://github.com/paultag/cybercom"
},
{
"Packages": [],
"Url": "https://github.com/paultag/go-topsort"}
"Path": "/go/archive",
"Repo": "https://github.com/paultag/go-archive",
"Url": "https://github.com/paultag/go-archive"
},
{
"Packages": [],
"Path": "/go/modprobe",
"Repo": "https://github.com/paultag/go-modprobe",
"Url": "https://github.com/paultag/go-modprobe"
},
{
"Packages": [],
"Path": "/go/topsort",
"Repo": "https://github.com/paultag/go-topsort",
"Url": "https://github.com/paultag/go-topsort"
},
{
"Packages": [],
"Path": "/go/schroot",
"Repo": "https://github.com/paultag/go-schroot",
"Url": "https://github.com/paultag/go-schroot"
},
{
"Packages": [],
"Path": "/go/sbuild",
"Repo": "https://github.com/paultag/go-sbuild",
"Url": "https://github.com/paultag/go-sbuild"
},
{
"Packages": [],
"Path": "/go/reprepro",
"Repo": "https://github.com/paultag/go-reprepro",
"Url": "https://github.com/paultag/go-reprepro"
},
{
"Packages": [],
"Path": "/go/resolver",
"Repo": "https://github.com/paultag/go-resolver",
"Url": "https://github.com/paultag/go-resolver"
},
{
"Packages": [],
"Path": "/go/fancytext",
"Repo": "https://github.com/paultag/go-fancytext",
"Url": "https://github.com/paultag/go-fancytext"
},
{
"Packages": [],
"Path": "/go/deceive",
"Repo": "https://github.com/paultag/deceive",
"Url": "https://github.com/paultag/deceive"
},
{
"Packages": [],
"Path": "/go/minica",
"Repo": "https://github.com/paultag/minica",
"Url": "https://github.com/paultag/minica"
},
{
"Packages": [
"descend"
],
"Path": "/go/descend",
"Repo": "https://github.com/paultag/descend",
"Url": "https://github.com/paultag/descend"
},
{
"Packages": [],
"Path": "/go/service",
"Repo": "https://github.com/paultag/go-service",
"Url": "https://github.com/paultag/go-service"
},
{
"Packages": [
"minion"
],
"Path": "/go/minion",
"Repo": "https://github.com/paultag/minion",
"Url": "https://github.com/paultag/minion"
},
{
"Packages": [],
"Path": "/go/config",
"Repo": "https://github.com/paultag/go-config",
"Url": "https://github.com/paultag/go-config"
},
{
"Packages": [],
"Path": "/go/haversine",
"Repo": "https://github.com/paultag/go-haversine",
"Url": "https://github.com/paultag/go-haversine"
},
{
"Packages": [],
"Path": "/go/wmata",
"Repo": "https://github.com/paultag/go-wmata",
"Url": "https://github.com/paultag/go-wmata"
},
{
"Packages": [],
"Path": "/go/mailer",
"Repo": "https://github.com/paultag/go-mailer",
"Url": "https://github.com/paultag/go-mailer"
},
{
"Packages": [],
"Path": "/go/blobstore",
"Repo": "https://github.com/paultag/go-blobstore",
"Url": "https://github.com/paultag/go-blobstore"
},
{
"Packages": [],
"Path": "/go/sense",
"Repo": "https://github.com/paultag/go-sense",
"Url": "https://github.com/paultag/go-sense"
},
{
"Packages": [],
"Path": "/go/politico",
"Repo": "https://github.com/paultag/go-politico",
"Url": "https://github.com/paultag/go-politico"
},
{
"Packages": [
"drivers/epspos"
],
"Path": "/go/epson",
"Repo": "https://github.com/paultag/go-epson",
"Url": "https://github.com/paultag/go-epson"
},
{
"Packages": [
"database",
"dictd",
"format",
"utils"
],
"Path": "/go/dictd",
"Repo": "https://github.com/paultag/go-dictd",
"Url": "https://github.com/paultag/go-dictd"
},
{
"Packages": [],
"Path": "/go/pkcs7",
"Repo": "https://github.com/paultag/go-pkcs7",
"Url": "https://github.com/paultag/go-pkcs7"
},
{
"Packages": [],
"Path": "/go/inept",
"Repo": "https://github.com/paultag/inept",
"Url": "https://github.com/paultag/inept"
},
{
"Packages": [],
"Path": "/go/proc-arp",
"Repo": "https://github.com/paultag/go-proc-arp",
"Url": "https://github.com/paultag/go-proc-arp"
},
{
"Packages": [],
"Path": "/go/ykpiv",
"Repo": "https://github.com/paultag/go-ykpiv",
"Url": "https://github.com/paultag/go-ykpiv"
},
{
"Packages": [],
"Path": "/go/gecos",
"Repo": "https://github.com/paultag/go-gecos",
"Url": "https://github.com/paultag/go-gecos"
},
{
"Packages": [],
"Path": "/go/maclookup",
"Repo": "https://github.com/paultag/go-maclookup",
"Url": "https://github.com/paultag/go-maclookup"
},
{
"Packages": [],
"Path": "/go/macchanger",
"Repo": "https://github.com/paultag/go-macchanger",
"Url": "https://github.com/paultag/go-macchanger"
},
{
"Packages": [],
"Path": "/go/nanopi",
"Repo": "https://github.com/paultag/nanopi",
"Url": "https://github.com/paultag/nanopi"
},
{
"Packages": [],
"Path": "/go/nytimes",
"Repo": "https://github.com/paultag/go-nytimes",
"Url": "https://github.com/paultag/go-nytimes"
},
{
"Packages": [],
"Path": "/go/loopback",
"Repo": "https://github.com/paultag/go-loopback",
"Url": "https://github.com/paultag/go-loopback"
},
{
"Packages": ["xattr"],
"Path": "/go/ima",
"Repo": "https://github.com/paultag/go-ima",
"Url": "https://github.com/paultag/go-ima"
},
{
"Packages": ["parser"],
"Path": "/go/sniff",
"Repo": "https://github.com/paultag/sniff",
"Url": "https://github.com/paultag/sniff"
},
{
"Packages": ["biometrics", "pkcs11"],
"Path": "/go/piv",
"Repo": "https://github.com/paultag/go-piv",
"Url": "https://github.com/paultag/go-piv"
},
{
"Packages": [],
"Path": "/go/cbeff",
"Repo": "https://github.com/paultag/go-cbeff",
"Url": "https://github.com/paultag/go-cbeff"
},
{
"Packages": [],
"Path": "/go/fasc",
"Repo": "https://github.com/paultag/go-fasc",
"Url": "https://github.com/paultag/go-fasc"
},
{
"Packages": [],
"Path": "/go/othername",
"Repo": "https://github.com/paultag/go-othername",
"Url": "https://github.com/paultag/go-othername"
},
{
"Packages": [],
"Path": "/go/pivtk",
"Repo": "https://github.com/paultag/pivtk",
"Url": "https://github.com/paultag/pivtk"
},
{
"Packages": [],
"Path": "/go/technicolor",
"Repo": "https://github.com/paultag/go-technicolor",
"Url": "https://github.com/paultag/go-technicolor"
},
{
"Packages": [
"armor",
"messages",
"sixbit"
],
"Path": "/go/ais",
"Repo": "https://github.com/paultag/go-ais",
"Url": "https://github.com/paultag/go-ais"
}
]