v0.5.0-rc4: fixing autocert issue, cache ACME registration, added ls-config option

This commit is contained in:
yusing
2024-09-17 08:41:36 +08:00
parent 04fd6543fd
commit 82f06374f7
33 changed files with 301 additions and 221 deletions

View File

@@ -2,6 +2,7 @@ package utils
import (
"context"
"encoding/json"
"io"
"os"
"sync/atomic"
@@ -135,7 +136,7 @@ func (p *BidirectionalPipe) Start() E.NestedError {
errCh <- p.pDstSrc.Start()
}()
for err := range errCh {
if err.IsNotNil() {
if err.HasError() {
return err
}
}
@@ -149,4 +150,20 @@ func (p *BidirectionalPipe) Stop() E.NestedError {
func Copy(ctx context.Context, dst io.WriteCloser, src io.ReadCloser) E.NestedError {
_, err := io.Copy(dst, StdReadCloser{&ReadCloser{ctx: ctx, r: src}})
return E.From(err)
}
}
func LoadJson[T any](path string, pointer *T) E.NestedError {
data, err := os.ReadFile(path)
if err != nil {
return E.From(err)
}
return E.From(json.Unmarshal(data, pointer))
}
func SaveJson[T any](path string, pointer *T, perm os.FileMode) E.NestedError {
data, err := json.Marshal(pointer)
if err != nil {
return E.From(err)
}
return E.From(os.WriteFile(path, data, perm))
}

View File

@@ -9,7 +9,7 @@ import (
func ExpectErrNil(t *testing.T, err E.NestedError) {
t.Helper()
if err.IsNotNil() {
if err.HasError() {
t.Errorf("expected err=nil, got %s", err.Error())
}
}