add a limited /api for the robotrons
Ted Unangst tedu@tedunangst.com
Thu, 07 Nov 2019 16:50:37 -0500
4 files changed,
21 insertions(+),
3 deletions(-)
M
docs/changelog.txt
→
docs/changelog.txt
@@ -1,5 +1,9 @@
changelog +-- next + ++ Add a limited /api for the robotrons. + -- 0.8.1 ++ Make it easier to upgrade by decoupling data dir from ".".
M
go.mod
→
go.mod
@@ -10,7 +10,7 @@ github.com/rivo/uniseg v0.0.0-20190313204849-f699dde9c340 // indirect
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.21 + humungus.tedunangst.com/r/webs v0.6.23 ) go 1.11
M
go.sum
→
go.sum
@@ -34,5 +34,5 @@ gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdrxJNoY=
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/webs v0.6.21 h1:bxI4ZFpxSZw06AbQsaTii5011wjxceF2MOfqJrFnM/w= -humungus.tedunangst.com/r/webs v0.6.21/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= +humungus.tedunangst.com/r/webs v0.6.23 h1:t1VxbiyXYTPQSad/cAJ/+ph1h02yfu+1FwXp8SWt8JY= +humungus.tedunangst.com/r/webs v0.6.23/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps=
M
web.go
→
web.go
@@ -1913,6 +1913,18 @@ log.Printf("frag error: %s", err)
} } +func apihandler(w http.ResponseWriter, r *http.Request) { + u := login.GetUserInfo(r) + action := r.FormValue("action") + log.Printf("api request '%s' on behalf of %s", action, u.Username) + switch action { + case "honk": + submithonk(w, r) + default: + http.Error(w, "unknown action", http.StatusNotFound) + } +} + func serve() { db := opendatabase() login.Init(db)@@ -1952,6 +1964,8 @@ }
mux := mux.NewRouter() mux.Use(login.Checker) + + mux.Handle("/api", login.TokenRequired(http.HandlerFunc(apihandler))) posters := mux.Methods("POST").Subrouter() getters := mux.Methods("GET").Subrouter()