Improve: config convergent and add log-level
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
)
|
||||
|
||||
@ -15,14 +14,12 @@ const (
|
||||
)
|
||||
|
||||
type ProxyAdapter interface {
|
||||
ReadWriter() io.ReadWriter
|
||||
Conn() net.Conn
|
||||
Close()
|
||||
}
|
||||
|
||||
type ServerAdapter interface {
|
||||
Addr() *Addr
|
||||
Connect(ProxyAdapter)
|
||||
Close()
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,11 @@ const (
|
||||
AtypDomainName = 3
|
||||
AtypIPv6 = 4
|
||||
|
||||
TCP = iota
|
||||
TCP NetWork = iota
|
||||
UDP
|
||||
|
||||
HTTP SourceType = iota
|
||||
SOCKS
|
||||
)
|
||||
|
||||
type NetWork int
|
||||
@ -23,9 +26,12 @@ func (n *NetWork) String() string {
|
||||
return "udp"
|
||||
}
|
||||
|
||||
type SourceType int
|
||||
|
||||
// Addr is used to store connection address
|
||||
type Addr struct {
|
||||
NetWork NetWork
|
||||
Source SourceType
|
||||
AddrType int
|
||||
Host string
|
||||
IP *net.IP
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -107,13 +106,3 @@ func downloadMMDB(path string) (err error) {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetConfig() (*ini.File, error) {
|
||||
if _, err := os.Stat(ConfigPath); os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
return ini.LoadSources(
|
||||
ini.LoadOptions{AllowBooleanKeys: true},
|
||||
ConfigPath,
|
||||
)
|
||||
}
|
||||
|
35
constant/log.go
Normal file
35
constant/log.go
Normal file
@ -0,0 +1,35 @@
|
||||
package constant
|
||||
|
||||
var (
|
||||
// LogLevelMapping is a mapping for LogLevel enum
|
||||
LogLevelMapping = map[string]LogLevel{
|
||||
"error": ERROR,
|
||||
"warning": WARNING,
|
||||
"info": INFO,
|
||||
"debug": DEBUG,
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
ERROR LogLevel = iota
|
||||
WARNING
|
||||
INFO
|
||||
DEBUG
|
||||
)
|
||||
|
||||
type LogLevel int
|
||||
|
||||
func (l LogLevel) String() string {
|
||||
switch l {
|
||||
case INFO:
|
||||
return "info"
|
||||
case WARNING:
|
||||
return "warning"
|
||||
case ERROR:
|
||||
return "error"
|
||||
case DEBUG:
|
||||
return "debug"
|
||||
default:
|
||||
return "unknow"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user