add a limited /api for the robotrons
This commit is contained in:
parent
df09c4bda3
commit
12d6e57d73
|
@ -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 ".".
|
||||
|
|
2
go.mod
2
go.mod
|
@ -10,7 +10,7 @@ require (
|
|||
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
|
||||
|
|
4
go.sum
4
go.sum
|
@ -34,5 +34,5 @@ gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdr
|
|||
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=
|
||||
|
|
14
web.go
14
web.go
|
@ -1913,6 +1913,18 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -1953,6 +1965,8 @@ func serve() {
|
|||
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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue