add http/2 and tls

This commit is contained in:
XenGi 2023-11-07 21:16:42 +01:00
parent 927a103c91
commit 632ece25c9
Signed by: xengi
SSH key fingerprint: SHA256:FGp51kRvGOcWnTHiOI39ImwVO4A3fpvR30nPX3LpV7g
3 changed files with 68 additions and 13 deletions

18
cert.pem Normal file
View file

@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC+jCCAeKgAwIBAgIRAKMiYz6LLo+9sgp/p9YbsgIwDQYJKoZIhvcNAQELBQAw
EjEQMA4GA1UEChMHQWNtZSBDbzAeFw0yMzExMDcyMDAyNTRaFw0yNDExMDYyMDAy
NTRaMBIxEDAOBgNVBAoTB0FjbWUgQ28wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQCkb+0FSWggYNPP0+X1erZc+9Qe1SxYv868C5FYgh6OZG8+YU7/7aYC
trk30LysZpO3gi9XfVWv1+R5c1DBXisxtrgz5Z966qBk60yBnPeigu7rtnHnxX3p
JDs0Yd9CLCGk6g4zHbCuDVqNHxWjc/M8oQMCb9ay5Qh0fFEOR6G7b0x9z7eXUCnT
+rZ+SvXpuZ75kxTYQNK7taYPEK2abP79u+rv3DXKR8nMWUwtligCCTj8dTAUPiVW
nQJ4MTv4Xj0gkak4n1p+r2BPrWvTjQOj8ndag5fe8sufkVu3Slt2yY0Ipdk15jfC
p6/C8FpZVTstwjP/XCAOV2se+FE5qwgVAgMBAAGjSzBJMA4GA1UdDwEB/wQEAwIF
oDATBgNVHSUEDDAKBggrBgEFBQcDATAMBgNVHRMBAf8EAjAAMBQGA1UdEQQNMAuC
CWxvY2FsaG9zdDANBgkqhkiG9w0BAQsFAAOCAQEAFGeg/L0jJn/IIeD37jn/GQ28
lCHe0RJC3x1FH/v5uNgnZXqz+xDV8SUv84wj9kbUnfu1gPaVhpwDMuirHrYhgViN
Fq742zLnUxZW7TOnIR/nPGEvfQRhe8wLWvkkT1pRVH1yJbdge431vIiuBEjOBEBO
cr2DZWL6xiJACSG0FBI6Iizvz4vbXrEHhFmleI4Gvj2WR8qx/A29rTnh+oE7ymMo
+yhREeDEZ7kTXTevGZoIwfHeHMg+IE1bNFz1OlA3qb38PS5ko+uD4INlT9f2dDdP
7uMJFAXjk6jqoZ5CRBuLCRSeTj5ady6x9X8lBv8be9np6JFue6L3S+d1/OoucQ==
-----END CERTIFICATE-----

28
key.pem Normal file
View file

