basic routes all set up

This commit is contained in:
Wouter Groeneveld 2021-04-07 11:44:58 +02:00
parent 795397aa82
commit 4c01023fcd
4 changed files with 36 additions and 5 deletions

View File

@ -11,7 +11,7 @@ import (
func Handle(conf *common.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Printf("testje")
fmt.Fprintf(w, "This is a Jamstack microservice endpoint.\nWanna start jammin' too? Go to https://github.com/wgroeneveld/go-jamming !")
}
}

14
app/pingback/handler.go Normal file
View File

@ -0,0 +1,14 @@
package pingback
import (
"net/http"
"github.com/wgroeneveld/go-jamming/common"
)
func Handle(conf *common.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}

View File

@ -4,11 +4,15 @@ package app
import (
"github.com/wgroeneveld/go-jamming/app/index"
"github.com/wgroeneveld/go-jamming/app/webmention"
"github.com/wgroeneveld/go-jamming/app/pingback"
)
// stole bits from https://pace.dev/blog/2018/05/09/how-I-write-http-services-after-eight-years.html
// stole ideas from https://pace.dev/blog/2018/05/09/how-I-write-http-services-after-eight-years.html
// not that contempt with passing conf, but can't create receivers on non-local types, and won't move specifics into package app
func (s *server) routes() {
s.router.HandleFunc("/", index.Handle(s.conf))
s.router.HandleFunc("/webmention/{domain}/{token}", s.authorizedOnly(webmention.Handle(s.conf)))
s.router.HandleFunc("/", index.Handle(s.conf)).Methods("GET")
s.router.HandleFunc("/pingback", pingback.Handle(s.conf)).Methods("POST")
s.router.HandleFunc("/webmention", webmention.HandlePost(s.conf)).Methods("POST")
s.router.HandleFunc("/webmention/{domain}/{token}", s.authorizedOnly(webmention.HandleGet(s.conf))).Methods("GET")
s.router.HandleFunc("/webmention/{domain}/{token}", s.authorizedOnly(webmention.HandlePut(s.conf))).Methods("PUT")
}

View File

@ -3,11 +3,24 @@ package webmention
import (
"net/http"
"fmt"
"github.com/wgroeneveld/go-jamming/common"
)
func Handle(conf *common.Config) http.HandlerFunc {
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 {
return func(w http.ResponseWriter, r *http.Request) {
}
}