go-jamming/app/webmention/handler.go

54 lines
1.1 KiB
Go
Raw Normal View History

package webmention
import (
"net/http"
2021-04-07 11:44:58 +02:00
"fmt"
"github.com/wgroeneveld/go-jamming/common"
"github.com/wgroeneveld/go-jamming/rest"
)
2021-04-07 11:44:58 +02:00
func HandleGet(conf *common.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Println("handling get")
}
}
func HandlePut(conf *common.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Println("handling put")
}
}
func HandlePost(conf *common.Config) http.HandlerFunc {
httpClient := &rest.HttpClient{}
return func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if !validate(r, r.Header, conf) {
rest.BadRequest(w)
return
}
target := r.FormValue("target")
if !isValidTargetUrl(target, httpClient) {
rest.BadRequest(w)
return
}
2021-04-09 12:40:37 +02:00
wm := Mention{
Source: r.FormValue("source"),
Target: target,
}
2021-04-09 12:40:37 +02:00
recv := &Receiver{
RestClient: httpClient,
Conf: conf,
}
2021-04-09 12:40:37 +02:00
go recv.Receive(wm)
rest.Accept(w)
}
}