@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCkb+0FSWggYNPP
0+X1erZc+9Qe1SxYv868C5FYgh6OZG8+YU7/7aYCtrk30LysZpO3gi9XfVWv1+R5
c1DBXisxtrgz5Z966qBk60yBnPeigu7rtnHnxX3pJDs0Yd9CLCGk6g4zHbCuDVqN
HxWjc/M8oQMCb9ay5Qh0fFEOR6G7b0x9z7eXUCnT+rZ+SvXpuZ75kxTYQNK7taYP
EK2abP79u+rv3DXKR8nMWUwtligCCTj8dTAUPiVWnQJ4MTv4Xj0gkak4n1p+r2BP
rWvTjQOj8ndag5fe8sufkVu3Slt2yY0Ipdk15jfCp6/C8FpZVTstwjP/XCAOV2se
+FE5qwgVAgMBAAECggEAZN9QTBzy5mHfra80czla44GMZ3mn4a2QWaTS/bOcoQcV
gvPYrYEQhLuotYe0JiIq3bjb59S4Gs3al3JZCLYG01FegF+NTK7fw+jgHua2tpeR
j0F1cJOjIMEcHI8pkQNXhD4chdjhyHPip415DbMUdI3lNbp7v3RmkmasppDkswCg
yz+vLflXwGTliuNzM0HxAPl+gH70KxqXgLMqGH568f8D0b63cViarfRCkL2UnFK6
rbysWIsRDqG8CIHZZya5KcTruDDXY0DXnZaXahINgb62Lm4C0tqlF387VWhREMyV
KM4DNFXsiDcgQ6El3BzhxMI0boI02X3jx4lPT11hAQKBgQDU3SlEzrgIX8gM7uG7
oIXaivHnSR/vYD4tCXtgHDrcNlToNEbFi/73ZQKuiNZHOUQWwDw59Y5LtQwOnpch
1cqI3E1Eq8CMNP+yAnnbbeDQTwqhou4nU87zpnXY+jVDnktHAF5zIwZo/8f6DaEu
TDZx3AAGKHv3ScZC6eprsWBNwQKBgQDFwoKvSp55ggY95ZJ9XXAUkeqH2LeGMPun
126vGviOdBM7c4Rqm4UQ/pPc/UDG3/CcvXpWf/Ab5SkXZJPRWJfd23RdIZcj5PX0
mRpXdaCJoLfFo0hH4V5C2O3zdIzip9pOU7P5WyWKf68qd7fpNuGUux/vhUnuOaue
ksraLKz3VQKBgQCiVozLsg++KzYJTwGOs2yB8GduaWFWkQK6HDogYUcufK0ibgPv
UsY/bKSv8SHiLbVU2ITV+wTrjgbE+4PtRPvyhnjTP11YUG8VFjhS9ah3lWBZR0Xz
bkItpazIroGCsS1d19UwX+zalP+xH0XmZi87hHnsOGHahUQT8gta2GrGwQKBgEi8
z2Z8EqfsjDEuBGB6AqR+Ov42VuJTl+xXD832JJ/4z64ZQgYYJ6xlhqtMtwuvCIgO
JTY1nnIUKrYA92GTrWAbvMQYe8fnChQqUAcFK8QTSiS2dvqBSTNbKMJYBw3C4UfX
/6Viwf8cEaiUGh/8YKJc5VUq+FNYAOi1Y0k2D3R1AoGAD+Ao5z3UplNCX+F6u/qa
XoGBFxUt6lFK+ROjXmUl7JmCHHgGuBZ/c6ZaNCFQWKOc21Z92en2whZS2afmjhYG
6Ps5CU0IKR5E616SOe38rfNpLeu/A+164oneTgb8m3UWAiJnTqTNFg8B1xzsRCBK
l5Fg6NTJ/tALKrhGfDEHHAU=
-----END PRIVATE KEY-----

View file

@ -1,11 +1,11 @@
package main
import (
"fmt"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4/middleware"
"golang.org/x/net/websocket"
"net/http"
"strings"
"github.com/labstack/echo/v4"
)
@ -41,29 +41,38 @@ func main() {
})
e.GET("/ws", wsServe)
e.GET("/api/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))
e.Logger.Fatal(e.StartTLS(":1323", "cert.pem", "key.pem"))
//e.Logger.Fatal(e.Start(":1323"))
}
func wsServe(c echo.Context) error {
websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
for {
// Write
err := websocket.Message.Send(ws, "Hello, Client!")
if err != nil {
c.Logger().Error(err)
}
// Read
msg := ""
err = websocket.Message.Receive(ws, &msg)
err := websocket.Message.Receive(ws, &msg)
if err != nil {
c.Logger().Error(err)
}
fmt.Printf("%s\n", msg)
// Forward MPD communication
if strings.HasPrefix(strings.ToUpper(msg), "MPD#") {
// TODO: forward request to mpd and response back to client
err := websocket.Message.Send(ws, "MPD command received, processing... processing...")
if err != nil {
c.Logger().Error(err)
}
}
// Download video link as audio file
if strings.HasPrefix(strings.ToUpper(msg), "YT#") {
// TODO: implement yt-dlp integration
err := websocket.Message.Send(ws, "YT-DLP command received, processing... processing...")
if err != nil {
c.Logger().Error(err)
}
}
//fmt.Printf("%s\n", msg)
}
}).ServeHTTP(c.Response(), c.Request())
return nil