mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-25 19:02:22 +01:00
refactor: refactor to adapt new custom json marshaler
This commit is contained in:
@@ -26,8 +26,8 @@ func getHealthInfo(r route.Route) map[string]string {
|
||||
}
|
||||
|
||||
type HealthInfoRaw struct {
|
||||
Status health.Status
|
||||
Latency time.Duration
|
||||
Status health.Status `json:"status,string"`
|
||||
Latency time.Duration `json:"latency"`
|
||||
}
|
||||
|
||||
func getHealthInfoRaw(r route.Route) *HealthInfoRaw {
|
||||
|
||||
@@ -300,7 +300,3 @@ func (cmd *Command) isBypass() bool {
|
||||
func (cmd *Command) String() string {
|
||||
return cmd.raw
|
||||
}
|
||||
|
||||
func (cmd *Command) MarshalText() ([]byte, error) {
|
||||
return []byte(cmd.String()), nil
|
||||
}
|
||||
|
||||
@@ -261,10 +261,6 @@ func (on *RuleOn) String() string {
|
||||
return on.raw
|
||||
}
|
||||
|
||||
func (on *RuleOn) MarshalText() ([]byte, error) {
|
||||
return []byte(on.String()), nil
|
||||
}
|
||||
|
||||
func parseOn(line string) (Checker, gperr.Error) {
|
||||
ors := strutils.SplitRune(line, '|')
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/yusing/go-proxy/pkg/json"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -40,8 +41,8 @@ type (
|
||||
*/
|
||||
Rule struct {
|
||||
Name string `json:"name"`
|
||||
On RuleOn `json:"on"`
|
||||
Do Command `json:"do"`
|
||||
On RuleOn `json:"on,string"`
|
||||
Do Command `json:"do,string"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -102,12 +103,12 @@ func (rules Rules) BuildHandler(caller string, up http.Handler) http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
func (rules Rules) MarshalJSON() ([]byte, error) {
|
||||
func (rules Rules) MarshalJSONTo(buf []byte) []byte {
|
||||
names := make([]string, len(rules))
|
||||
for i, rule := range rules {
|
||||
names[i] = rule.Name
|
||||
}
|
||||
return json.Marshal(names)
|
||||
return json.MarshalTo(names, buf)
|
||||
}
|
||||
|
||||
func (rule *Rule) String() string {
|
||||
|
||||
Reference in New Issue
Block a user