get very simple webserver up and running

This commit is contained in:
2026-07-31 12:38:56 -07:00
parent 760dbec077
commit e8b422e390
3 changed files with 18 additions and 1 deletions
+9
View File
@@ -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)
+4
View File
@@ -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 -1
View File
@@ -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())
}
}