diff options
| author | Christine Dodrill <me@christine.website> | 2019-06-15 20:51:21 -0400 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-06-15 20:51:21 -0400 |
| commit | 101cd28dc37249efd4f61c0d21d4d9d1f2272d0b (patch) | |
| tree | 488b8e448d5a6eeaf94c2312a1e004a85f22aa0b | |
| parent | 598268d233e69586bcc5886fff149b506dc496e5 (diff) | |
| download | x-101cd28dc37249efd4f61c0d21d4d9d1f2272d0b.tar.xz x-101cd28dc37249efd4f61c0d21d4d9d1f2272d0b.zip | |
add jvozba to johaus and polyglot
| -rw-r--r-- | cmd/johaus/main.go | 26 | ||||
| -rw-r--r-- | go.mod | 1 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | tg/polyglot/main.go | 23 |
4 files changed, 44 insertions, 8 deletions
diff --git a/cmd/johaus/main.go b/cmd/johaus/main.go index 4b43d2a..092cd69 100644 --- a/cmd/johaus/main.go +++ b/cmd/johaus/main.go @@ -8,6 +8,7 @@ import ( "log" "net/http" + "git.xeserv.us/xena/jvozba" "within.website/johaus/parser" _ "within.website/johaus/parser/camxes" "within.website/johaus/pretty" @@ -24,18 +25,38 @@ func main() { log.Printf("Listening on http://0.0.0.0:%s", *port) - http.DefaultServeMux.HandleFunc("/tree", tree) - http.DefaultServeMux.HandleFunc("/braces", braces) + 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 := ioutil.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 := ioutil.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 { @@ -57,6 +78,7 @@ func tree(w http.ResponseWriter, r *http.Request) { 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 { @@ -1,6 +1,7 @@ module within.website/x require ( + git.xeserv.us/xena/jvozba v0.0.0-20190616002803-f274e24d1e52 github.com/McKael/madon/v2 v2.0.0-20180929094633-c679abc985d6 github.com/Yawning/bulb v0.0.0-20170405033506-85d80d893c3d github.com/aclements/go-moremath v0.0.0-20190506201756-286cc0be6f75 // indirect @@ -1,6 +1,8 @@ bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U= bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +git.xeserv.us/xena/jvozba v0.0.0-20190616002803-f274e24d1e52 h1:MumuDSv8Ebsal1C98APrRRb8JyX+FpKiyGT/8fiMjaw= +git.xeserv.us/xena/jvozba v0.0.0-20190616002803-f274e24d1e52/go.mod h1:lPdeNnexyxX+GQt62HV9UypJDg9enMwadWLXazGUUuc= github.com/McKael/madon/v2 v2.0.0-20180929094633-c679abc985d6 h1:9cJcTOeILzInNo+DCYmXKME1QfAP07FYdo3M9/9jyc4= github.com/McKael/madon/v2 v2.0.0-20180929094633-c679abc985d6/go.mod h1:mvlJhxZCchfiasx3XvN3hBu5RekGwTDm09dKlSM/dQQ= github.com/StackExchange/wmi v0.0.0-20170410192909-ea383cf3ba6e/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= diff --git a/tg/polyglot/main.go b/tg/polyglot/main.go index 35ea098..0048adf 100644 --- a/tg/polyglot/main.go +++ b/tg/polyglot/main.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "expvar" - _ "expvar" "flag" "fmt" "log" @@ -12,10 +11,7 @@ import ( "strings" "time" - "within.website/x/idp/idpmiddleware" - "within.website/x/internal" - _ "within.website/x/tokipona" - "within.website/x/web/tokiponatokens" + "git.xeserv.us/xena/jvozba" _ "github.com/joho/godotenv/autoload" tb "gopkg.in/tucnak/telebot.v2" "within.website/johaus/parser" @@ -23,6 +19,9 @@ import ( "within.website/johaus/pretty" "within.website/ln" "within.website/ln/opname" + "within.website/x/internal" + _ "within.website/x/tokipona" + "within.website/x/web/tokiponatokens" ) const ( @@ -83,8 +82,20 @@ func main() { b.Send(m.Sender, sb.String()) }) + b.Handle("/lujvo", func(m *tb.Message) { + msg := m.Payload + jvo, err := jvozba.Jvozba(msg) + if err != nil { + b.Send(m.Sender, err.Error()) + errCount.Add(1) + return + } + + b.Send(m.Sender, jvo) + }) + ln.Log(opname.With(context.Background(), "main"), ln.Info("starting HTTP server"), ln.F{"port": *port, "using": "idpmiddleware", "self_url": selfURL}) - go http.ListenAndServe(":"+*port, idpmiddleware.XeProtect(selfURL)(http.DefaultServeMux)) + go http.ListenAndServe(":"+*port, http.DefaultServeMux) b.Start() } |
