mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fix: build error
This commit is contained in:
parent
104e1b1d0a
commit
bf429998e8
7 changed files with 15 additions and 16 deletions
|
@ -25,7 +25,7 @@ func (d *dockerInfo) MarshalJSON() ([]byte, error) {
|
||||||
},
|
},
|
||||||
"images": d.Images,
|
"images": d.Images,
|
||||||
"n_cpu": d.NCPU,
|
"n_cpu": d.NCPU,
|
||||||
"memory": strutils.FormatByteSizeWithUnit(d.MemTotal),
|
"memory": strutils.FormatByteSize(d.MemTotal),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/pkg/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// baseError is an immutable wrapper around an error.
|
// baseError is an immutable wrapper around an error.
|
||||||
|
@ -49,6 +49,6 @@ func (err *baseError) Error() string {
|
||||||
return err.Err.Error()
|
return err.Err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err *baseError) MarshalJSONTo(buf []byte) []byte {
|
func (err *baseError) MarshalJSON() ([]byte, error) {
|
||||||
return json.MarshalTo(err.Err, buf)
|
return json.Marshal(err.Err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/pkg/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/internal/utils/strutils/ansi"
|
"github.com/yusing/go-proxy/internal/utils/strutils/ansi"
|
||||||
)
|
)
|
||||||
|
@ -94,7 +94,7 @@ func (err *withSubject) Error() string {
|
||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err *withSubject) MarshalJSONTo(buf []byte) []byte {
|
func (err *withSubject) MarshalJSON() ([]byte, error) {
|
||||||
subjects := slices.Clone(err.Subjects)
|
subjects := slices.Clone(err.Subjects)
|
||||||
slices.Reverse(subjects)
|
slices.Reverse(subjects)
|
||||||
|
|
||||||
|
@ -102,5 +102,5 @@ func (err *withSubject) MarshalJSONTo(buf []byte) []byte {
|
||||||
"subjects": subjects,
|
"subjects": subjects,
|
||||||
"err": err.Err,
|
"err": err.Err,
|
||||||
}
|
}
|
||||||
return json.MarshalTo(reversed, buf)
|
return json.Marshal(reversed)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/pkg/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newError(message string) error {
|
func newError(message string) error {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
"github.com/yusing/go-proxy/internal/logging"
|
||||||
"github.com/yusing/go-proxy/internal/net/gphttp"
|
"github.com/yusing/go-proxy/internal/net/gphttp"
|
||||||
"github.com/yusing/go-proxy/internal/net/gphttp/httpheaders"
|
"github.com/yusing/go-proxy/internal/net/gphttp/httpheaders"
|
||||||
"github.com/yusing/go-proxy/internal/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func warnNoMatchDomains() {
|
func warnNoMatchDomains() {
|
||||||
|
@ -95,7 +94,7 @@ func WriteText(r *http.Request, conn *websocket.Conn, msg string) bool {
|
||||||
func DynamicJSONHandler[ResultType any](w http.ResponseWriter, r *http.Request, getter func() ResultType, interval time.Duration) {
|
func DynamicJSONHandler[ResultType any](w http.ResponseWriter, r *http.Request, getter func() ResultType, interval time.Duration) {
|
||||||
if httpheaders.IsWebsocket(r.Header) {
|
if httpheaders.IsWebsocket(r.Header) {
|
||||||
Periodic(w, r, interval, func(conn *websocket.Conn) error {
|
Periodic(w, r, interval, func(conn *websocket.Conn) error {
|
||||||
return wsjson.Write(r.Context(), conn, utils.ToJSONObject(getter()))
|
return wsjson.Write(r.Context(), conn, getter())
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
gphttp.RespondJSON(w, r, getter())
|
gphttp.RespondJSON(w, r, getter())
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
|
@ -22,12 +21,12 @@ import (
|
||||||
type SerializedObject = map[string]any
|
type SerializedObject = map[string]any
|
||||||
|
|
||||||
type (
|
type (
|
||||||
MapMarshaller interface {
|
MapMarshaler interface {
|
||||||
MarshalMap() map[string]any
|
MarshalMap() map[string]any
|
||||||
}
|
}
|
||||||
MapUnmarshaller interface {
|
MapUnmarshaller interface {
|
||||||
UnmarshalMap(m map[string]any) gperr.Error
|
UnmarshalMap(m map[string]any) gperr.Error
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -51,9 +50,10 @@ var (
|
||||||
typeURL = reflect.TypeFor[url.URL]()
|
typeURL = reflect.TypeFor[url.URL]()
|
||||||
typeCIDR = reflect.TypeFor[net.IPNet]()
|
typeCIDR = reflect.TypeFor[net.IPNet]()
|
||||||
|
|
||||||
typeMapMarshaller = reflect.TypeFor[MapMarshaller]()
|
typeMapMarshaller = reflect.TypeFor[MapMarshaler]()
|
||||||
typeMapUnmarshaler = reflect.TypeFor[MapUnmarshaller]()
|
typeMapUnmarshaler = reflect.TypeFor[MapUnmarshaller]()
|
||||||
typeJSONMarshaller = reflect.TypeFor[json.Marshaler]()
|
typeJSONMarshaller = reflect.TypeFor[json.Marshaler]()
|
||||||
|
typeStrParser = reflect.TypeFor[strutils.Parser]()
|
||||||
|
|
||||||
typeAny = reflect.TypeOf((*any)(nil)).Elem()
|
typeAny = reflect.TypeOf((*any)(nil)).Elem()
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,7 +24,7 @@ type (
|
||||||
task.TaskStarter
|
task.TaskStarter
|
||||||
task.TaskFinisher
|
task.TaskFinisher
|
||||||
fmt.Stringer
|
fmt.Stringer
|
||||||
utils.MapMarshaller
|
utils.MapMarshaler
|
||||||
WithHealthInfo
|
WithHealthInfo
|
||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue