refactor: move hhu handler
This commit is contained in:
parent
021885c50b
commit
3bb46ef95a
3 changed files with 29 additions and 15 deletions
26
src/hhu/handler.go
Normal file
26
src/hhu/handler.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package hhu
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/jordic/goics"
|
||||
)
|
||||
|
||||
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
events, err := GetHhuComputerScienceEvent()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
header := w.Header()
|
||||
header.Set("Content-type", "text/calendar")
|
||||
header.Set("charset", "utf-8")
|
||||
header.Set("Content-Disposition", "inline")
|
||||
header.Set("filename", "calendar.ics")
|
||||
enc := goics.NewICalEncode(w)
|
||||
enc.Encode(events)
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package scrape
|
||||
package hhu
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
16
src/main.go
16
src/main.go
|
|
@ -5,9 +5,8 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/cato-001/calapi/scrape"
|
||||
"github.com/cato-001/calapi/hhu"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/jordic/goics"
|
||||
|
||||
arg "github.com/alexflint/go-arg"
|
||||
)
|
||||
|
|
@ -25,7 +24,7 @@ func main() {
|
|||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/", HomeHandler)
|
||||
r.HandleFunc("/hhu", HhuHandler)
|
||||
r.HandleFunc("/hhu", hhu.Handler)
|
||||
|
||||
url := fmt.Sprintf(":%d", args.Port)
|
||||
http.ListenAndServe(url, r)
|
||||
|
|
@ -35,14 +34,3 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func HhuHandler(w http.ResponseWriter, r *http.Request) {
|
||||
events, err := scrape.GetHhuComputerScienceEvent()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
enc := goics.NewICalEncode(w)
|
||||
enc.Encode(events)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue