mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Marshalling of config to string
This commit is contained in:
@@ -43,6 +43,10 @@ func (c *configTypeHostPort) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configTypeHostPort) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeHostPort) String() string {
|
func (c configTypeHostPort) String() string {
|
||||||
return c.Value(net.IP{}, 0)
|
return c.Value(net.IP{}, 0)
|
||||||
}
|
}
|
||||||
@@ -75,6 +79,10 @@ func (c *configTypePort) UnmarshalJSON(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configTypePort) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(c.value)
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypePort) String() string {
|
func (c configTypePort) String() string {
|
||||||
return strconv.Itoa(int(c.value))
|
return strconv.Itoa(int(c.value))
|
||||||
}
|
}
|
||||||
@@ -110,6 +118,10 @@ func (c *configTypeBytes) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configTypeBytes) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeBytes) String() string {
|
func (c configTypeBytes) String() string {
|
||||||
return units.ToString(int64(c.value), 1024, "ib", "b")
|
return units.ToString(int64(c.value), 1024, "ib", "b")
|
||||||
}
|
}
|
||||||
@@ -143,6 +155,10 @@ func (c *configTypePreferIP) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configTypePreferIP) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.value), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *configTypePreferIP) String() string {
|
func (c *configTypePreferIP) String() string {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
@@ -178,6 +194,10 @@ func (c *configTypeDuration) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configTypeDuration) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.value.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeDuration) String() string {
|
func (c configTypeDuration) String() string {
|
||||||
return c.value.String()
|
return c.value.String()
|
||||||
}
|
}
|
||||||
@@ -209,6 +229,10 @@ func (c *configTypeFloat) UnmarshalJSON(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configTypeFloat) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeFloat) String() string {
|
func (c configTypeFloat) String() string {
|
||||||
return strconv.FormatFloat(c.value, 'f', -1, 64)
|
return strconv.FormatFloat(c.value, 'f', -1, 64)
|
||||||
}
|
}
|
||||||
@@ -240,7 +264,15 @@ func (c *configTypeIP) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configTypeIP) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeIP) String() string {
|
func (c configTypeIP) String() string {
|
||||||
|
if c.value == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
return c.value.String()
|
return c.value.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,6 +303,10 @@ func (c *configTypeURL) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configTypeURL) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeURL) String() string {
|
func (c configTypeURL) String() string {
|
||||||
if c.value == nil {
|
if c.value == nil {
|
||||||
return ""
|
return ""
|
||||||
@@ -307,6 +343,10 @@ func (c *configTypeMetricPrefix) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configTypeMetricPrefix) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeMetricPrefix) String() string {
|
func (c configTypeMetricPrefix) String() string {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
@@ -331,6 +371,10 @@ func (c *configTypeHTTPPath) UnmarshalText(data []byte) error { // nolint: unpar
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c configTypeHTTPPath) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(c.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c configTypeHTTPPath) String() string {
|
func (c configTypeHTTPPath) String() string {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
@@ -392,6 +436,19 @@ func (c *config) Validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *config) String() string {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
encoder := json.NewEncoder(buf)
|
||||||
|
|
||||||
|
encoder.SetEscapeHTML(false)
|
||||||
|
|
||||||
|
if err := encoder.Encode(c); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
type configRaw struct {
|
type configRaw struct {
|
||||||
Debug bool `toml:"debug" json:"debug"`
|
Debug bool `toml:"debug" json:"debug"`
|
||||||
Secret string `toml:"secret" json:"secret"`
|
Secret string `toml:"secret" json:"secret"`
|
||||||
|
|||||||
Reference in New Issue
Block a user