fixed typos and formatting, fixed loading page not being shown (idlewaker)

This commit is contained in:
yusing 2024-10-08 13:15:23 +08:00
parent d1c9e18c97
commit 1797896fa6
6 changed files with 23 additions and 29 deletions

View file

@ -1,8 +1,9 @@
package autocert package autocert
import ( import (
"github.com/go-acme/lego/v4/registration"
"crypto" "crypto"
"github.com/go-acme/lego/v4/registration"
) )
type User struct { type User struct {

View file

@ -64,7 +64,7 @@ func (w *Waker) wake(next http.HandlerFunc, rw http.ResponseWriter, r *http.Requ
defer cancel() defer cancel()
accept := gphttp.GetAccept(r.Header) accept := gphttp.GetAccept(r.Header)
acceptHTML := r.Method == http.MethodGet && accept.AcceptHTML() acceptHTML := (r.Method == http.MethodGet && accept.AcceptHTML() || r.RequestURI == "/" && accept.IsEmpty())
isCheckRedirect := r.Header.Get(headerCheckRedirect) != "" isCheckRedirect := r.Header.Get(headerCheckRedirect) != ""
if !isCheckRedirect && acceptHTML { if !isCheckRedirect && acceptHTML {

View file

@ -36,7 +36,7 @@ func (route *TCPRoute) Setup() error {
if err != nil { if err != nil {
return err return err
} }
//! this read the allocated port from orginal ':0' //! this read the allocated port from original ':0'
route.Port.ListeningPort = T.Port(in.Addr().(*net.TCPAddr).Port) route.Port.ListeningPort = T.Port(in.Addr().(*net.TCPAddr).Port)
route.listener = in route.listener = in
return nil return nil

View file

@ -51,7 +51,7 @@ func (route *UDPRoute) Setup() error {
return err return err
} }
//! this read the allocated listeningPort from orginal ':0' //! this read the allocated listeningPort from original ':0'
route.Port.ListeningPort = T.Port(source.LocalAddr().(*net.UDPAddr).Port) route.Port.ListeningPort = T.Port(source.LocalAddr().(*net.UDPAddr).Port)
route.listeningConn = source route.listeningConn = source

View file

@ -6,6 +6,7 @@ import (
"errors" "errors"
"io" "io"
"os" "os"
"sync"
"syscall" "syscall"
E "github.com/yusing/go-proxy/internal/error" E "github.com/yusing/go-proxy/internal/error"
@ -30,8 +31,6 @@ type (
Pipe struct { Pipe struct {
r ContextReader r ContextReader
w ContextWriter w ContextWriter
ctx context.Context
cancel context.CancelFunc
} }
BidirectionalPipe struct { BidirectionalPipe struct {
@ -59,12 +58,9 @@ func (w *ContextWriter) Write(p []byte) (int, error) {
} }
func NewPipe(ctx context.Context, r io.ReadCloser, w io.WriteCloser) *Pipe { func NewPipe(ctx context.Context, r io.ReadCloser, w io.WriteCloser) *Pipe {
_, cancel := context.WithCancel(ctx)
return &Pipe{ return &Pipe{
r: ContextReader{ctx: ctx, Reader: r}, r: ContextReader{ctx: ctx, Reader: r},
w: ContextWriter{ctx: ctx, Writer: w}, w: ContextWriter{ctx: ctx, Writer: w},
ctx: ctx,
cancel: cancel,
} }
} }
@ -87,22 +83,20 @@ func NewBidirectionalPipe(ctx context.Context, rw1 io.ReadWriteCloser, rw2 io.Re
} }
} }
func NewBidirectionalPipeIntermediate(ctx context.Context, listener io.ReadCloser, client io.ReadWriteCloser, target io.ReadWriteCloser) *BidirectionalPipe {
return &BidirectionalPipe{
pSrcDst: NewPipe(ctx, listener, client),
pDstSrc: NewPipe(ctx, client, target),
}
}
func (p BidirectionalPipe) Start() error { func (p BidirectionalPipe) Start() error {
errCh := make(chan error, 2) var wg sync.WaitGroup
wg.Add(2)
b := E.NewBuilder("bidirectional pipe error")
go func() { go func() {
errCh <- p.pSrcDst.Start() b.AddE(p.pSrcDst.Start())
wg.Done()
}() }()
go func() { go func() {
errCh <- p.pDstSrc.Start() b.AddE(p.pDstSrc.Start())
wg.Done()
}() }()
return E.JoinE("bidirectional pipe error", <-errCh, <-errCh).Error() wg.Wait()
return b.Build().Error()
} }
func Copy(dst *ContextWriter, src *ContextReader) error { func Copy(dst *ContextWriter, src *ContextReader) error {

View file

@ -149,9 +149,8 @@ func Deserialize(src SerializedObject, dst any) E.NestedError {
if dstV.Kind() == reflect.Struct { if dstV.Kind() == reflect.Struct {
mapping := make(map[string]reflect.Value) mapping := make(map[string]reflect.Value)
for i := 0; i < dstV.NumField(); i++ { for _, field := range reflect.VisibleFields(dstT) {
field := dstT.Field(i) mapping[ToLowerNoSnake(field.Name)] = dstV.FieldByName(field.Name)
mapping[ToLowerNoSnake(field.Name)] = dstV.Field(i)
} }
for k, v := range src { for k, v := range src {
if field, ok := mapping[ToLowerNoSnake(k)]; ok { if field, ok := mapping[ToLowerNoSnake(k)]; ok {
@ -322,7 +321,7 @@ func ConvertString(src string, dst reflect.Value) (convertible bool, convErr E.N
var tmp any var tmp any
switch dst.Kind() { switch dst.Kind() {
case reflect.Slice: case reflect.Slice:
// one liner is comma seperated list // one liner is comma separated list
if len(lines) == 0 { if len(lines) == 0 {
dst.Set(reflect.ValueOf(CommaSeperatedList(src))) dst.Set(reflect.ValueOf(CommaSeperatedList(src)))
return return