get very simple webserver up and running
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"astraltech.xyz/calendar/v2/webserver"
|
||||
)
|
||||
|
||||
func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
var test_html string = "Hello, world"
|
||||
w.Write([]byte(test_html))
|
||||
}
|
||||
|
||||
func main() {
|
||||
read_config()
|
||||
init_dav_client()
|
||||
|
||||
webserver.ServeWebpage("/login", LoginHandler)
|
||||
webserver.ServeWebserver()
|
||||
|
||||
// calDavData := get_caldav_data(serverConfig.Username, serverConfig.Password)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
this is meant to be a reusable webserver component that I can integrate into applications
|
||||
while it can serve custom routes it is also designed to server routes that are needed in all of my applications
|
||||
Examples:
|
||||
- Login page
|
||||
@@ -5,9 +5,13 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ServeWebpage(url string, handler func(http.ResponseWriter, *http.Request)) {
|
||||
http.HandleFunc(url, handler)
|
||||
}
|
||||
|
||||
func ServeWebserver() {
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
fmt.Printf(err.Error())
|
||||
fmt.Print(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user