Move config into separate package

This commit is contained in:
9seconds
2021-03-11 05:37:18 +03:00
parent 757ea5b63c
commit 1a02511afe
15 changed files with 615 additions and 552 deletions
+45
View File
@@ -0,0 +1,45 @@
package config
import (
"fmt"
"net"
)
type TypeIP struct {
value net.IP
}
func (c *TypeIP) UnmarshalText(data []byte) error {
if len(data) == 0 {
return nil
}
ip := net.ParseIP(string(data))
if ip == nil {
return fmt.Errorf("incorrect ip address: %s", string(data))
}
c.value = ip
return nil
}
func (c *TypeIP) MarshalText() ([]byte, error) { // nolint: unparam
return []byte(c.String()), nil
}
func (c TypeIP) String() string {
if c.value == nil {
return ""
}
return c.value.String()
}
func (c TypeIP) Value(defaultValue net.IP) net.IP {
if c.value == nil {
return defaultValue
}
return c.value
}