diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-10-06 08:53:06 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-10-06 08:56:03 -0400 |
| commit | 57c4d9757ae09700e6bd65de6e55f5cd17e6e6e2 (patch) | |
| tree | 0b4b8365328c7e66ab1fb6d4b4d4bb94ac796f78 /cmd/_old/johaus | |
| parent | fda09b55e316b7f162371cf52bc401fa742913e8 (diff) | |
| download | x-57c4d9757ae09700e6bd65de6e55f5cd17e6e6e2.tar.xz x-57c4d9757ae09700e6bd65de6e55f5cd17e6e6e2.zip | |
move some old code to the _old folder to save CI time
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/_old/johaus')
| -rw-r--r-- | cmd/_old/johaus/.gitignore | 2 | ||||
| -rw-r--r-- | cmd/_old/johaus/main.go | 95 | ||||
| -rw-r--r-- | cmd/_old/johaus/yeetfile.js | 3 |
3 files changed, 100 insertions, 0 deletions
diff --git a/cmd/_old/johaus/.gitignore b/cmd/_old/johaus/.gitignore new file mode 100644 index 0000000..cffb494 --- /dev/null +++ b/cmd/_old/johaus/.gitignore @@ -0,0 +1,2 @@ +web +*.tar.gz
\ No newline at end of file diff --git a/cmd/_old/johaus/main.go b/cmd/_old/johaus/main.go new file mode 100644 index 0000000..c18928e --- /dev/null +++ b/cmd/_old/johaus/main.go @@ -0,0 +1,95 @@ +// Command johaus wraps the lojban parser camxes and presents the results over HTTP. +package main + +import ( + "encoding/json" + "flag" + "io" + "log" + "net/http" + + "tulpa.dev/cadey/jvozba" + "within.website/johaus/parser" + _ "within.website/johaus/parser/camxes" + "within.website/johaus/pretty" + "within.website/x/internal" +) + +var ( + port = flag.String("port", "9001", "TCP port to bind on for HTTP") + dialect = flag.String("dialect", "camxes", "Lojban dialect to use") +) + +func main() { + internal.HandleStartup() + + log.Printf("Listening on http://0.0.0.0:%s", *port) + + http.HandleFunc("/tree", tree) + http.HandleFunc("/braces", braces) + http.HandleFunc("/lujvo", lujvo) + + http.ListenAndServe(":"+*port, nil) +} + +func lujvo(w http.ResponseWriter, r *http.Request) { + data, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, "can't read: "+err.Error(), http.StatusBadRequest) + return + } + defer r.Body.Close() + + jvo, err := jvozba.Jvozba(string(data)) + if err != nil { + http.Error(w, "can't read: "+err.Error(), http.StatusBadRequest) + return + } + + w.Header().Set("X-Content-Language", "jbo") + http.Error(w, jvo, http.StatusOK) +} + +func braces(w http.ResponseWriter, r *http.Request) { + data, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, "can't parse: "+err.Error(), http.StatusBadRequest) + return + } + defer r.Body.Close() + + tree, err := parser.Parse(*dialect, string(data)) + if err != nil { + http.Error(w, "can't parse: "+err.Error(), http.StatusBadRequest) + return + } + + parser.RemoveMorphology(tree) + parser.AddElidedTerminators(tree) + parser.RemoveSpace(tree) + parser.CollapseLists(tree) + + pretty.Braces(w, tree) +} + +func tree(w http.ResponseWriter, r *http.Request) { + data, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, "can't parse: "+err.Error(), http.StatusBadRequest) + return + } + defer r.Body.Close() + + tree, err := parser.Parse(*dialect, string(data)) + if err != nil { + http.Error(w, "can't parse: "+err.Error(), http.StatusBadRequest) + return + } + + parser.RemoveMorphology(tree) + parser.AddElidedTerminators(tree) + parser.RemoveSpace(tree) + parser.CollapseLists(tree) + + json.NewEncoder(w).Encode(tree) +} diff --git a/cmd/_old/johaus/yeetfile.js b/cmd/_old/johaus/yeetfile.js new file mode 100644 index 0000000..9b6d04e --- /dev/null +++ b/cmd/_old/johaus/yeetfile.js @@ -0,0 +1,3 @@ +yeet.run("kubectl", "apply", "-f=manifest.yaml"); +yeet.run("sh", "-c", "kubectl rollout restart deployments/johaus"); + |
