mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-23 20:54:02 +02:00
feat: add websocket writer and error handling utilities
This commit is contained in:
parent
7ef8354eb0
commit
366fede517
3 changed files with 49 additions and 2 deletions
|
@ -15,7 +15,7 @@
|
||||||
# options:
|
# options:
|
||||||
# auth_token: c1234565789-abcdefghijklmnopqrst # your zone API token
|
# auth_token: c1234565789-abcdefghijklmnopqrst # your zone API token
|
||||||
|
|
||||||
# 3. other providers, see https://github.com/yusing/go-proxy/wiki/Supported-DNS%E2%80%9001-Providers#supported-dns-01-providers
|
# 3. other providers, see https://github.com/yusing/godoxy/wiki/Supported-DNS%E2%80%9001-Providers#supported-dns-01-providers
|
||||||
|
|
||||||
entrypoint:
|
entrypoint:
|
||||||
# Below define an example of middleware config
|
# Below define an example of middleware config
|
||||||
|
@ -73,7 +73,7 @@ providers:
|
||||||
# url: https://discord.com/api/webhooks/...
|
# url: https://discord.com/api/webhooks/...
|
||||||
# template: discord # this means use payload template from internal/notif/templates/discord.json
|
# template: discord # this means use payload template from internal/notif/templates/discord.json
|
||||||
|
|
||||||
# Check https://github.com/yusing/go-proxy/wiki/Certificates-and-domain-matching#domain-matching
|
# Check https://github.com/yusing/godoxy/wiki/Certificates-and-domain-matching#domain-matching
|
||||||
# for explaination of `match_domains`
|
# for explaination of `match_domains`
|
||||||
#
|
#
|
||||||
# match_domains:
|
# match_domains:
|
||||||
|
|
29
internal/net/gphttp/gpwebsocket/writer.go
Normal file
29
internal/net/gphttp/gpwebsocket/writer.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package gpwebsocket
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/coder/websocket"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Writer struct {
|
||||||
|
conn *websocket.Conn
|
||||||
|
msgType websocket.MessageType
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriter(ctx context.Context, conn *websocket.Conn, msgType websocket.MessageType) *Writer {
|
||||||
|
return &Writer{
|
||||||
|
ctx: ctx,
|
||||||
|
conn: conn,
|
||||||
|
msgType: msgType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Write(p []byte) (int, error) {
|
||||||
|
return len(p), w.conn.Write(w.ctx, w.msgType, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Close() error {
|
||||||
|
return w.conn.CloseNow()
|
||||||
|
}
|
18
internal/net/gphttp/server/error.go
Normal file
18
internal/net/gphttp/server/error.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleError(logger *zerolog.Logger, err error, msg string) {
|
||||||
|
switch {
|
||||||
|
case err == nil, errors.Is(err, http.ErrServerClosed), errors.Is(err, context.Canceled):
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
logger.Fatal().Err(err).Msg(msg)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue