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

89
main.go
View file

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

View file

@ -1,11 +1,293 @@
[ [
{"Repo": "https://github.com/paultag/go-debian.git", {
"Path": "/go/debian", "Packages": [
"Packages": ["control", "dependency", "internal", "version"], "control",
"Url": "https://github.com/paultag/go-debian"}, "dependency",
"internal",
{"Repo": "https://github.com/paultag/go-topsort.git", "version",
"Path": "/go/topsort", "changelog",
"Packages": [], "hashio",
"Url": "https://github.com/paultag/go-topsort"} "deb"
],
"Path": "/go/debian",
"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": [],
"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"
}
] ]