hivedav

A curlable free/busy scheduler with CalDAV integration
git clone https://git.in0rdr.ch/hivedav.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 07fd6b4af84cc2cf07f0e8adedbb8eba37d620c0
parent 4ce7bb45e83a28081a5ffc563341bb2354e53f65
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Wed, 16 Aug 2023 00:23:22 +0200

feat(ui): render ui based on user agent

Diffstat:
Mgo.mod | 6+++++-
Mgo.sum | 3+++
Mmain.go | 2+-
Mserver.go | 21+++++++++++++++++++--
4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/go.mod b/go.mod @@ -2,11 +2,15 @@ module hivedav go 1.21.0 -require github.com/spf13/viper v1.16.0 +require ( + github.com/pquerna/termchalk v0.0.0-20140809212720-8cc5932700ba + github.com/spf13/viper v1.16.0 +) require ( github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/kr/text v0.2.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect diff --git a/go.sum b/go.sum @@ -46,6 +46,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -145,6 +146,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pquerna/termchalk v0.0.0-20140809212720-8cc5932700ba h1:OLlV7v3MejdMam8+NV7mATPrV2sC/eP5FvOIqL73NYQ= +github.com/pquerna/termchalk v0.0.0-20140809212720-8cc5932700ba/go.mod h1:LPpM4y5i8FCoTn8l4qLbjR+eNia/BCUkDkXimr2i43U= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= diff --git a/main.go b/main.go @@ -1,8 +1,8 @@ package main import ( - "fmt" "hivedav/config" + "fmt" "log" "net/http" ) diff --git a/server.go b/server.go @@ -3,7 +3,11 @@ package main import ( "hivedav/config" "io" + "fmt" + "strings" "net/http" + "github.com/pquerna/termchalk/ansistyle" + "github.com/pquerna/termchalk/prettytable" ) type Server struct { @@ -11,8 +15,21 @@ type Server struct { } func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { - io.WriteString(w, "Welcome to the hive\n") - io.WriteString(w, "<Calendar here>\n") + userAgent := req.Header.Get("user-agent"); + + if strings.Contains(userAgent, "curl") { + w.Header().Set("Content-Type", "text/plain") + io.WriteString(w, ansistyle.Bold.Open + "Welcome to the " + ansistyle.Bold.Close) + io.WriteString(w, ansistyle.BgRed.Open + "hive!" + ansistyle.BgBlue.Close + "\n") + + pt := prettytable.New([]string{"Time ", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}) + pt.AddRow("08:00 - 09:00", "", "", "busy", "", "") + io.WriteString(w, fmt.Sprint(pt)) + } else { + w.Header().Set("Content-Type", "text/html") + io.WriteString(w, "<h1>Welcome to the hive!</h1>") + io.WriteString(w, "<p>HTML Calendar here</p>") + } } func (s *Server) showCubicles() {